Skip to content

Commit 8059131

Browse files
update gh-pages ci to not compile trunk every time, and update build
scripts to work with that
1 parent b24becb commit 8059131

File tree

3 files changed

+109
-23
lines changed

3 files changed

+109
-23
lines changed

.github/workflows/pages.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,16 @@ jobs:
2121
rustup target add wasm32-unknown-unknown
2222
- name: Rust Cache # cache the rust build artefacts
2323
uses: Swatinem/rust-cache@v2
24-
- name: install Trunk binary
25-
run: cargo install trunk
24+
- name: Download Trunk binary
25+
run: wget -qO- https://github.com/thedodd/trunk/releases/latest/download/trunk-x86_64-unknown-linux-gnu.tar.gz | tar -xzf-
2626
- name: Build # build
2727
# Environment $public_url resolves to the github project page.
2828
# If using a user/organization page, remove the `${{ github.event.repository.name }}` part.
2929
# using --public-url something will allow trunk to modify all the href paths like from favicon.ico to repo_name/favicon.ico .
3030
# this is necessary for github pages where the site is deployed to username.github.io/repo_name and all files must be requested
3131
# relatively as eframe_template/favicon.ico. if we skip public-url option, the href paths will instead request username.github.io/favicon.ico which
3232
# will obviously return error 404 not found.
33-
run: ./build.sh --wasm --public-url "$public_url"
33+
run: ./build.sh --ci --wasm --public-url "$public_url"
3434
env:
3535
public_url: "https://${{ github.repository_owner }}.github.io/${{ github.event.repository.name }}"
3636
- name: Deploy

build.ps1

Lines changed: 66 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,91 @@
11
param(
22
[switch]$native,
33
[string]$publicUrl = "",
4-
[switch]$wasm
4+
[switch]$wasm,
5+
[switch]$ci
56
)
67

78
$TARGET = "x86_64-pc-windows-msvc"
89

10+
$trunkCmd = "trunk"
11+
if ($ci) {
12+
$trunkCmd = ".\trunk"
13+
Write-Host "CI mode enabled: Using local trunk binary at $trunkCmd"
14+
if (-not (Test-Path $trunkCmd)) {
15+
Write-Error "Error: CI mode specified, but '$trunkCmd' not found."
16+
exit 1
17+
}
18+
}
19+
20+
921
$env:RUSTFLAGS = "-Csymbol-mangling-version=v0 -Zlocation-detail=none -Zfmt-debug=none"
1022

11-
mv .cargo/.config.toml .cargo/config.toml
23+
24+
Move-Item -Path ".cargo/.config.toml" -Destination ".cargo/config.toml" -Force
25+
1226

1327
if ($wasm -or $publicUrl -ne "") {
1428
Write-Host "Building particle-simulation for web..."
15-
if ($publicUrl -ne "") {
16-
Write-Host "Using public URL: $publicUrl"
17-
$env:RUSTFLAGS += " -C target-feature=-nontrapping-fptoint"
18-
& trunk build --release --public-url $publicUrl
19-
} else {
20-
$env:RUSTFLAGS += " -C target-feature=-nontrapping-fptoint"
21-
& trunk build --release
29+
30+
$originalRustFlags = $env:RUSTFLAGS
31+
$env:RUSTFLAGS += " -C target-feature=-nontrapping-fptoint"
32+
33+
try {
34+
if ($publicUrl -ne "") {
35+
Write-Host "Using public URL: $publicUrl"
36+
& $trunkCmd build --release --public-url $publicUrl
37+
} else {
38+
& $trunkCmd build --release
39+
}
40+
41+
if ($LASTEXITCODE -ne 0) {
42+
throw "trunk build failed with exit code $LASTEXITCODE"
43+
}
44+
}
45+
catch {
46+
Write-Error "Error during trunk build: $_"
47+
48+
$env:RUSTFLAGS = $originalRustFlags
49+
Move-Item -Path ".cargo/config.toml" -Destination ".cargo/.config.toml" -Force
50+
exit 1
51+
}
52+
finally {
53+
54+
$env:RUSTFLAGS = $originalRustFlags
2255
}
2356
}
2457

58+
$nativeRustFlags = $env:RUSTFLAGS
2559
if ($native) {
2660
Write-Host "Building particle-simulation for $TARGET with native CPU optimizations..."
27-
$env:RUSTFLAGS += " -C target-cpu=native"
61+
$nativeRustFlags += " -C target-cpu=native"
2862
} else {
2963
Write-Host "Building particle-simulation for $TARGET..."
3064
}
3165

32-
$env:RUSTFLAGS += " -Clink-args=-fuse-ld=lld -Clink-args=-Wl,--icf=all"
3366

34-
cargo +nightly build --target $TARGET --release
67+
$nativeRustFlags += " -Clink-args=-fuse-ld=lld -Clink-args=-Wl,--icf=all"
68+
69+
70+
$env:RUSTFLAGS = $nativeRustFlags
71+
72+
try {
73+
cargo +nightly build --target $TARGET --release
74+
75+
if ($LASTEXITCODE -ne 0) {
76+
throw "cargo build failed with exit code $LASTEXITCODE"
77+
}
78+
}
79+
catch {
80+
Write-Error "Error during cargo build: $_"
81+
82+
Move-Item -Path ".cargo/config.toml" -Destination ".cargo/.config.toml" -Force
83+
exit 1
84+
}
85+
86+
87+
Move-Item -Path ".cargo/config.toml" -Destination ".cargo/.config.toml" -Force
3588

36-
mv .cargo/config.toml .cargo/.config.toml
89+
Write-Host "Build finished successfully."
3790

3891
exit $LASTEXITCODE

build.sh

Lines changed: 40 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ TARGET=""
44
BUILD_WASM=false
55
NATIVE_OPT=false
66
PUBLIC_URL=""
7+
CI_MODE=false
78

89
while [[ "$#" -gt 0 ]]; do
910
case $1 in
@@ -27,6 +28,9 @@ while [[ "$#" -gt 0 ]]; do
2728
PUBLIC_URL="$2"
2829
shift
2930
;;
31+
--ci)
32+
CI_MODE=true
33+
;;
3034
native)
3135
NATIVE_OPT=true
3236
;;
@@ -35,47 +39,76 @@ while [[ "$#" -gt 0 ]]; do
3539
;;
3640
*)
3741
echo "Unknown parameter: $1"
38-
echo "Usage: $0 [--target=<target>] [--wasm] [--native] [--public-url=<url>]"
42+
echo "Usage: $0 [--target=<target>] [--wasm] [--native] [--public-url=<url>] [--ci]"
3943
exit 1
4044
;;
4145
esac
4246
shift
4347
done
4448

