1

I have a workspace project with multiple crates in it. If I run cargo test --workspace twice in a row locally, it will only compile the crates the first time. But if I push a build to CI, and then push another build with just a dummy change to the README, it will rebuild the crates.

I'm using the following github actions ci config, i.e. it's doing caching:

- uses: actions/checkout@v3
- uses: dtolnay/rust-toolchain@stable
- uses: Leafwing-Studios/cargo-cache@v1
- name: Run tests
  run: cargo test --workspace --release

I'm guessing that cargo build checks the timestamp of the files in the src directories, and since it's git cloning them out each time they're always "new", but I'm not sure if that's the case.

cafce25
  • 15,907
  • 4
  • 25
  • 31
  • 1
    https://stackoverflow.com/questions/70174147/how-do-i-make-cargo-show-what-files-are-causing-a-rebuild – PiRocks Feb 13 '23 at 15:54
  • Your CI might be using a container-based build in which case *any* source file change results in a complete rebuild, as one of the dependent layers has changed. Your local `cargo test` can finesse this better by checking individual files and their timestamps, etc. – tadman Feb 13 '23 at 16:21
  • 1
    Hm yeah I tried the `CARGO_LOG=cargo::core::compiler::fingerprint=info`, seems like it always thinks the files are updated because the timestamps are new, which I assume is because it's just been cloned in. I've posted an issue in the cargo repo: https://github.com/rust-lang/cargo/issues/11706 – Fredrik Norén Feb 13 '23 at 17:11

0 Answers0