-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Description
Problem
When running CI builds in CircleCI, I've noticed that caching the Cargo registry and target directory works most, but not all of the time to avoid rebuilding dependencies. In particular, tikv-jemalloc-sys is rebuilt on every CI run.
From what I can tell from reading the cargo::core::compiler::fingerprint log output, it looks like the issue is tikv-jemalloc-sys's build script emits a rerun-if-changed
directive for the jemalloc source directory published with the crate. It seems like Circle's caching logic does not preserve file modification times, and while that seems to normally be fine it forces rebuilds in this one particular case.
I believe the same should be true for basically any crate that does something similar (openssl-src, etc) but haven't checked.
Steps
- Depend on a published crate that reports a
rerun-if-changed
on files bundled with the crate. - Cache the Cargo source and target directories in a manner that does not preserve mtimes.
- Set that most dependencies in the crate graph (
cc
, etc) are correctly detected as not needing a rebuild, but thererun-if-changed
crate does not.
I've put together a simple project that reproduces the issue: https://github.com/sfackler/target-cache-test
A Circle build with fingerprint trace logging: https://app.circleci.com/pipelines/github/sfackler/target-cache-test/2/workflows/1dee508c-bd46-4729-a6a6-2715fff14c5a/jobs/2
A copy of the logs if you don't want to log into circle:
[2022-09-13T18:00:20Z DEBUG cargo::core::compiler::fingerprint] fingerprint at: /root/project/target/debug/.fingerprint/target-cache-test-ad795130651e176c/bin-target-cache-test
[2022-09-13T18:00:20Z DEBUG cargo::core::compiler::fingerprint] new local fingerprints deps "/usr/local/cargo/registry/src/github.com-1ecc6299db9ec823/libc-0.2.132"
[2022-09-13T18:00:20Z DEBUG cargo::core::compiler::fingerprint] max output mtime for "/usr/local/cargo/registry/src/github.com-1ecc6299db9ec823/libc-0.2.132" is "/root/project/target/debug/build/libc-875143ba2a651140/build_script_build-875143ba2a651140" 1663091920.000000000s
[2022-09-13T18:00:20Z DEBUG cargo::core::compiler::fingerprint] all paths up-to-date relative to "/root/project/target/debug/.fingerprint/libc-875143ba2a651140/dep-build-script-build-script-build" mtime=1663091920.000000000s
[2022-09-13T18:00:20Z DEBUG cargo::core::compiler::fingerprint] filesystem up-to-date "/usr/local/cargo/registry/src/github.com-1ecc6299db9ec823/libc-0.2.132"
[2022-09-13T18:00:20Z DEBUG cargo::core::compiler::fingerprint] max output mtime for "/usr/local/cargo/registry/src/github.com-1ecc6299db9ec823/libc-0.2.132" is "/root/project/target/debug/build/libc-06ac331ace17f261/output" 1663091920.000000000s
[2022-09-13T18:00:20Z DEBUG cargo::core::compiler::fingerprint] max dep mtime for "/usr/local/cargo/registry/src/github.com-1ecc6299db9ec823/libc-0.2.132" is "/root/project/target/debug/build/libc-875143ba2a651140/build_script_build-875143ba2a651140" 1663091920.000000000s
[2022-09-13T18:00:20Z DEBUG cargo::core::compiler::fingerprint] all paths up-to-date relative to "/root/project/target/debug/build/libc-06ac331ace17f261/output" mtime=1663091920.000000000s
[2022-09-13T18:00:20Z DEBUG cargo::core::compiler::fingerprint] filesystem up-to-date "/usr/local/cargo/registry/src/github.com-1ecc6299db9ec823/libc-0.2.132"
[2022-09-13T18:00:20Z DEBUG cargo::core::compiler::fingerprint] max output mtime for "/usr/local/cargo/registry/src/github.com-1ecc6299db9ec823/libc-0.2.132" is "/root/project/target/debug/deps/liblibc-dadc43429530f2e4.rlib" 1663091921.000000000s
[2022-09-13T18:00:20Z DEBUG cargo::core::compiler::fingerprint] max dep mtime for "/usr/local/cargo/registry/src/github.com-1ecc6299db9ec823/libc-0.2.132" is "/root/project/target/debug/build/libc-06ac331ace17f261/output" 1663091920.000000000s
[2022-09-13T18:00:20Z DEBUG cargo::core::compiler::fingerprint] all paths up-to-date relative to "/root/project/target/debug/.fingerprint/libc-dadc43429530f2e4/dep-lib-libc" mtime=1663091920.000000000s
[2022-09-13T18:00:20Z DEBUG cargo::core::compiler::fingerprint] filesystem up-to-date "/usr/local/cargo/registry/src/github.com-1ecc6299db9ec823/libc-0.2.132"
[2022-09-13T18:00:20Z DEBUG cargo::core::compiler::fingerprint] new local fingerprints deps "/usr/local/cargo/registry/src/github.com-1ecc6299db9ec823/tikv-jemalloc-sys-0.5.1+5.3.0-patched"
[2022-09-13T18:00:20Z DEBUG cargo::core::compiler::fingerprint] max output mtime for "/usr/local/cargo/registry/src/github.com-1ecc6299db9ec823/cc-1.0.73" is "/root/project/target/debug/deps/libcc-a23a0e4ab5ac45ce.rlib" 1663091921.000000000s
[2022-09-13T18:00:20Z DEBUG cargo::core::compiler::fingerprint] all paths up-to-date relative to "/root/project/target/debug/.fingerprint/cc-a23a0e4ab5ac45ce/dep-lib-cc" mtime=1663091920.000000000s
[2022-09-13T18:00:20Z DEBUG cargo::core::compiler::fingerprint] filesystem up-to-date "/usr/local/cargo/registry/src/github.com-1ecc6299db9ec823/cc-1.0.73"
[2022-09-13T18:00:20Z DEBUG cargo::core::compiler::fingerprint] max output mtime for "/usr/local/cargo/registry/src/github.com-1ecc6299db9ec823/fs_extra-1.2.0" is "/root/project/target/debug/deps/libfs_extra-d1409e0b5297afde.rlib" 1663091920.000000000s
[2022-09-13T18:00:20Z DEBUG cargo::core::compiler::fingerprint] all paths up-to-date relative to "/root/project/target/debug/.fingerprint/fs_extra-d1409e0b5297afde/dep-lib-fs_extra" mtime=1663091920.000000000s
[2022-09-13T18:00:20Z DEBUG cargo::core::compiler::fingerprint] filesystem up-to-date "/usr/local/cargo/registry/src/github.com-1ecc6299db9ec823/fs_extra-1.2.0"
[2022-09-13T18:00:20Z DEBUG cargo::core::compiler::fingerprint] max output mtime for "/usr/local/cargo/registry/src/github.com-1ecc6299db9ec823/tikv-jemalloc-sys-0.5.1+5.3.0-patched" is "/root/project/target/debug/build/tikv-jemalloc-sys-2b39192ec04e05b2/build_script_build-2b39192ec04e05b2" 1663091921.000000000s
[2022-09-13T18:00:20Z DEBUG cargo::core::compiler::fingerprint] max dep mtime for "/usr/local/cargo/registry/src/github.com-1ecc6299db9ec823/tikv-jemalloc-sys-0.5.1+5.3.0-patched" is "/root/project/target/debug/deps/libcc-a23a0e4ab5ac45ce.rlib" 1663091921.000000000s
[2022-09-13T18:00:20Z DEBUG cargo::core::compiler::fingerprint] max dep mtime for "/usr/local/cargo/registry/src/github.com-1ecc6299db9ec823/tikv-jemalloc-sys-0.5.1+5.3.0-patched" is "/root/project/target/debug/deps/libfs_extra-d1409e0b5297afde.rlib" 1663091920.000000000s
[2022-09-13T18:00:20Z DEBUG cargo::core::compiler::fingerprint] all paths up-to-date relative to "/root/project/target/debug/.fingerprint/tikv-jemalloc-sys-2b39192ec04e05b2/dep-build-script-build-script-build" mtime=1663091921.000000000s
[2022-09-13T18:00:20Z DEBUG cargo::core::compiler::fingerprint] filesystem up-to-date "/usr/local/cargo/registry/src/github.com-1ecc6299db9ec823/tikv-jemalloc-sys-0.5.1+5.3.0-patched"
[2022-09-13T18:00:20Z DEBUG cargo::core::compiler::fingerprint] max output mtime for "/usr/local/cargo/registry/src/github.com-1ecc6299db9ec823/tikv-jemalloc-sys-0.5.1+5.3.0-patched" is "/root/project/target/debug/build/tikv-jemalloc-sys-8101985b937c9e9f/output" 1663091921.000000000s
[2022-09-13T18:00:20Z DEBUG cargo::core::compiler::fingerprint] max dep mtime for "/usr/local/cargo/registry/src/github.com-1ecc6299db9ec823/tikv-jemalloc-sys-0.5.1+5.3.0-patched" is "/root/project/target/debug/build/tikv-jemalloc-sys-2b39192ec04e05b2/build_script_build-2b39192ec04e05b2" 1663091921.000000000s
[2022-09-13T18:00:20Z INFO cargo::core::compiler::fingerprint] stale: changed "/usr/local/cargo/registry/src/github.com-1ecc6299db9ec823/tikv-jemalloc-sys-0.5.1+5.3.0-patched/jemalloc"
[2022-09-13T18:00:20Z INFO cargo::core::compiler::fingerprint] (vs) "/root/project/target/debug/build/tikv-jemalloc-sys-8101985b937c9e9f/output"
[2022-09-13T18:00:20Z INFO cargo::core::compiler::fingerprint] FileTime { seconds: 1663091921, nanos: 0 } != FileTime { seconds: 1663092020, nanos: 432004673 }
[2022-09-13T18:00:20Z DEBUG cargo::core::compiler::fingerprint] max output mtime for "/usr/local/cargo/registry/src/github.com-1ecc6299db9ec823/tikv-jemalloc-sys-0.5.1+5.3.0-patched" is "/root/project/target/debug/deps/libtikv_jemalloc_sys-812ba7dac85e5ef8.rmeta" 1663091951.000000000s
[2022-09-13T18:00:20Z DEBUG cargo::core::compiler::fingerprint] max dep mtime for "/usr/local/cargo/registry/src/github.com-1ecc6299db9ec823/tikv-jemalloc-sys-0.5.1+5.3.0-patched" is "/root/project/target/debug/deps/liblibc-dadc43429530f2e4.rmeta" 1663091921.000000000s
[2022-09-13T18:00:20Z DEBUG cargo::core::compiler::fingerprint] max output mtime for "/usr/local/cargo/registry/src/github.com-1ecc6299db9ec823/tikv-jemallocator-0.5.0" is "/root/project/target/debug/deps/libtikv_jemallocator-c2826f4f246f2c52.rmeta" 1663091951.000000000s
[2022-09-13T18:00:20Z DEBUG cargo::core::compiler::fingerprint] max dep mtime for "/usr/local/cargo/registry/src/github.com-1ecc6299db9ec823/tikv-jemallocator-0.5.0" is "/root/project/target/debug/deps/liblibc-dadc43429530f2e4.rmeta" 1663091921.000000000s
[2022-09-13T18:00:20Z DEBUG cargo::core::compiler::fingerprint] max output mtime for "/root/project" is "/root/project/target/debug/deps/target_cache_test-ad795130651e176c" 1663091951.000000000s
[2022-09-13T18:00:20Z INFO cargo::core::compiler::fingerprint] fingerprint error for target-cache-test v0.1.0 (/root/project)/Build/TargetInner { name: "target-cache-test", doc: true, ..: with_path("/root/project/src/main.rs", Edition2021) }
[2022-09-13T18:00:20Z INFO cargo::core::compiler::fingerprint] err: current filesystem status shows we're outdated
[2022-09-13T18:00:20Z DEBUG cargo::core::compiler::fingerprint] fingerprint at: /root/project/target/debug/.fingerprint/tikv-jemallocator-c2826f4f246f2c52/lib-tikv-jemallocator
[2022-09-13T18:00:20Z INFO cargo::core::compiler::fingerprint] fingerprint error for tikv-jemallocator v0.5.0/Build/TargetInner { tested: false, benched: false, ..: lib_target("tikv-jemallocator", ["lib"], "/usr/local/cargo/registry/src/github.com-1ecc6299db9ec823/tikv-jemallocator-0.5.0/src/lib.rs", Edition2018) }
[2022-09-13T18:00:20Z INFO cargo::core::compiler::fingerprint] err: current filesystem status shows we're outdated
[2022-09-13T18:00:20Z DEBUG cargo::core::compiler::fingerprint] fingerprint at: /root/project/target/debug/.fingerprint/libc-dadc43429530f2e4/lib-libc
[2022-09-13T18:00:20Z DEBUG cargo::core::compiler::fingerprint] fingerprint at: /root/project/target/debug/.fingerprint/libc-06ac331ace17f261/run-build-script-build-script-build
[2022-09-13T18:00:20Z DEBUG cargo::core::compiler::fingerprint] fingerprint at: /root/project/target/debug/.fingerprint/libc-875143ba2a651140/build-script-build-script-build
[2022-09-13T18:00:20Z DEBUG cargo::core::compiler::fingerprint] fingerprint at: /root/project/target/debug/.fingerprint/tikv-jemalloc-sys-812ba7dac85e5ef8/lib-tikv-jemalloc-sys
[2022-09-13T18:00:20Z INFO cargo::core::compiler::fingerprint] fingerprint error for tikv-jemalloc-sys v0.5.1+5.3.0-patched/Build/TargetInner { ..: lib_target("tikv-jemalloc-sys", ["lib"], "/usr/local/cargo/registry/src/github.com-1ecc6299db9ec823/tikv-jemalloc-sys-0.5.1+5.3.0-patched/src/lib.rs", Edition2018) }
[2022-09-13T18:00:20Z INFO cargo::core::compiler::fingerprint] err: current filesystem status shows we're outdated
[2022-09-13T18:00:20Z DEBUG cargo::core::compiler::fingerprint] fingerprint at: /root/project/target/debug/.fingerprint/tikv-jemalloc-sys-8101985b937c9e9f/run-build-script-build-script-build
[2022-09-13T18:00:20Z INFO cargo::core::compiler::fingerprint] fingerprint error for tikv-jemalloc-sys v0.5.1+5.3.0-patched/RunCustomBuild/TargetInner { ..: custom_build_target("build-script-build", "/usr/local/cargo/registry/src/github.com-1ecc6299db9ec823/tikv-jemalloc-sys-0.5.1+5.3.0-patched/build.rs", Edition2018) }
[2022-09-13T18:00:20Z INFO cargo::core::compiler::fingerprint] err: current filesystem status shows we're outdated
[2022-09-13T18:00:20Z DEBUG cargo::core::compiler::fingerprint] fingerprint at: /root/project/target/debug/.fingerprint/tikv-jemalloc-sys-2b39192ec04e05b2/build-script-build-script-build
[2022-09-13T18:00:20Z DEBUG cargo::core::compiler::fingerprint] fingerprint at: /root/project/target/debug/.fingerprint/cc-a23a0e4ab5ac45ce/lib-cc
[2022-09-13T18:00:20Z DEBUG cargo::core::compiler::fingerprint] fingerprint at: /root/project/target/debug/.fingerprint/fs_extra-d1409e0b5297afde/lib-fs_extra
Compiling tikv-jemalloc-sys v0.5.1+5.3.0-patched
[2022-09-13T18:00:55Z DEBUG cargo::core::compiler::fingerprint] new local fingerprints deps "/usr/local/cargo/registry/src/github.com-1ecc6299db9ec823/tikv-jemalloc-sys-0.5.1+5.3.0-patched"
[2022-09-13T18:00:55Z DEBUG cargo::core::compiler::fingerprint] write fingerprint (b16608c139b4fa80) : /root/project/target/debug/.fingerprint/tikv-jemalloc-sys-8101985b937c9e9f/run-build-script-build-script-build
Compiling tikv-jemallocator v0.5.0
[2022-09-13T18:00:55Z DEBUG cargo::core::compiler::fingerprint] write fingerprint (9dc3e3c9592e9add) : /root/project/target/debug/.fingerprint/tikv-jemalloc-sys-812ba7dac85e5ef8/lib-tikv-jemalloc-sys
[2022-09-13T18:00:55Z DEBUG cargo::core::compiler::fingerprint] write fingerprint (65cbcef45534a05) : /root/project/target/debug/.fingerprint/tikv-jemallocator-c2826f4f246f2c52/lib-tikv-jemallocator
Compiling target-cache-test v0.1.0 (/root/project)
[2022-09-13T18:00:56Z DEBUG cargo::core::compiler::fingerprint] write fingerprint (52394158d0809914) : /root/project/target/debug/.fingerprint/target-cache-test-ad795130651e176c/bin-target-cache-test
Finished dev [unoptimized + debuginfo] target(s) in 35.90s
Possible Solution(s)
It seems like Cargo already assumes that the source of published crates will never change given that we don't see the same rebuilding behavior for most crates. It could potentially extend that to ignoring rerun-if-changed
paths that point into the published crate source directory.
Notes
No response
Version
No response