45-
RUSTFLAGS="-Csymbol-mangling-version=v0 -Zlocation-detail=none -Zfmt-debug=none"
49+
TRUNK_CMD="trunk"
50+
if [ "$CI_MODE" = true ]; then
51+
TRUNK_CMD="./trunk"
52+
echo "CI mode enabled: Using local trunk binary at $TRUNK_CMD"
53+
if [ ! -x "$TRUNK_CMD" ]; then
54+
echo "Error: CI mode specified, but '$TRUNK_CMD' not found or not executable."
55+
exit 1
56+
fi
57+
fi
58+
4659

4760
if [ -z "$TARGET" ] && [ "$BUILD_WASM" = false ]; then
4861
echo "Error: At least a target platform or the --wasm flag is required"
49-
echo "Usage: $0 [--target=<target>] [--wasm] [--native] [--public-url=<url>]"
62+
echo "Usage: $0 [--target=<target>] [--wasm] [--native] [--public-url=<url>] [--ci]"
5063
echo "Examples:"
5164
echo " $0 --target=x86_64-unknown-linux-gnu"
5265
echo " $0 x86_64-unknown-linux-gnu --native"
5366
echo " $0 --wasm"
5467
echo " $0 --wasm --public-url=https://example.com"
68+
echo " $0 --wasm --ci"
5569
exit 1
5670
fi
5771

72+
BASE_RUSTFLAGS="-Csymbol-mangling-version=v0 -Zlocation-detail=none -Zfmt-debug=none"
73+
5874
mv .cargo/.config.toml .cargo/config.toml
5975

6076
if [ "$BUILD_WASM" = true ]; then
6177
echo "Building particle-simulation for web..."
78+
WASM_RUSTFLAGS="$BASE_RUSTFLAGS -C target-feature=-nontrapping-fptoint"
6279
if [ -n "$PUBLIC_URL" ]; then
6380
echo "Using public URL: $PUBLIC_URL"
64-
RUSTFLAGS="$RUSTFLAGS -C target-feature=-nontrapping-fptoint" trunk build --release --public-url "$PUBLIC_URL"
81+
RUSTFLAGS="$WASM_RUSTFLAGS" "$TRUNK_CMD" build --release --public-url "$PUBLIC_URL"
6582
else
66-
RUSTFLAGS="$RUSTFLAGS -C target-feature=-nontrapping-fptoint" trunk build --release
83+
RUSTFLAGS="$WASM_RUSTFLAGS" "$TRUNK_CMD" build --release
84+
fi
85+
if [ $? -ne 0 ]; then
86+
echo "Error: trunk build failed."
87+
mv .cargo/config.toml .cargo/.config.toml
88+
exit 1
6789
fi
6890
fi
6991

7092
if [ -n "$TARGET" ]; then
93+
NATIVE_RUSTFLAGS="$BASE_RUSTFLAGS"
7194
if [ "$NATIVE_OPT" = true ]; then
7295
echo "Building particle-simulation for $TARGET with native CPU optimizations..."
73-
RUSTFLAGS="$RUSTFLAGS -C target-cpu=native"
96+
NATIVE_RUSTFLAGS="$NATIVE_RUSTFLAGS -C target-cpu=native"
7497
else
7598
echo "Building particle-simulation for $TARGET..."
7699
fi
77100

78-
RUSTFLAGS="$RUSTFLAGS -Clink-args=-fuse-ld=lld -Clink-args=-Wl,--icf=all" cargo +nightly build --target $TARGET --release
101+
NATIVE_RUSTFLAGS="$NATIVE_RUSTFLAGS -Clink-args=-fuse-ld=lld -Clink-args=-Wl,--icf=all"
102+
103+
RUSTFLAGS="$NATIVE_RUSTFLAGS" cargo +nightly build --target "$TARGET" --release
104+
105+
if [ $? -ne 0 ]; then
106+
echo "Error: cargo build failed."
107+
mv .cargo/config.toml .cargo/.config.toml
108+
exit 1
109+
fi
79110
fi
80111

81112
mv .cargo/config.toml .cargo/.config.toml
113+
114+
echo "Build finished successfully."

0 commit comments

Comments
 (0)