Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Option for stripping binary #3483

Closed
torkleyy opened this issue Jan 1, 2017 · 11 comments · Fixed by #8246
Closed

Option for stripping binary #3483

torkleyy opened this issue Jan 1, 2017 · 11 comments · Fixed by #8246
Labels
C-feature-request Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted` Command-build

Comments

@torkleyy
Copy link
Contributor

torkleyy commented Jan 1, 2017

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.

@carols10cents carols10cents added C-feature-request Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted` Command-build labels Sep 29, 2017
@mdsteele
Copy link

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

@ghost
Copy link

ghost commented Oct 19, 2018

(ugly) workaround is:

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

#4122 (comment)

@johnthagen
Copy link
Contributor

Possible solution is the recently released cargo-strip

@dewyatt
Copy link

dewyatt commented Jan 12, 2020

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).

@johnthagen
Copy link
Contributor

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

@fadeevab
Copy link

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.

elasticdog added a commit to elasticdog/taxonate that referenced this issue May 1, 2020
I'm still having cargo optimize for speed, but have configured the
following tweaks:

- Enable Link Time Optimization (LTO)
- Reduce Parallel Code Generation Units

There's no way to have cargo strip the binaries automatically, but using
the following command will handle it for you:

    $ RUSTFLAGS='-C link-arg=-s' cargo build --release

Putting these changes into place shouldn't affect the speed or behavior
of the released binary, but it does increase the compilation time. For
size reference, no optimizations resulted in a binary that was ~4.8M,and
after these steps, the binary is ~1.8M (a savings of over 60%).

See:
- https://github.com/johnthagen/min-sized-rust
- rust-lang/cargo#3483
@bors bors closed this as completed in d18e4b3 May 19, 2020
@GabrielMajeri
Copy link
Contributor

GabrielMajeri commented May 20, 2020

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).

@ehuss
Copy link
Contributor

ehuss commented May 20, 2020

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

@zonyitoo
Copy link

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

@ehuss
Copy link
Contributor

ehuss commented Aug 27, 2020

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-feature-request Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted` Command-build
Projects
None yet
10 participants