diff --git a/.github/workflows/pages.yml b/.github/workflows/pages.yml index 3878bdc9..383f163e 100644 --- a/.github/workflows/pages.yml +++ b/.github/workflows/pages.yml @@ -15,34 +15,36 @@ permissions: contents: write # for committing to gh-pages branch. jobs: - build-github-pages: + deploy-github-pages: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v4 # repo checkout - - name: Setup toolchain for wasm + - uses: actions/checkout@v4 + - uses: cargo-bins/cargo-binstall@main + - name: Install cargo-generate and trunk + run: cargo binstall -y cargo-generate trunk + - name: Generate project + # Delete Cargo.toml template as trunk also looks in the parent directory. run: | - rustup update stable - rustup default stable - rustup set profile minimal - rustup target add wasm32-unknown-unknown - - name: Rust Cache # cache the rust build artefacts - uses: Swatinem/rust-cache@v2 - - name: Download and install Trunk binary - run: wget -qO- https://github.com/thedodd/trunk/releases/latest/download/trunk-x86_64-unknown-linux-gnu.tar.gz | tar -xzf- - - name: Build # build + cargo generate --path . --name "eframe-template" + rm Cargo.toml + - uses: dtolnay/rust-toolchain@stable + with: + targets: wasm32-unknown-unknown + - name: Build + working-directory: eframe-template # Environment $public_url resolves to the github project page. # If using a user/organization page, remove the `${{ github.event.repository.name }}` part. # using --public-url something will allow trunk to modify all the href paths like from favicon.ico to repo_name/favicon.ico . # this is necessary for github pages where the site is deployed to username.github.io/repo_name and all files must be requested # relatively as eframe_template/favicon.ico. if we skip public-url option, the href paths will instead request username.github.io/favicon.ico which # will obviously return error 404 not found. - run: ./trunk build --release --public-url $public_url env: public_url: "https://${{ github.repository_owner }}.github.io/${{ github.event.repository.name }}" + run: trunk build --release --public-url $public_url - name: Deploy uses: JamesIves/github-pages-deploy-action@v4 with: - folder: dist + folder: eframe-template/dist # this option will not maintain any history of your previous pages deployment # set to false if you want all page build to be committed to your gh-pages branch history single-commit: true diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index db5b62b2..eec337ca 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -7,102 +7,105 @@ env: RUSTDOCFLAGS: -D warnings jobs: - check: - name: Check + generate: + name: Generate from template runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - - uses: actions-rs/toolchain@v1 + - uses: cargo-bins/cargo-binstall@main + - name: Install cargo-generate + run: cargo binstall -y cargo-generate + - name: Generate project + run: cargo generate --path . --name "eframe-template" + - uses: actions/upload-artifact@v4 with: - profile: minimal - toolchain: stable - override: true - - uses: actions-rs/cargo@v1 + name: eframe-template + path: eframe-template + + check: + name: Check + needs: generate + runs-on: ubuntu-latest + steps: + - uses: actions/download-artifact@v4 with: - command: check - args: --all-features + name: eframe-template + - uses: dtolnay/rust-toolchain@stable + - name: Check + run: cargo check check_wasm: name: Check wasm32 + needs: generate runs-on: ubuntu-latest steps: - - uses: actions/checkout@v4 - - uses: actions-rs/toolchain@v1 + - uses: actions/download-artifact@v4 with: - profile: minimal - toolchain: stable - target: wasm32-unknown-unknown - override: true - - uses: actions-rs/cargo@v1 + name: eframe-template + - uses: dtolnay/rust-toolchain@stable with: - command: check - args: --all-features --lib --target wasm32-unknown-unknown + targets: wasm32-unknown-unknown + - name: Check + run: cargo check test: - name: Test Suite + name: Test suite + needs: generate runs-on: ubuntu-latest steps: - - uses: actions/checkout@v4 - - uses: actions-rs/toolchain@v1 - with: - profile: minimal - toolchain: stable - override: true - - run: sudo apt-get install libxcb-render0-dev libxcb-shape0-dev libxcb-xfixes0-dev libxkbcommon-dev libssl-dev - - uses: actions-rs/cargo@v1 + - uses: actions/download-artifact@v4 with: - command: test - args: --lib + name: eframe-template + - name: Install dependencies + run: sudo apt-get install libxcb-render0-dev libxcb-shape0-dev libxcb-xfixes0-dev libxkbcommon-dev libssl-dev + - uses: dtolnay/rust-toolchain@stable + - name: Test + run: cargo test --lib fmt: name: Rustfmt + needs: generate runs-on: ubuntu-latest steps: - - uses: actions/checkout@v4 - - uses: actions-rs/toolchain@v1 - with: - profile: minimal - toolchain: stable - override: true - components: rustfmt - - uses: actions-rs/cargo@v1 + - uses: actions/download-artifact@v4 with: - command: fmt - args: --all -- --check + name: eframe-template + - uses: dtolnay/rust-toolchain@stable + - name: Format + run: cargo fmt --all -- --check clippy: name: Clippy + needs: generate runs-on: ubuntu-latest steps: - - uses: actions/checkout@v4 - - uses: actions-rs/toolchain@v1 + - uses: actions/download-artifact@v4 with: - profile: minimal - toolchain: stable - override: true - components: clippy - - uses: actions-rs/cargo@v1 - with: - command: clippy - args: -- -D warnings + name: eframe-template + - uses: dtolnay/rust-toolchain@stable + - name: Clippy + run: cargo clippy -- -D warnings + trunk: - name: trunk + name: Trunk + needs: generate runs-on: ubuntu-latest steps: - - uses: actions/checkout@v4 - - uses: actions-rs/toolchain@v1 + - uses: actions/download-artifact@v4 + with: + name: eframe-template + - uses: cargo-bins/cargo-binstall@main + - name: Install trunk + run: cargo binstall -y trunk + - uses: dtolnay/rust-toolchain@stable with: - profile: minimal - toolchain: 1.76.0 - target: wasm32-unknown-unknown - override: true - - name: Download and install Trunk binary - run: wget -qO- https://github.com/thedodd/trunk/releases/latest/download/trunk-x86_64-unknown-linux-gnu.tar.gz | tar -xzf- + targets: wasm32-unknown-unknown - name: Build - run: ./trunk build + run: trunk build build: + needs: generate runs-on: ${{ matrix.os }} strategy: fail-fast: false @@ -128,7 +131,6 @@ jobs: - name: Building ${{ matrix.TARGET }} run: echo "${{ matrix.TARGET }}" - - uses: actions/checkout@master - name: Install build dependencies - Rustup run: | curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- --default-toolchain stable --profile default --target ${{ matrix.TARGET }} -y @@ -146,25 +148,27 @@ jobs: run: | cargo install cross + - uses: actions/download-artifact@v4 + with: + name: eframe-template - name: Build - run: | - cross build --verbose --release --target=${{ matrix.TARGET }} + run: cross build --verbose --release --target=${{ matrix.TARGET }} - name: Rename - run: cp target/${{ matrix.TARGET }}/release/eframe_template${{ matrix.EXTENSION }} eframe_template-${{ matrix.TARGET }}${{ matrix.EXTENSION }} + run: cp target/${{ matrix.TARGET }}/release/eframe-template${{ matrix.EXTENSION }} eframe-template-${{ matrix.TARGET }}${{ matrix.EXTENSION }} - uses: actions/upload-artifact@master with: - name: eframe_template-${{ matrix.TARGET }}${{ matrix.EXTENSION }} - path: eframe_template-${{ matrix.TARGET }}${{ matrix.EXTENSION }} + name: eframe-template-${{ matrix.TARGET }}${{ matrix.EXTENSION }} + path: eframe-template-${{ matrix.TARGET }}${{ matrix.EXTENSION }} - uses: svenstaro/upload-release-action@v2 name: Upload binaries to release if: ${{ github.event_name == 'push' }} with: repo_token: ${{ secrets.GITHUB_TOKEN }} - file: eframe_template-${{ matrix.TARGET }}${{ matrix.EXTENSION }} - asset_name: eframe_template-${{ matrix.TARGET }}${{ matrix.EXTENSION }} + file: eframe-template-${{ matrix.TARGET }}${{ matrix.EXTENSION }} + asset_name: eframe-template-${{ matrix.TARGET }}${{ matrix.EXTENSION }} tag: ${{ github.ref }} prerelease: ${{ !startsWith(github.ref, 'refs/tags/') }} overwrite: true diff --git a/Cargo.lock b/Cargo.lock index 9540e960..1184dcce 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -864,7 +864,7 @@ dependencies = [ ] [[package]] -name = "eframe_template" +name = "{{project-name}}" version = "0.1.0" dependencies = [ "eframe", diff --git a/Cargo.toml b/Cargo.toml index e7a94065..4f37a82e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,7 @@ [package] -name = "eframe_template" +name = "{{project-name}}" version = "0.1.0" -authors = ["Emil Ernerfeldt "] +authors = ["{{authors}}"] edition = "2021" include = ["LICENSE-APACHE", "LICENSE-MIT", "**/*.rs", "Cargo.toml"] rust-version = "1.76" diff --git a/README.md b/README.md index c9f52ebb..df27b85e 100644 --- a/README.md +++ b/README.md @@ -11,22 +11,17 @@ You can compile your app natively or for the web, and share it using Github Page ## Getting started -Start by clicking "Use this template" at https://github.com/emilk/eframe_template/ or follow [these instructions](https://docs.github.com/en/free-pro-team@latest/github/creating-cloning-and-archiving-repositories/creating-a-repository-from-a-template). - -Change the name of the crate: Choose a good name for your project, and change the name to it in: -* `Cargo.toml` - * Change the `package.name` from `eframe_template` to `your_crate`. - * Change the `package.authors` -* `main.rs` - * Change `eframe_template::TemplateApp` to `your_crate::TemplateApp` -* `index.html` - * Change the `eframe template` to `your_crate`. optional. -* `assets/sw.js` - * Change the `'./eframe_template.js'` to `./your_crate.js` (in `filesToCache` array) - * Change the `'./eframe_template_bg.wasm'` to `./your_crate_bg.wasm` (in `filesToCache` array) - -Alternatively, you can run `fill_template.sh` which will ask for the needed names and email and perform the above patches for you. This is particularly useful if you clone this repository outside GitHub and hence cannot make use of its -templating function. +If you don't have [`cargo-generate`](https://github.com/cargo-generate/cargo-generate) installed yet, install it with: + +```sh +cargo install cargo-generate +``` + +Then create a project by running: + +```sh +cargo generate --git https://github.com/emilk/eframe_template +``` ### Learning about egui @@ -38,15 +33,21 @@ The official egui docs are at . If you prefer watching a v Make sure you are using the latest version of stable rust by running `rustup update`. -`cargo run --release` +```sh +cargo run --release +``` On Linux you need to first run: -`sudo apt-get install libxcb-render0-dev libxcb-shape0-dev libxcb-xfixes0-dev libxkbcommon-dev libssl-dev` +```sh +sudo apt-get install libxcb-render0-dev libxcb-shape0-dev libxcb-xfixes0-dev libxkbcommon-dev libssl-dev +``` On Fedora Rawhide you need to run: -`dnf install clang clang-devel clang-tools-extra libxkbcommon-devel pkg-config openssl-devel libxcb-devel gtk3-devel atk fontconfig-devel` +```sh +dnf install clang clang-devel clang-tools-extra libxkbcommon-devel pkg-config openssl-devel libxcb-devel gtk3-devel atk fontconfig-devel +``` ### Web Locally @@ -78,7 +79,7 @@ We use [Trunk](https://trunkrs.dev/) to build for web target. > - > ``` -You can test the template app at . +You can test the template app at . ## Updating egui diff --git a/assets/sw.js b/assets/sw.js index 7ecd2298..09228b41 100644 --- a/assets/sw.js +++ b/assets/sw.js @@ -2,8 +2,8 @@ var cacheName = 'egui-template-pwa'; var filesToCache = [ './', './index.html', - './eframe_template.js', - './eframe_template_bg.wasm', + './{{crate_name}}.js', + './{{crate_name}}_bg.wasm', ]; /* Start the service worker and cache all of the app's content */ diff --git a/fill_template.ps1 b/fill_template.ps1 deleted file mode 100644 index 13edffed..00000000 --- a/fill_template.ps1 +++ /dev/null @@ -1,13 +0,0 @@ -$crate = Read-Host "To fill the template, tell me your egui project crate name: " -$name = Read-Host "To fill the template, tell me your name (for author in Cargo.toml): " -$email = Read-Host "To fill the template, tell me your e-mail address (also for Cargo.toml): " - -Write-Host "Patching files..." - -(Get-Content "Cargo.toml") -replace "eframe_template", $crate | Set-Content "Cargo.toml" -(Get-Content "src\main.rs") -replace "eframe_template", $crate | Set-Content "src\main.rs" -(Get-Content "index.html") -replace "eframe template", $crate -replace "eframe_template", $crate | Set-Content "index.html" -(Get-Content "assets\sw.js") -replace "eframe_template", $crate | Set-Content "assets\sw.js" -(Get-Content "Cargo.toml") -replace "Emil Ernerfeldt", $name -replace "emil.ernerfeldt@gmail.com", $email | Set-Content "Cargo.toml" - -Write-Host "Done." \ No newline at end of file diff --git a/fill_template.sh b/fill_template.sh deleted file mode 100755 index d9c37107..00000000 --- a/fill_template.sh +++ /dev/null @@ -1,27 +0,0 @@ -#!/usr/bin/env sh - -set -e - -echo "To fill the template tell me your egui project crate name: " - -read crate - -echo "To fill the template tell me your name (for author in Cargo.toml): " - -read name - -echo "To fill the template tell me your e-mail address (also for Cargo.toml): " - -read email - -echo "Patching files..." - -sed -i "s/eframe_template/$crate/g" Cargo.toml -sed -i "s/eframe_template/$crate/g" src/main.rs -sed -i "s/eframe template/$crate/g" index.html -sed -i "s/eframe_template/$crate/g" assets/sw.js -sed -i "s/Emil Ernerfeldt/$name/g" Cargo.toml -sed -i "s/emil.ernerfeldt@gmail.com/$email/g" Cargo.toml - -echo "Done." - diff --git a/src/main.rs b/src/main.rs index 029bf61f..d6db3b6b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -20,7 +20,7 @@ fn main() -> eframe::Result { eframe::run_native( "eframe template", native_options, - Box::new(|cc| Ok(Box::new(eframe_template::TemplateApp::new(cc)))), + Box::new(|cc| Ok(Box::new({{crate_name}}::TemplateApp::new(cc)))), ) } @@ -50,7 +50,7 @@ fn main() { .start( canvas, web_options, - Box::new(|cc| Ok(Box::new(eframe_template::TemplateApp::new(cc)))), + Box::new(|cc| Ok(Box::new({{crate_name}}::TemplateApp::new(cc)))), ) .await;