I have a strange issue that I can't reliably repro, but I still wanted to ask in case it's a known issue.
Most of the time when I do cargo build or cargo run repeatedly without changing any Rust code it reuses the previous build and command runs fast.
But sometimes my tree gets into a state where cargo build and run builds every time. E.g. I do cargo build; cargo build and the second command still takes about 10 seconds.
I can't figure out when and how this happens and it's extremely annoying, because I have a bunch of scripts that use cargo run and they take forever when my tree gets into this state.
Does this sound familiar to anyone? What could be the issue?
AFAIK one common situation where this can happen is if you have rust-analyzer running on that projest and it’s using a different set of flags than the ones you’re using when compiling from the terminal with cargo
You can use cargo build --verbose to see why Cargo thinks a rebuild is needed. This will add lines to the progress output that say “Fresh” or “Dirty”; look for the first “Dirty” to see what it says.
Also, is it rebuilding a specific crate in your project, or everything in the dependency tree?
Do you have any build scripts (build.rs) in your project? A build script that doesn’t emit rerun-if-changed directives will be rerun every time.
Dirty fir v0.1.0 (/home/omer/fir/fir): the file `.git/refs/heads/con_syntax` has changed (1754594127.401205111s, 1h 24m 21s after last build at 1754589066.029161970s)
Not sure what that means, why is it tracking a file in .git?
Cargo relies on being able to update timestamps of files with the same precision as the underlying filesystem has (losslessly). Docker can't do that. Docker mounts read timestamps with nanosecond precision, but for some reason can write timestamps only with whole-second precision.