From 98d8a96a02f34966bdf64621a2062021ed73ce5f Mon Sep 17 00:00:00 2001 From: Jiahao XU Date: Fri, 29 Jul 2022 19:00:35 +1000 Subject: [PATCH 1/5] Use `build-std` feature for release build to reduce binary size Signed-off-by: Jiahao XU --- .github/workflows/build.yml | 2 +- ci-scripts/compile-settings.jq | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 67dda4b4..b9f3e2a9 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -105,7 +105,7 @@ jobs: run: sudo ./ci-scripts/install-deps.sh - name: Build - run: ${{ env.CTOOL }} build ${{ env.CARGS }} + run: ${{ env.CTOOL }} ${{ env.TOOLCHAIN }} build ${{ env.CARGS }} - name: Get output shell: bash diff --git a/ci-scripts/compile-settings.jq b/ci-scripts/compile-settings.jq index ba1df64a..676bc105 100644 --- a/ci-scripts/compile-settings.jq +++ b/ci-scripts/compile-settings.jq @@ -1,10 +1,14 @@ if $for_release then { output: "release", + toolchain: "+nightly", 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", + toolchain: "+stable", profile: "dev", args: ($matrix.debug_build_args // ""), features: ($matrix.debug_features // ["rustls", "fancy-with-backtrace"]), @@ -19,6 +23,7 @@ if $for_release then { { CBIN: (if ($matrix.target | test("windows")) then "cargo-binstall.exe" else "cargo-binstall" end), CTOOL: (if ($matrix."use-cross" // false) then "cross" else "cargo" end), + TOOLCHAIN: .toolchain, COUTPUT: .output, CARGS: "--target \($matrix.target) --profile \(.profile) \(.features) \(.args)", } From 7a7220b1a2f07ccfec585cad1ab92517ec448566 Mon Sep 17 00:00:00 2001 From: Jiahao XU Date: Fri, 29 Jul 2022 19:03:18 +1000 Subject: [PATCH 2/5] Fix build: Rm unnecessary `env.TOOLCHAIN` Since we build it using +nightly anyway. Signed-off-by: Jiahao XU --- .github/workflows/build.yml | 2 +- ci-scripts/compile-settings.jq | 3 --- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index b9f3e2a9..67dda4b4 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -105,7 +105,7 @@ jobs: run: sudo ./ci-scripts/install-deps.sh - name: Build - run: ${{ env.CTOOL }} ${{ env.TOOLCHAIN }} build ${{ env.CARGS }} + run: ${{ env.CTOOL }} build ${{ env.CARGS }} - name: Get output shell: bash diff --git a/ci-scripts/compile-settings.jq b/ci-scripts/compile-settings.jq index 676bc105..ae905cf0 100644 --- a/ci-scripts/compile-settings.jq +++ b/ci-scripts/compile-settings.jq @@ -1,6 +1,5 @@ if $for_release then { output: "release", - toolchain: "+nightly", profile: "release", # 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. @@ -8,7 +7,6 @@ if $for_release then { features: ($matrix.release_features // []), } else { output: "debug", - toolchain: "+stable", profile: "dev", args: ($matrix.debug_build_args // ""), features: ($matrix.debug_features // ["rustls", "fancy-with-backtrace"]), @@ -23,7 +21,6 @@ if $for_release then { { CBIN: (if ($matrix.target | test("windows")) then "cargo-binstall.exe" else "cargo-binstall" end), CTOOL: (if ($matrix."use-cross" // false) then "cross" else "cargo" end), - TOOLCHAIN: .toolchain, COUTPUT: .output, CARGS: "--target \($matrix.target) --profile \(.profile) \(.features) \(.args)", } From af3b87df7af6ef8e723e116ad77ea5e391288482 Mon Sep 17 00:00:00 2001 From: Jiahao XU Date: Fri, 29 Jul 2022 19:11:47 +1000 Subject: [PATCH 3/5] Fix releasae build: Install rust-src for release Signed-off-by: Jiahao XU --- .github/workflows/build.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 67dda4b4..57d04169 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: | From 9e5ff25be8ff5e2aa581faee804770dca0f29e0d Mon Sep 17 00:00:00 2001 From: Jiahao XU Date: Sun, 31 Jul 2022 13:12:27 +1000 Subject: [PATCH 4/5] Fix release build: Set `RUSTFLAGS` to link with libgcc statically Signed-off-by: Jiahao XU --- .github/workflows/build.yml | 2 ++ ci-scripts/compile-settings.jq | 8 ++++++++ 2 files changed, 10 insertions(+) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 57d04169..93a7af04 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -110,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 ae905cf0..72f45153 100644 --- a/ci-scripts/compile-settings.jq +++ b/ci-scripts/compile-settings.jq @@ -9,9 +9,16 @@ if $for_release then { output: "debug", profile: "dev", args: ($matrix.debug_build_args // ""), + rustflags: "", 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(","))" @@ -23,6 +30,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)" From a6889c678edcf2e2e8cb8df3fd4585c03687fcb7 Mon Sep 17 00:00:00 2001 From: Jiahao XU Date: Sun, 31 Jul 2022 16:21:31 +1000 Subject: [PATCH 5/5] Rm unused `rustflags` value in `ci-scripts/compile-settings.jq` Signed-off-by: Jiahao XU --- ci-scripts/compile-settings.jq | 1 - 1 file changed, 1 deletion(-) diff --git a/ci-scripts/compile-settings.jq b/ci-scripts/compile-settings.jq index 72f45153..aa0e37f0 100644 --- a/ci-scripts/compile-settings.jq +++ b/ci-scripts/compile-settings.jq @@ -9,7 +9,6 @@ if $for_release then { output: "debug", profile: "dev", args: ($matrix.debug_build_args // ""), - rustflags: "", features: ($matrix.debug_features // ["rustls", "fancy-with-backtrace"]), } end |