Merge pull request #256 from NobodyXu/optimize-release-build

Use `build-std` feature for release build to reduce binary size
This commit is contained in:
Jiahao XU 2022-07-31 19:44:13 +10:00 committed by GitHub
commit 3d967a5405
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 1 deletions

View file

@ -73,6 +73,10 @@ jobs:
if: "!matrix.use-cross" if: "!matrix.use-cross"
run: rustup target add ${{ matrix.target }} run: rustup target add ${{ matrix.target }}
- name: Install rust-src
if: inputs.for_release
run: rustup component add rust-src
- name: Select compile settings - name: Select compile settings
shell: bash shell: bash
run: | run: |
@ -106,6 +110,8 @@ jobs:
- name: Build - name: Build
run: ${{ env.CTOOL }} build ${{ env.CARGS }} run: ${{ env.CTOOL }} build ${{ env.CARGS }}
env:
RUSTFLAGS: ${{ env.RUSTFLAGS }}
- name: Get output - name: Get output
shell: bash shell: bash

View file

@ -1,7 +1,9 @@
if $for_release then { if $for_release then {
output: "release", output: "release",
profile: "release", profile: "release",
args: ($matrix.release_build_args // ""), # Use build-std to build a std library optimized for size and abort immediately on abort,
# so that format string for `unwrap`/`expect`/`unreachable`/`panic` can be optimized out.
args: ($matrix.release_build_args // "-Z build-std=std,panic_abort -Z build-std-features=panic_immediate_abort"),
features: ($matrix.release_features // []), features: ($matrix.release_features // []),
} else { } else {
output: "debug", output: "debug",
@ -10,6 +12,12 @@ if $for_release then {
features: ($matrix.debug_features // ["rustls", "fancy-with-backtrace"]), features: ($matrix.debug_features // ["rustls", "fancy-with-backtrace"]),
} end } end
| |
.rustflags = (
if $for_release and $matrix.target == "aarch64-unknown-linux-musl" or $matrix.target == "armv7-unknown-linux-musleabihf"
then "-C link-arg=-lgcc -Clink-arg=-static-libgcc"
else "" end
)
|
.features = ( .features = (
if (.features | length > 0) if (.features | length > 0)
then "--no-default-features --features \(.features | join(","))" then "--no-default-features --features \(.features | join(","))"
@ -21,6 +29,7 @@ if $for_release then {
CTOOL: (if ($matrix."use-cross" // false) then "cross" else "cargo" end), CTOOL: (if ($matrix."use-cross" // false) then "cross" else "cargo" end),
COUTPUT: .output, COUTPUT: .output,
CARGS: "--target \($matrix.target) --profile \(.profile) \(.features) \(.args)", CARGS: "--target \($matrix.target) --profile \(.profile) \(.features) \(.args)",
RUSTFLAGS: .rustflags,
} }
| |
to_entries[] | "\(.key)=\(.value)" to_entries[] | "\(.key)=\(.value)"