diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 67dda4b4..93a7af04 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -73,6 +73,10 @@ jobs: if: "!matrix.use-cross" run: rustup target add ${{ matrix.target }} + - name: Install rust-src + if: inputs.for_release + run: rustup component add rust-src + - name: Select compile settings shell: bash run: | @@ -106,6 +110,8 @@ jobs: - name: Build run: ${{ env.CTOOL }} build ${{ env.CARGS }} + env: + RUSTFLAGS: ${{ env.RUSTFLAGS }} - name: Get output shell: bash diff --git a/ci-scripts/compile-settings.jq b/ci-scripts/compile-settings.jq index ba1df64a..aa0e37f0 100644 --- a/ci-scripts/compile-settings.jq +++ b/ci-scripts/compile-settings.jq @@ -1,7 +1,9 @@ if $for_release then { output: "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 // []), } else { output: "debug", @@ -10,6 +12,12 @@ if $for_release then { features: ($matrix.debug_features // ["rustls", "fancy-with-backtrace"]), } 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 = ( if (.features | length > 0) 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), COUTPUT: .output, CARGS: "--target \($matrix.target) --profile \(.profile) \(.features) \(.args)", + RUSTFLAGS: .rustflags, } | to_entries[] | "\(.key)=\(.value)"