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

Enable strip binary on release build #48

Merged
merged 2 commits into from
Apr 24, 2022

Conversation

MiSawa
Copy link
Contributor

@MiSawa MiSawa commented Mar 31, 2022

This PR is to enable stripping option on the release build of the generated cargo project. Resolves #36

Comparison of built binary

It actually works, and the binary size of a hello world program reduced from 3.5M to 300K.

$ ./rust-script-no-strip --clear-cache ./hello.rs
Hello world!
$ file $binary
/home/misawa/.cache/rust-script/binaries/release/hello_59500b17925d6a21fe59ae0b: ELF 64-bit LSB pie executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, BuildID[sha1]=da41165504c484ad9734ded644b275ae7d4c2030, for GNU/Linux 4.4.0, with debug_info, not stripped
$ du $binary
3.5M    /home/misawa/.cache/rust-script/binaries/release/hello_59500b17925d6a21fe59ae0b
$ ./rust-script-with-strip --clear-cache ./hello.rs
Hello world!
$ file $binary
/home/misawa/.cache/rust-script/binaries/release/hello_59500b17925d6a21fe59ae0b: ELF 64-bit LSB pie executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, BuildID[sha1]=558091b50cb49c7c88877998d454b9bda928a973, for GNU/Linux 4.4.0, stripped
$ du $binary
300K    /home/misawa/.cache/rust-script/binaries/release/hello_59500b17925d6a21fe59ae0b

Comparison of build+run time

I'd say they're the same.

$ hyperfine './rust-script-no-strip --clear-cache ./hello.rs' './rust-script-with-strip --clear-cache ./hello.rs' -w 10
Benchmark 1: ./rust-script-no-strip --clear-cache ./hello.rs
  Time (mean ± σ):      1.114 s ±  0.066 s    [User: 0.946 s, System: 0.180 s]
  Range (min … max):    1.050 s …  1.253 s    10 runs
 
Benchmark 2: ./rust-script-with-strip --clear-cache ./hello.rs
  Time (mean ± σ):      1.051 s ±  0.035 s    [User: 0.882 s, System: 0.186 s]
  Range (min … max):    1.006 s …  1.128 s    10 runs
 
Summary
  './rust-script-with-strip --clear-cache ./hello.rs' ran
    1.06 ± 0.07 times faster than './rust-script-no-strip --clear-cache ./hello.rs'

Compatibilities

Works fine (I mean, just a warning message that's shown only when you passed -o) when used with older version of cargo.

$ rustup default 1.42.0-x86_64-unknown-linux-gnu
info: using existing install for '1.42.0-x86_64-unknown-linux-gnu'
info: default toolchain set to '1.42.0-x86_64-unknown-linux-gnu'

  1.42.0-x86_64-unknown-linux-gnu unchanged - rustc 1.42.0 (b8cedc004 2020-03-09)

$ ./rust-script-with-strip --clear-cache -o ./hello.rs
warning: unused manifest key: profile.release.strip
   Compiling hello v0.1.0 (/home/misawa/.cache/rust-script/projects/59500b17925d6a21fe59ae0b)
    Finished release [optimized] target(s) in 0.79s
     Running `/home/misawa/.cache/rust-script/binaries/release/hello_59500b17925d6a21fe59ae0b`
Hello world!

Other consideration

I don't have Windows / Mac OSX, so unsure how it perform on those environment.

@fornwall fornwall merged commit 92d3157 into fornwall:master Apr 24, 2022
@fornwall
Copy link
Owner

Thanks! Will be included in version 0.21.0, which will be released shortly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add --strip flag
2 participants