Skip to content
This repository has been archived by the owner on Nov 29, 2023. It is now read-only.

Commit

Permalink
Adjust complilation to reduce release binary size
Browse files Browse the repository at this point in the history
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
  • Loading branch information
elasticdog committed May 1, 2020
1 parent fb47cca commit 4fc3daa
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,7 @@ features = ["derive"]

[badges]
maintenance = { status = "actively-developed" }

[profile.release]
codegen-units = 1
lto = true

0 comments on commit 4fc3daa

Please sign in to comment.