1- on : [push, pull_request, workflow_dispatch]
1+ on : [
2+ push,
3+ pull_request,
4+ workflow_dispatch,
5+ ]
26
37name : CI
48
59env :
6- RUSTFLAGS : -D warnings
10+ # --cfg=web_sys_unstable_apis is required to enable the web_sys clipboard API which egui_web uses
11+ # https://rustwasm.github.io/wasm-bindgen/api/web_sys/struct.Clipboard.html
12+ # https://rustwasm.github.io/docs/wasm-bindgen/web-sys/unstable-apis.html
13+ RUSTFLAGS : -D warnings --cfg=web_sys_unstable_apis
714 RUSTDOCFLAGS : -D warnings
815
916jobs :
1017 check :
1118 name : Check
19+ strategy :
20+ fail-fast : false
21+ matrix :
22+ include :
23+ - TARGET : x86_64-unknown-linux-gnu
24+ # If you add features to your crate, chances are you want to test for all features for native binaries,
25+ # so that all features are checked and can be build by someone cloning your repository.
26+ # If you build natively it will be a binary, the default binary will have the entrypoint "src/main.rs".
27+ flags : " --all-features --bins"
28+ - TARGET : wasm32-unknown-unknown
29+ # With the current trunk setup, if you add features, the webpage will have the default features.
30+ # You could test for all features too, however that might require a lot of conditional compilation annotations.
31+ # Thus we only test for the default features by default.
32+ # Since we build with trunk the entrypoint will also be the "src/main.rs" file.
33+ flags : " --bin ${{ github.event.repository.name }}"
1234 runs-on : ubuntu-latest
1335 steps :
1436 - uses : actions/checkout@v4
15- - uses : actions-rs/toolchain@v1
16- with :
17- profile : minimal
18- toolchain : stable
19- override : true
20- - uses : actions-rs/cargo@v1
21- with :
22- command : check
23- args : --all-features
24-
25- check_wasm :
26- name : Check wasm32
27- runs-on : ubuntu-latest
28- steps :
29- - uses : actions/checkout@v4
30- - uses : actions-rs/toolchain@v1
37+ - uses : dtolnay/rust-toolchain@stable
3138 with :
32- profile : minimal
33- toolchain : stable
34- target : wasm32-unknown-unknown
35- override : true
36- - uses : actions-rs/cargo@v1
37- with :
38- command : check
39- args : --all-features --lib --target wasm32-unknown-unknown
39+ targets : ${{matrix.TARGET}}
40+ - uses : Swatinem/rust-cache@v2
41+ - run : cargo check ${{matrix.flags}} --target ${{matrix.TARGET}}
4042
4143 test :
4244 name : Test Suite
4345 runs-on : ubuntu-latest
4446 steps :
4547 - uses : actions/checkout@v4
46- - uses : actions-rs/toolchain@v1
47- with :
48- profile : minimal
49- toolchain : stable
50- override : true
51- - run : sudo apt-get install libxcb-render0-dev libxcb-shape0-dev libxcb-xfixes0-dev libxkbcommon-dev libssl-dev
52- - uses : actions-rs/cargo@v1
53- with :
54- command : test
55- args : --lib
48+ - uses : dtolnay/rust-toolchain@stable
49+ - uses : Swatinem/rust-cache@v2
50+ - run : cargo test --lib
5651
5752 fmt :
5853 name : Rustfmt
5954 runs-on : ubuntu-latest
6055 steps :
6156 - uses : actions/checkout@v4
62- - uses : actions-rs/ toolchain@v1
57+ - uses : dtolnay/rust- toolchain@stable
6358 with :
64- profile : minimal
65- toolchain : stable
66- override : true
6759 components : rustfmt
68- - uses : actions-rs/cargo@v1
69- with :
70- command : fmt
71- args : --all -- --check
60+ - uses : Swatinem/rust-cache@v2
61+ - run : cargo fmt --all -- --check
7262
7363 clippy :
7464 name : Clippy
7565 runs-on : ubuntu-latest
7666 steps :
7767 - uses : actions/checkout@v4
78- - uses : actions-rs/ toolchain@v1
68+ - uses : dtolnay/rust- toolchain@stable
7969 with :
80- profile : minimal
81- toolchain : stable
82- override : true
8370 components : clippy
84- - uses : actions-rs/cargo@v1
85- with :
86- command : clippy
87- args : -- -D warnings
71+ - uses : Swatinem/rust-cache@v2
72+ - run : cargo clippy --workspace --all-targets --all-features -- -D warnings -W clippy::all
8873
8974 trunk :
9075 name : trunk
9176 runs-on : ubuntu-latest
9277 steps :
9378 - uses : actions/checkout@v4
94- - uses : actions-rs/ toolchain@v1
79+ - uses : dtolnay/rust- toolchain@stable
9580 with :
96- profile : minimal
97- toolchain : 1.81.0
98- target : wasm32-unknown-unknown
99- override : true
81+ targets : wasm32-unknown-unknown
82+ - uses : Swatinem/rust-cache@v2
10083 - name : Download and install Trunk binary
10184 run : wget -qO- https://github.com/thedodd/trunk/releases/latest/download/trunk-x86_64-unknown-linux-gnu.tar.gz | tar -xzf-
10285 - name : Build
@@ -108,63 +91,87 @@ jobs:
10891 fail-fast : false
10992 matrix :
11093 include :
111- - os : macos-latest
112- TARGET : aarch64-apple-darwin
94+ - os : macos-latest
95+ # macos-latest seems to already run on arm64(=aarch64):
96+ # https://docs.github.com/en/actions/using-jobs/choosing-the-runner-for-a-job#standard-github-hosted-runners-for-public-repositories
97+ TARGET : aarch64-apple-darwin
11398
114- - os : ubuntu-latest
115- TARGET : aarch64-unknown-linux-gnu
99+ - os : macos-latest
100+ TARGET : x86_64-apple-darwin
101+ # even though the runner uses arm64, MacOS on arm64 seems to support building for amd64.
102+ # which makes sense, would be bad for devs otherwise.
103+ cross : false
116104
117- - os : ubuntu-latest
118- TARGET : armv7-unknown-linux-gnueabihf
105+ - os : ubuntu-latest
106+ TARGET : aarch64-unknown-linux-gnu
107+ cross : true
119108
120- - os : ubuntu-latest
121- TARGET : x86_64-unknown-linux-gnu
109+ - os : ubuntu-latest
110+ TARGET : armv7-unknown-linux-gnueabihf
111+ cross : true
122112
123- - os : windows-latest
124- TARGET : x86_64-pc-windows-msvc
125- EXTENSION : .exe
113+ - os : ubuntu-latest
114+ TARGET : x86_64-unknown-linux-gnu
115+
116+ - os : windows-latest
117+ TARGET : x86_64-pc-windows-msvc
118+ EXTENSION : .exe
126119
127120 steps :
128- - name : Building ${{ matrix.TARGET }}
129- run : echo "${{ matrix.TARGET }}"
130-
131- - uses : actions/checkout@master
132- - name : Install build dependencies - Rustup
133- run : |
134- curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- --default-toolchain stable --profile default --target ${{ matrix.TARGET }} -y
135- echo "$HOME/.cargo/bin" >> $GITHUB_PATH
136-
137- # For linux, it's necessary to use cross from the git repository to avoid glibc problems
138- # Ref: https://github.com/cross-rs/cross/issues/1510
139- - name : Install cross for linux
140- if : contains(matrix.TARGET, 'linux')
141- run : |
142- cargo install cross --git https://github.com/cross-rs/cross --rev 1b8cf50d20180c1a394099e608141480f934b7f7
143-
144- - name : Install cross for mac and windows
145- if : ${{ !contains(matrix.TARGET, 'linux') }}
146- run : |
147- cargo install cross
148-
149- - name : Build
150- run : |
151- cross build --verbose --release --target=${{ matrix.TARGET }}
152-
153- - name : Rename
154- run : cp target/${{ matrix.TARGET }}/release/eframe_template${{ matrix.EXTENSION }} eframe_template-${{ matrix.TARGET }}${{ matrix.EXTENSION }}
155-
156- - uses : actions/upload-artifact@master
157- with :
158- name : eframe_template-${{ matrix.TARGET }}${{ matrix.EXTENSION }}
159- path : eframe_template-${{ matrix.TARGET }}${{ matrix.EXTENSION }}
160-
161- - uses : svenstaro/upload-release-action@v2
162- name : Upload binaries to release
163- if : ${{ github.event_name == 'push' }}
164- with :
165- repo_token : ${{ secrets.GITHUB_TOKEN }}
166- file : eframe_template-${{ matrix.TARGET }}${{ matrix.EXTENSION }}
167- asset_name : eframe_template-${{ matrix.TARGET }}${{ matrix.EXTENSION }}
168- tag : ${{ github.ref }}
169- prerelease : ${{ !startsWith(github.ref, 'refs/tags/') }}
170- overwrite : true
121+ - uses : taiki-e/install-action@v2
122+ if : matrix.cross
123+ with :
124+ 125+ # Github doesnt have runners with exotic architectures (eg. arm64/aarch64 on anything but macos).
126+ # Thus we use cross.
127+ # It's necessary to use an up-to-date cross from the git repository to avoid glibc problems on linux
128+ # Ref: https://github.com/cross-rs/cross/issues/1510
129+ # if: matrix.cross
130+ # run: |
131+ # cargo install cross --git https://github.com/cross-rs/cross --rev 1b8cf50d20180c1a394099e608141480f934b7f7
132+
133+ - name : Building ${{ matrix.TARGET }}
134+ run : echo "${{ matrix.TARGET }}"
135+
136+ - uses : actions/checkout@master
137+
138+ - uses : dtolnay/rust-toolchain@stable
139+ with :
140+ targets : ${{ matrix.TARGET }}
141+
142+ - uses : Swatinem/rust-cache@v2
143+ with :
144+ # this is required to avoid failures due to caching of artifacts for different architectures
145+ # The reason is the potential usage of cross.
146+ # The cache checks the rustc host which doesn't record us targeting
147+ # different architectures (and native) with cross on the generic ubuntu-latest.
148+ key : ${{ matrix.TARGET }}
149+
150+ - if : ${{ !matrix.cross }}
151+ name : Cargo Build
152+ run : cargo build --verbose --release --target=${{ matrix.TARGET }}
153+
154+ - if : matrix.cross
155+ name : Cross Build
156+ run : cross build --verbose --release --target=${{ matrix.TARGET }}
157+
158+ - name : Rename
159+ run : cp target/${{ matrix.TARGET }}/release/${{ github.event.repository.name }}${{ matrix.EXTENSION }} ${{ github.event.repository.name }}-${{ matrix.TARGET }}${{ matrix.EXTENSION }}
160+
161+ - uses : actions/upload-artifact@master
162+ with :
163+ name : ${{ github.event.repository.name }}-${{ matrix.TARGET }}${{ matrix.EXTENSION }}
164+ path : ${{ github.event.repository.name }}-${{ matrix.TARGET }}${{ matrix.EXTENSION }}
165+
166+ # this requires read-write permissions on the repo:
167+ # https://github.com/svenstaro/upload-release-action/issues/70
168+ - uses : svenstaro/upload-release-action@v2
169+ name : Upload binaries to release
170+ if : ${{ github.event_name == 'push' }}
171+ with :
172+ repo_token : ${{ secrets.GITHUB_TOKEN }}
173+ file : ${{ github.event.repository.name }}-${{ matrix.TARGET }}${{ matrix.EXTENSION }}
174+ asset_name : ${{ github.event.repository.name }}-${{ matrix.TARGET }}${{ matrix.EXTENSION }}
175+ tag : ${{ github.ref }}
176+ prerelease : ${{ !startsWith(github.ref, 'refs/tags/') }}
177+ overwrite : true
0 commit comments