Building
Usually, building a Rust project is as simple as running the appropriate Cargo command, and everything just works:
cargo build --release
However, doing builds on a larger scale can present some more challenges. For example, always building the same dependencies in CI can be wasteful. Some projects want to provide builds for multiple architectures.
This chapter discusses some issues you might run into when building Rust code in your project, and strategies for how you might solve them.
You can also use cargo-wizard to apply some preset templates to optimize your project’s build process for faster builds, smaller binaries, or better runtime performance.
Reading
Tips For Faster Rust Compile Times by Matthias Endler
Matthias goes through an extensive list of tips for getting faster Rust compile times. These include making sure your toolchain is up-to-date, enabling the parallel compiler frontend, removing unused dependencies, debugging dependency compile times, splitting large crates into smaller ones, optimizing workspaces, compilation caching, and many more.
Fast Rust Builds (archived) by Alex Kladov
Alex explains some strategies to speed up Rust compilation. He explains that the Rust programming language has prioritized execution speed and programmer productivity over compilation speed. He gives recommendations for how to set up your CI pipeline, pruning dependencies, what code styles lead to faster compilation times.
Stupidly effective ways to optimize Rust compile time (archived) by Tianxiao Shen
Tianxiao shares practical tips for optimizing Rust compilation times, including dependency management strategies, workspace organization, and compiler flags that can significantly reduce build times in real-world projects.
What part of Rust compilation is the bottleneck? (archived) by Jakub Beránek
Jakub analyzes the Rust compilation process to identify the main bottlenecks, examining different phases like parsing, type checking, and code generation to help developers understand where compilation time is actually spent.