Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support cargo-generate #169

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 16 additions & 14 deletions .github/workflows/pages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
138 changes: 71 additions & 67 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "eframe_template"
name = "{{project-name}}"
version = "0.1.0"
authors = ["Emil Ernerfeldt <[email protected]>"]
authors = ["{{authors}}"]
edition = "2021"
include = ["LICENSE-APACHE", "LICENSE-MIT", "**/*.rs", "Cargo.toml"]
rust-version = "1.76"
Expand Down
41 changes: 21 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 `<title>eframe template</title>` to `<title>your_crate</title>`. 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

Expand All @@ -38,15 +33,21 @@ The official egui docs are at <https://docs.rs/egui>. 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

Expand Down Expand Up @@ -78,7 +79,7 @@ We use [Trunk](https://trunkrs.dev/) to build for web target.
> - <branch name>
> ```

You can test the template app at <https://emilk.github.io/eframe_template/>.
You can test the template app at <https://emilk.github.io/{{project-name}}/>.

## Updating egui

Expand Down
4 changes: 2 additions & 2 deletions assets/sw.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
13 changes: 0 additions & 13 deletions fill_template.ps1

This file was deleted.

27 changes: 0 additions & 27 deletions fill_template.sh

This file was deleted.

Loading
Loading