Cargo-bake - Compile Rust faster


Hey. Here’s this little tool that tweaks rustc’s optimization settings to produce release builds faster: cargo-bake. The idea is that cargo build --release is unnecessarily aggressive with optimizations, and we can build faster without sacrificing much performance. I’m happy to use this as a platform for experiments in modifying the LLVM optimization pipeline; PRs welcome.


Compile Rust faster with smarter defaults. Alternative to cargo build. The default bake compiles more quickly than Cargo’s
--release and produces reasonably fast code.


$ cargo install cargo-bake
$ cargo bake <other-cargo-build-options>

The default (“normal”) bake produces compiler flags more-or-less

-C opt-level=2
-C inline-threshold=25
-C no-vectorize-loops
-C codegen-units=$NUM_CPUS_UP_TO_4
-Z no-verify
-C debuginfo=0

Besides the normal bake, cargo-bake also accepts a --fast bake,
which is similar to Cargo’s default, a --slow bake, similar to
Cargo’s release, and a --glacial bake, which additionally adds LTO.

By default cargo-bake, in all modes, reduces debuginfo generation to
line numbers only. Use the --debug flag to turn on full debuginfo.

Run cargo bake --compare to compare compile time of cargo build --release to cargo bake.

Note: cargo-bake requires the 2015-11-23 nightlies or later.