How can I find out why I'm rebuilding/rechecking crates?

Does it seem to anyone else like Rust often does more rebuilding and rechecking than could possibly be required?

I'd love to understand, when cargo build rebuilds a crate or cargo check rechecks a crate, why that is happening. Are there any good tools or techniques for this?

Try passing -v. This should make cargo report why it rebuilt a crate.

2 Likes

If you are seeing rebuilds of every dependency, then the usual cause of that is that you are building from two different environments (e.g. IDE and terminal) with different RUSTFLAGS values, or directories with build.rustflags configured. You should avoid using RUSTFLAGS / build.rustflags if not strictly necessary, and if necessary, make sure that the value is always the same.

But, whether or not that's the problem, yes, use cargo build --verbose to diagnose the problem. Look for the first line with “Dirty” in the output to see what reason Cargo decided to rebuild that crate.

1 Like

Note that the RUSTFLAGS issue was fixed several releases ago.

For more thorough results than -v is

CARGO_LOG=cargo::core::compiler::fingerprint=trace cargo build

Some possible causes

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.