mirror of
https://github.com/cargo-bins/cargo-binstall.git
synced 2025-04-21 13:08:42 +00:00
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:
commit
3d967a5405
2 changed files with 16 additions and 1 deletions
6
.github/workflows/build.yml
vendored
6
.github/workflows/build.yml
vendored
|
@ -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
|
||||
|
|
|
@ -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)"
|
||||
|
|
Loading…
Add table
Reference in a new issue