Skip to content

Commit c1ec614

Browse files
add compile time optimizations, remove unwanted CI and update gh-pages
ci to work with the new build scripts
1 parent f0b40fd commit c1ec614

File tree

9 files changed

+141
-201
lines changed

9 files changed

+141
-201
lines changed

.cargo/.config.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[unstable]
2+
build-std = ["std", "panic_abort"]
3+
build-std-features = ["panic_immediate_abort"]
4+
trim-paths = true

Trunk.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,5 @@ filehash = false
33

44
[tools]
55
wasm_opt = "version_123"
6+
wasm_bindgen = "0.2.100"
7+
minify = "on_release"

build.ps1

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
param(
2+
[switch]$native,
3+
[string]$publicUrl = "",
4+
[switch]$wasm
5+
)
6+
7+
$TARGET = "x86_64-pc-windows-msvc"
8+
9+
$env:RUSTFLAGS = "-Csymbol-mangling-version=v0 -Zlocation-detail=none -Zfmt-debug=none"
10+
11+
mv .cargo/.config.toml .cargo/config.toml
12+
13+
if ($wasm -or $publicUrl -ne "") {
14+
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
22+
}
23+
}
24+
25+
if ($native) {
26+
Write-Host "Building particle-simulation for $TARGET with native CPU optimizations..."
27+
$env:RUSTFLAGS += " -C target-cpu=native"
28+
} else {
29+
Write-Host "Building particle-simulation for $TARGET..."
30+
}
31+
32+
$env:RUSTFLAGS += " -Clink-args=-fuse-ld=lld -Clink-args=-Wl,--icf=all"
33+
34+
cargo +nightly build --target $TARGET --release
35+
36+
mv .cargo/config.toml .cargo/.config.toml
37+
38+
exit $LASTEXITCODE

build.sh

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
#!/bin/bash
2+
3+
TARGET=""
4+
BUILD_WASM=false
5+
NATIVE_OPT=false
6+
PUBLIC_URL=""
7+
8+
while [[ "$#" -gt 0 ]]; do
9+
case $1 in
10+
--target=*)
11+
TARGET="${1#*=}"
12+
;;
13+
--target)
14+
TARGET="$2"
15+
shift
16+
;;
17+
--wasm)
18+
BUILD_WASM=true
19+
;;
20+
--native)
21+
NATIVE_OPT=true
22+
;;
23+
--public-url=*)
24+
PUBLIC_URL="${1#*=}"
25+
;;
26+
--public-url)
27+
PUBLIC_URL="$2"
28+
shift
29+
;;
30+
native)
31+
NATIVE_OPT=true
32+
;;
33+
*-*-*) # matches typical rust targets like x86_64-unknown-linux-gnu
34+
TARGET="$1"
35+
;;
36+
*)
37+
echo "Unknown parameter: $1"
38+
echo "Usage: $0 [--target=<target>] [--wasm] [--native] [--public-url=<url>]"
39+
exit 1
40+
;;
41+
esac
42+
shift
43+
done
44+
45+
RUSTFLAGS="-Csymbol-mangling-version=v0 -Zlocation-detail=none -Zfmt-debug=none"
46+
47+
if [ -z "$TARGET" ] && [ "$BUILD_WASM" = false ]; then
48+
echo "Error: At least a target platform or the --wasm flag is required"
49+
echo "Usage: $0 [--target=<target>] [--wasm] [--native] [--public-url=<url>]"
50+
echo "Examples:"
51+
echo " $0 --target=x86_64-unknown-linux-gnu"
52+
echo " $0 x86_64-unknown-linux-gnu --native"
53+
echo " $0 --wasm"
54+
echo " $0 --wasm --public-url=https://example.com"
55+
exit 1
56+
fi
57+
58+
mv .cargo/.config.toml .cargo/config.toml
59+
60+
if [ "$BUILD_WASM" = true ]; then
61+
echo "Building particle-simulation for web..."
62+
if [ -n "$PUBLIC_URL" ]; then
63+
echo "Using public URL: $PUBLIC_URL"
64+
RUSTFLAGS="$RUSTFLAGS -C target-feature=-nontrapping-fptoint" trunk build --release --public-url "$PUBLIC_URL"
65+
else
66+
RUSTFLAGS="$RUSTFLAGS -C target-feature=-nontrapping-fptoint" trunk build --release
67+
fi
68+
fi
69+
70+
if [ -n "$TARGET" ]; then
71+
if [ "$NATIVE_OPT" = true ]; then
72+
echo "Building particle-simulation for $TARGET with native CPU optimizations..."
73+
RUSTFLAGS="$RUSTFLAGS -C target-cpu=native"
74+
else
75+
echo "Building particle-simulation for $TARGET..."
76+
fi
77+
78+
RUSTFLAGS="$RUSTFLAGS -Clink-args=-fuse-ld=lld -Clink-args=-Wl,--icf=all" cargo +nightly build --target $TARGET --release
79+
fi
80+
81+
mv .cargo/config.toml .cargo/.config.toml

