From 621c2872639392195c0a8ac577b285d206562ce8 Mon Sep 17 00:00:00 2001 From: neverland Date: Tue, 11 Aug 2026 16:13:01 +0800 Subject: [PATCH 1/4] build(native): reduce release binary size --- .cargo/release.toml | 3 +++ .github/workflows/reusable-native-build.yml | 1 + packages/rstack/package.json | 2 +- rust-toolchain.toml | 3 ++- 4 files changed, 7 insertions(+), 2 deletions(-) create mode 100644 .cargo/release.toml diff --git a/.cargo/release.toml b/.cargo/release.toml new file mode 100644 index 00000000..bd3a5760 --- /dev/null +++ b/.cargo/release.toml @@ -0,0 +1,3 @@ +# Remove source locations from release panic metadata to reduce binary size. +[target.'cfg(all())'] +rustflags = ["-Zlocation-detail=none"] diff --git a/.github/workflows/reusable-native-build.yml b/.github/workflows/reusable-native-build.yml index 4a893f2f..861c90d0 100644 --- a/.github/workflows/reusable-native-build.yml +++ b/.github/workflows/reusable-native-build.yml @@ -109,6 +109,7 @@ jobs: ;; esac + args+=(-- --config ../../.cargo/release.toml) pnpm exec napi "${args[@]}" - name: Upload native binding diff --git a/packages/rstack/package.json b/packages/rstack/package.json index a678ae1e..89782fd7 100644 --- a/packages/rstack/package.json +++ b/packages/rstack/package.json @@ -67,7 +67,7 @@ "build": "rslib", "build:native": "napi build --config-path napi.json --platform --manifest-path ../../Cargo.toml --package rstack-binding --package-json-path package.json --output-dir . --js binding.cjs --dts binding.d.cts", "build:native:ci": "napi build --config-path napi.json --platform --profile ci --manifest-path ../../Cargo.toml --package rstack-binding --package-json-path package.json --output-dir . --js binding.cjs --dts binding.d.cts", - "build:native:release": "napi build --config-path napi.json --platform --release --manifest-path ../../Cargo.toml --package rstack-binding --package-json-path package.json --output-dir . --js binding.cjs --dts binding.d.cts", + "build:native:release": "napi build --config-path napi.json --platform --release --manifest-path ../../Cargo.toml --package rstack-binding --package-json-path package.json --output-dir . --js binding.cjs --dts binding.d.cts -- --config ../../.cargo/release.toml", "dev": "rslib -w", "package:native": "napi create-npm-dirs --config-path napi.json", "test": "rs test" diff --git a/rust-toolchain.toml b/rust-toolchain.toml index 99461977..6f8397f5 100644 --- a/rust-toolchain.toml +++ b/rust-toolchain.toml @@ -1,4 +1,5 @@ [toolchain] -channel = "1.97.1" +# Required by the release-only -Zlocation-detail=none flag. +channel = "nightly-2026-04-16" components = ["clippy", "rustfmt"] profile = "minimal" From 25c7dfb56eea6060434d1f09c2f663aab805f6d3 Mon Sep 17 00:00:00 2001 From: neverland Date: Tue, 11 Aug 2026 16:16:42 +0800 Subject: [PATCH 2/4] refactor(native): inline release rustflags --- .cargo/release.toml | 3 --- .github/workflows/reusable-native-build.yml | 2 +- packages/rstack/package.json | 2 +- 3 files changed, 2 insertions(+), 5 deletions(-) delete mode 100644 .cargo/release.toml diff --git a/.cargo/release.toml b/.cargo/release.toml deleted file mode 100644 index bd3a5760..00000000 --- a/.cargo/release.toml +++ /dev/null @@ -1,3 +0,0 @@ -# Remove source locations from release panic metadata to reduce binary size. -[target.'cfg(all())'] -rustflags = ["-Zlocation-detail=none"] diff --git a/.github/workflows/reusable-native-build.yml b/.github/workflows/reusable-native-build.yml index 861c90d0..6679b042 100644 --- a/.github/workflows/reusable-native-build.yml +++ b/.github/workflows/reusable-native-build.yml @@ -109,7 +109,7 @@ jobs: ;; esac - args+=(-- --config ../../.cargo/release.toml) + args+=(-- --config "target.'cfg(all())'.rustflags = ['-Zlocation-detail=none']") pnpm exec napi "${args[@]}" - name: Upload native binding diff --git a/packages/rstack/package.json b/packages/rstack/package.json index 89782fd7..8ba649ca 100644 --- a/packages/rstack/package.json +++ b/packages/rstack/package.json @@ -67,7 +67,7 @@ "build": "rslib", "build:native": "napi build --config-path napi.json --platform --manifest-path ../../Cargo.toml --package rstack-binding --package-json-path package.json --output-dir . --js binding.cjs --dts binding.d.cts", "build:native:ci": "napi build --config-path napi.json --platform --profile ci --manifest-path ../../Cargo.toml --package rstack-binding --package-json-path package.json --output-dir . --js binding.cjs --dts binding.d.cts", - "build:native:release": "napi build --config-path napi.json --platform --release --manifest-path ../../Cargo.toml --package rstack-binding --package-json-path package.json --output-dir . --js binding.cjs --dts binding.d.cts -- --config ../../.cargo/release.toml", + "build:native:release": "napi build --config-path napi.json --platform --release --manifest-path ../../Cargo.toml --package rstack-binding --package-json-path package.json --output-dir . --js binding.cjs --dts binding.d.cts -- --config \"target.'cfg(all())'.rustflags = ['-Zlocation-detail=none']\"", "dev": "rslib -w", "package:native": "napi create-npm-dirs --config-path napi.json", "test": "rs test" From 89e037ca59f74bdda790b6431441a770b11620d4 Mon Sep 17 00:00:00 2001 From: neverland Date: Tue, 11 Aug 2026 16:17:57 +0800 Subject: [PATCH 3/4] chore(ci): explain release rustflag --- .github/workflows/reusable-native-build.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/reusable-native-build.yml b/.github/workflows/reusable-native-build.yml index 6679b042..e93f890d 100644 --- a/.github/workflows/reusable-native-build.yml +++ b/.github/workflows/reusable-native-build.yml @@ -109,6 +109,7 @@ jobs: ;; esac + # Omit panic source locations to reduce the release binary size. args+=(-- --config "target.'cfg(all())'.rustflags = ['-Zlocation-detail=none']") pnpm exec napi "${args[@]}" From 8c5c75cf0400b999a17e0e15ff9d161c4ec51f40 Mon Sep 17 00:00:00 2001 From: neverland Date: Tue, 11 Aug 2026 16:20:15 +0800 Subject: [PATCH 4/4] refactor(native): use release Cargo config --- .cargo/release.toml | 3 +++ .github/workflows/reusable-native-build.yml | 2 +- packages/rstack/package.json | 2 +- 3 files changed, 5 insertions(+), 2 deletions(-) create mode 100644 .cargo/release.toml diff --git a/.cargo/release.toml b/.cargo/release.toml new file mode 100644 index 00000000..bd3a5760 --- /dev/null +++ b/.cargo/release.toml @@ -0,0 +1,3 @@ +# Remove source locations from release panic metadata to reduce binary size. +[target.'cfg(all())'] +rustflags = ["-Zlocation-detail=none"] diff --git a/.github/workflows/reusable-native-build.yml b/.github/workflows/reusable-native-build.yml index e93f890d..d06dbd48 100644 --- a/.github/workflows/reusable-native-build.yml +++ b/.github/workflows/reusable-native-build.yml @@ -110,7 +110,7 @@ jobs: esac # Omit panic source locations to reduce the release binary size. - args+=(-- --config "target.'cfg(all())'.rustflags = ['-Zlocation-detail=none']") + args+=(-- --config ../../.cargo/release.toml) pnpm exec napi "${args[@]}" - name: Upload native binding diff --git a/packages/rstack/package.json b/packages/rstack/package.json index 8ba649ca..89782fd7 100644 --- a/packages/rstack/package.json +++ b/packages/rstack/package.json @@ -67,7 +67,7 @@ "build": "rslib", "build:native": "napi build --config-path napi.json --platform --manifest-path ../../Cargo.toml --package rstack-binding --package-json-path package.json --output-dir . --js binding.cjs --dts binding.d.cts", "build:native:ci": "napi build --config-path napi.json --platform --profile ci --manifest-path ../../Cargo.toml --package rstack-binding --package-json-path package.json --output-dir . --js binding.cjs --dts binding.d.cts", - "build:native:release": "napi build --config-path napi.json --platform --release --manifest-path ../../Cargo.toml --package rstack-binding --package-json-path package.json --output-dir . --js binding.cjs --dts binding.d.cts -- --config \"target.'cfg(all())'.rustflags = ['-Zlocation-detail=none']\"", + "build:native:release": "napi build --config-path napi.json --platform --release --manifest-path ../../Cargo.toml --package rstack-binding --package-json-path package.json --output-dir . --js binding.cjs --dts binding.d.cts -- --config ../../.cargo/release.toml", "dev": "rslib -w", "package:native": "napi create-npm-dirs --config-path napi.json", "test": "rs test"