Repository navigation
rust: key crates alike in every cargo target directory - #3071
Open
yusukeshib wants to merge 1 commit into
Open
yusukeshib wants to merge 1 commit into
yusukeshib wants to merge 1 commit into
Conversation
Cargo writes a build script's OUT_DIR under the target directory, so a crate that include!s generated code, such as serde_core, got a different key in every target directory, and so did every crate depending on it. Strip the profile's build directory, found from the deps directories of --out-dir and -L dependency=, like a basedir. The generated files are still hashed by content, now in the order of their stripped paths so where the target directory lives doesn't change it.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #3071 +/- ##
==========================================
- Coverage 79.99% 76.72% -3.28%
==========================================
Files 76 76
Lines 47374 45979 -1395
==========================================
- Hits 37898 35276 -2622
- Misses 9476 10703 +1227 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
3 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Cargo puts a build script's
OUT_DIRunder the target directory, and rustc lists it as an env-dep of every crate that doesinclude!(concat!(env!("OUT_DIR"), ...))(serde, serde_core, thiserror, pulp, nano-gemm, ...). So each target directory gives these crates their own key, and their rlibs record the included file's path, so every crate depending on them misses too. With one target directory per git worktree, a new worktree rebuilds a large part of the dependency graph even though the sources are identical.#2918 fixed this when the target directories are listed in
SCCACHE_BASEDIRS, but that list is fixed when the server starts, and worktrees come and go. This PR strips the compile's own profile build directory (<target-dir>[/<triple>]/<profile>, the parent of thedepsdirectory given with--out-diror-L dependency=) the same way as a basedir, without any configuration. The generated files are still hashed by content. They are now hashed in the order of their stripped paths, because otherwise where the target directory sits relative to the other sources changes the order and the key.SCCACHE_BASEDIRS_VERBATIM_ENV_DEPS=OUT_DIRopts out, for crates that bakeenv!("OUT_DIR")into their outputs.Measured on Linux with a private server and cache, building the same commit of a ~300-crate workspace into a second target directory:
cargo build -p <crate>, Rust hits / missescargo test -p <crate> --lib --no-run, Rust hits / missesThe two remaining misses are a crate depending on a path dependency and one depending on the
rustversionproc-macro, whose dylib metadata records itsOUT_DIRpath.Related: #2870, #2652, #2595.