@@ -4,6 +4,7 @@ TARGET=""
44BUILD_WASM=false
55NATIVE_OPT=false
66PUBLIC_URL=" "
7+ CI_MODE=false
78
89while [[ " $# " -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
4347done
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
4760if [ -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
5670fi
5771
72+ BASE_RUSTFLAGS=" -Csymbol-mangling-version=v0 -Zlocation-detail=none -Zfmt-debug=none"
73+
5874mv .cargo/.config.toml .cargo/config.toml
5975
6076if [ " $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
6890fi
6991
7092if [ -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
79110fi
80111
81112mv .cargo/config.toml .cargo/.config.toml
113+
114+ echo " Build finished successfully."
0 commit comments