Cargo: Option for stripping binary

Created on 1 Jan 2017  路  10Comments  路  Source: rust-lang/cargo

I think it would be helpful to have an option for stripping the binary (probably as default in release mode) because executables often get much smaller.

C-feature-request Command-build

Most helpful comment

(ugly) workaround is:

~sh
RUSTFLAGS='-C link-arg=-s' cargo build --release
~

https://github.com/rust-lang/cargo/issues/4122#issuecomment-378928831

All 10 comments

I would like to have this as well. See also #4122.

(ugly) workaround is:

~sh
RUSTFLAGS='-C link-arg=-s' cargo build --release
~

https://github.com/rust-lang/cargo/issues/4122#issuecomment-378928831

Possible solution is the recently released cargo-strip

Possible solution is the recently released cargo-strip

That appears to just call strip, which may not always be what you want (you may want x86_64-linux-musl-strip, for example).

@dewyatt I'd suggest opening an issue with cargo-strip as that may be a use case that wasn't considered.

For the record, I was slightly confused why my release binary had 3 MB of size, and I found _debug_ info inside of my _release_ binary. After strip the size is just 500 KB.

It's now possible (with a nightly compiler) to have the linker strip symbols from the final build by adding a strip = "symbols" line to your [profile.dev]/[profile.release] section in Cargo.toml (and enable the corresponding cargo-feature).

To be clear, the Cargo support will land in nightly sometime next week.

When will this feature to be released in stable channel? It seems that this feature is not included in v1.46.0. @ehuss

@zonyitoo It will not appear in stable until the feature is stabilized. You can follow the tracking issue at https://github.com/rust-lang/rust/issues/72110 to see when it is stabilized.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

fprijate picture fprijate  路  3Comments

japaric picture japaric  路  3Comments

tensorchen picture tensorchen  路  3Comments

briansmith picture briansmith  路  3Comments

ehuss picture ehuss  路  3Comments