Cargo book and incremental compilation

On my Gentoo Linux box "cargo build --release" was incremental from the beginning, at least since end of 2023. So I was a bit surprised, that the Cargo book tells us that only debug built uses incremental build as default. I understand that I can change that by overwriting the profiles in Cargo.toml, by environment variables and other ways. And I think I also understand why the incremental might be turned off for release builds -- reproducible builds for utmost performance.

But the issue is: From Cargo book

The default settings for the release profile are:

[profile.release]
opt-level = 3
debug = false
split-debuginfo = '...'  # Platform-specific.
strip = "none"
debug-assertions = false
overflow-checks = false
lto = false
panic = 'unwind'
incremental = false
codegen-units = 16
rpath = false

And on my box incremental is enabled for release build. )My Rust is provided by Gentoo package manager, not by Rustup.)

So might the Cargo book be outdated? Additional, the book contains the following sentence:

https://doc.rust-lang.org/cargo/reference/profiles.html?highlight=incremental#incremental

"Incremental compilation is only used for workspace members and “path” dependencies."

I don't really understand this sentence, as incremental compilation should at least be active for all debug builds.

Note, that actual reason why I care for these details is, that after studying the Cargo book, I wrote in "Rust for C-Programmers" that incremental is the default only for debug builds, and now I have the feeling that what I told is wrong.

Are you sure you are using incremental compilation? Cargo caching the build artefacts of your dependencies is not meant by incremental compilation. Incremental compilation only concerns rebuilding a single crate after you made some changes to its source code.

2 Likes

Oh -- I was not aware of this difference. I have to study that point in more detail.

I was only aware, that my chess game took about 60 secs for the first builds (Bevy or EGUI), and then, after editing only the engine.rs file, a rebuild took only 2 to 3 secs.