index.html

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,12 @@
1313
<title>Particle Simulation</title>
1414

1515
<!-- config for our rust wasm binary. go to https://trunkrs.dev/assets/#rust for more customization -->
16-
<link data-trunk rel="rust" data-wasm-opt="4" />
16+
<link
17+
data-trunk
18+
rel="rust"
19+
data-wasm-opt="4"
20+
data-wasm-opt-params="--enable-bulk-memory"
21+
/>
1722
<!-- this is the base url relative to which other urls will be constructed. trunk will insert this from the public-url option -->
1823
<base data-trunk-public-url />
1924

rust-toolchain.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[toolchain]
2+
channel = "nightly"
3+
profile = "minimal"
4+
# TODO: Add additional targets
5+
targets = ["x86_64-unknown-linux-gnu", "wasm32-unknown-unknown"]

workflows/pages.yml

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,9 @@
11
name: Github Pages
22

3-
# By default, runs if you push to main. keeps your deployed app in sync with main branch.
43
on:
54
push:
65
branches:
76
- main
8-
# to only run when you do a new github release, comment out above part and uncomment the below trigger.
9-
# on:
10-
# release:
11-
# types:
12-
# - published
137

148
permissions:
159
contents: write # for committing to gh-pages branch.
@@ -21,22 +15,22 @@ jobs:
2115
- uses: actions/checkout@v4 # repo checkout
2216
- name: Setup toolchain for wasm
2317
run: |
24-
rustup update stable
25-
rustup default stable
18+
rustup update nightly
19+
rustup default nightly
2620
rustup set profile minimal
2721
rustup target add wasm32-unknown-unknown
2822
- name: Rust Cache # cache the rust build artefacts
2923
uses: Swatinem/rust-cache@v2
30-
- name: Download and install Trunk binary
31-
run: wget -qO- https://github.com/thedodd/trunk/releases/latest/download/trunk-x86_64-unknown-linux-gnu.tar.gz | tar -xzf-
24+
- name: install Trunk binary
25+
run: cargo install trunk
3226
- name: Build # build
3327
# Environment $public_url resolves to the github project page.
3428
# If using a user/organization page, remove the `${{ github.event.repository.name }}` part.
3529
# using --public-url something will allow trunk to modify all the href paths like from favicon.ico to repo_name/favicon.ico .
3630
# this is necessary for github pages where the site is deployed to username.github.io/repo_name and all files must be requested
3731
# relatively as eframe_template/favicon.ico. if we skip public-url option, the href paths will instead request username.github.io/favicon.ico which
3832
# will obviously return error 404 not found.
39-
run: ./trunk build --release --public-url $public_url
33+
run: ./build.sh --wasm --public-url "$public_url"
4034
env:
4135
public_url: "https://${{ github.repository_owner }}.github.io/${{ github.event.repository.name }}"
4236
- name: Deploy

workflows/rust.yml

Lines changed: 0 additions & 170 deletions
This file was deleted.

workflows/typos.yml

Lines changed: 0 additions & 19 deletions
This file was deleted.

0 commit comments

Comments
 (0)