You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
-Ztrim-paths might be a way to partially fix this (as part of fixing the artifaict content hash), but that would also introduce more --remap-path-prefix=…, which will contain more aboslute paths. (See Tracking Issue for trim-paths RFC 3127 rust-lang/cargo#12137)
I think at least we need to implement a basic support to eliminate some of the most common absolute paths from the cache key, like --remap-path-prefix=/abs/path, -Clinker=/abs/path, -Clin-arge=something,/abs/path, and others.
Drawback
SCCACHE_BASEDIRS only normalize paths for cache keys not the real compiler invocations. That means embedded path in binaries are shared across different build root.
This might be a user problem, as they can fix it via prefix-map flag, like -fdebug-prefix-map, -ffile-prefix-map, -fmacro-prefix-map in C compiler and --remap-path-prefix in rustc.
Reacted by Adam Gutglick, Amit Kotlovski and Daniel
I have some work that at least passes artificial tests, are there any integration tests or other things you think might be useful to run before I put up a PR?
I have some work that at least passes artificial tests, are there any integration tests or other things you think might be useful to run before I put up a PR?
Confirmed on sccache 0.17.0, including client-side mode. Two byte-identical Rust rlib compilations from sibling checkout roots produced two misses even when SCCACHE_BASEDIRS contained both source and target roots. The daemon reported the bases correctly.
There is an additional Rust-specific key input beyond path-bearing arguments: RustHasher::generate_hash_key hashes cwd directly as input 9 because the directory can appear in the rlib. Base-directory normalization therefore cannot become sound by changing only the key. The compile must also use an equivalent --remap-path-prefix, and the differing source half of that flag must itself be normalized before hashing.
A useful regression should compile the same rlib from two sibling roots, not only compare constructed argument hashes. Expected: first miss, second Rust hit, and neither artifact contains the physical checkout root.
We are mitigating this downstream with an immutable, toolchain-keyed Cargo target snapshot restored by filesystem copy-on-write. It preserves lane isolation and lets Cargo validate its own fingerprints, but fixing this issue would recover the compiler-object layer too.
Some numbers on what this is worth, from a project that builds in many git worktrees. These are on macOS: a full cargo build of a crate with about 220 dependency compiles, with a second worktree building the same commit after the first through one sccache server.
Most of the misses #2882 leaves trace back to serde_core. Its key includes its OUT_DIR env-dep, which sits under each checkout's target directory. So it misses and is rebuilt, and the new rlib then changes the key of everything that depends on it. Normalising OUT_DIR is what takes it from 182 to 221.
Two things we needed beyond what #2813 does, in case they help:
Among env-deps we only normalised OUT_DIR. Another env-dep holding the base dir, like env!("CARGO_MANIFEST_DIR"), can end up in running code, so for those crates we kept the unnormalised key rather than share an artifact carrying another checkout's path.
After a hit from another checkout, the replayed dep-info file still names that checkout's paths, including OUT_DIR, and cargo reads them back. We rewrite the stored base dir to the current one on a hit.
Happy to test #2813 against the same setup, or turn either of these into a follow-up on top of it.
Some data from trying #2813 + #2814 on Firefox (macOS arm64). Firefox gets built in lots of git worktrees and vendors all its crates in-tree under third_party/rust, so it hits a few things beyond the registry-deps case.
Linker paths. Even with both PRs applied, a leaf crate still got different keys across worktrees. Firefox sets CARGO_TARGET_AARCH64_APPLE_DARWIN_LINKER=<srcdir>/build/cargo-linker, which gets hashed verbatim as a CARGO_ env var, and cargo turns it into -C linker=<srcdir>/build/cargo-linker, whose value isn't normalized either. Normalizing both (the linker doesn't affect rlib output) gave identical keys for that crate. I have this as a small patch on top of #2813 if it's useful.
Proc-macros. After that, everything downstream of a proc-macro misses. Proc-macros aren't cacheable, so each worktree builds its own, and their dylib contents go into dependents' keys. #2882 handles the macOS output-path part, but it isn't enough here: because the crates are vendored inside each checkout, the .rustc metadata section itself contains the checkout path. All 59 of our proc-macros differed in that section between two worktrees. Firefox only adds --remap-path-prefix to target RUSTFLAGS, and since cargo is invoked with --target, host/proc-macro builds don't get it.
I checked that remapping fixes this. Building serde_derive 1.0.228 with syn/quote/proc-macro2 from two checkouts' vendored dirs:
without remap: all rlibs and serde_derive's .rustc section differ
with --remap-path-prefix=<checkout>=/topsrcdir: the syn/quote/proc-macro2 rlibs are byte-identical and serde_derive's .rustc section is identical. The dylib as a whole still differs because of the output path, which is what rust: hash proc-macro externs by their crate metadata #2882 covers.
So for projects that vendor crates (or use path deps, see #2870), getting cross-checkout Rust hits seems to need all of: #2813/#2814, normalizing -C linker/CARGO_TARGET_*_LINKER, #2882, and remapping paths for host builds too. That last part is either up to the project (which needs -Zhost-config/target-applies-to-host today) or sccache adding a remap for basedirs itself, like #2765 suggests.
Also for anyone testing this locally: #2863 reproduces in client-side mode, which is Firefox's default, so I backed out my patched build until #2868 lands.
From my experiment, to get full cross-workspace cache reuse, you probably need trim-paths support (cargo native --remap-path-prefix support). It will be stabilized at 1.101.
Thanks, that was it. With nightly 1.101 and trim-paths = "all", plus #2813, #2814, #2882 and a local patch normalizing the linker path, a second Firefox worktree got 705/712 Rust hits (details in #2813 (comment)).
It's also enough to set it only for host builds (CARGO_PROFILE_RELEASE_BUILD_OVERRIDE_TRIM_PATHS=all). Proc-macro metadata then no longer embeds the checkout path, and every target crate hit without remapping target builds at all. That's useful for projects like Firefox that don't want to change paths in shipped debug info.
Activity
weihanglo commentedon Mar 24, 2026
This may need #2651 when taking
--remap-path-prefixusage into account.AdamGS commentedon Apr 14, 2026
I have some work that at least passes artificial tests, are there any integration tests or other things you think might be useful to run before I put up a PR?
mmastrac commentedon Apr 14, 2026
@AdamGS, we've got a somewhat-tested-but-sloppy patch that isn't ready to upstream available at https://github.com/vercel/sccache/pull/10/changes if you'd like to steal any of the tests and/or functionality from it.
weihanglo commentedon Apr 14, 2026
-Clin-arge=something,/abs/pathis one kind of patterns that easily forget to handle.kennethsinder commentedon Aug 10, 2026
Confirmed on sccache 0.17.0, including client-side mode. Two byte-identical Rust
rlibcompilations from sibling checkout roots produced two misses even whenSCCACHE_BASEDIRScontained both source and target roots. The daemon reported the bases correctly.There is an additional Rust-specific key input beyond path-bearing arguments:
RustHasher::generate_hash_keyhashescwddirectly as input 9 because the directory can appear in the rlib. Base-directory normalization therefore cannot become sound by changing only the key. The compile must also use an equivalent--remap-path-prefix, and the differing source half of that flag must itself be normalized before hashing.A useful regression should compile the same
rlibfrom two sibling roots, not only compare constructed argument hashes. Expected: first miss, second Rust hit, and neither artifact contains the physical checkout root.We are mitigating this downstream with an immutable, toolchain-keyed Cargo target snapshot restored by filesystem copy-on-write. It preserves lane isolation and lets Cargo validate its own fingerprints, but fixing this issue would recover the compiler-object layer too.
feat(cache): normalize CARGO_TARGET_DIR for sccache via a RUSTC_WRAPP…
build(cache): make sccache cache keys portable across worktrees (SCCA…
xdustinface commentedon Oct 7, 2026
Some numbers on what this is worth, from a project that builds in many git worktrees. These are on macOS: a full
cargo buildof a crate with about 220 dependency compiles, with a second worktree building the same commit after the first through one sccache server.Most of the misses #2882 leaves trace back to
serde_core. Its key includes itsOUT_DIRenv-dep, which sits under each checkout's target directory. So it misses and is rebuilt, and the new rlib then changes the key of everything that depends on it. NormalisingOUT_DIRis what takes it from 182 to 221.Two things we needed beyond what #2813 does, in case they help:
OUT_DIR. Another env-dep holding the base dir, likeenv!("CARGO_MANIFEST_DIR"), can end up in running code, so for those crates we kept the unnormalised key rather than share an artifact carrying another checkout's path.OUT_DIR, and cargo reads them back. We rewrite the stored base dir to the current one on a hit.Happy to test #2813 against the same setup, or turn either of these into a follow-up on top of it.
fix(rust): write dep-info locally not restoring from cache
fix(rust): write dep-info locally not restoring from cache
fix(rust): write dep-info locally not restoring from cache
loganrosen commentedon Oct 11, 2026
Some data from trying #2813 + #2814 on Firefox (macOS arm64). Firefox gets built in lots of git worktrees and vendors all its crates in-tree under
third_party/rust, so it hits a few things beyond the registry-deps case.Linker paths. Even with both PRs applied, a leaf crate still got different keys across worktrees. Firefox sets
CARGO_TARGET_AARCH64_APPLE_DARWIN_LINKER=<srcdir>/build/cargo-linker, which gets hashed verbatim as aCARGO_env var, and cargo turns it into-C linker=<srcdir>/build/cargo-linker, whose value isn't normalized either. Normalizing both (the linker doesn't affect rlib output) gave identical keys for that crate. I have this as a small patch on top of #2813 if it's useful.Proc-macros. After that, everything downstream of a proc-macro misses. Proc-macros aren't cacheable, so each worktree builds its own, and their dylib contents go into dependents' keys. #2882 handles the macOS output-path part, but it isn't enough here: because the crates are vendored inside each checkout, the
.rustcmetadata section itself contains the checkout path. All 59 of our proc-macros differed in that section between two worktrees. Firefox only adds--remap-path-prefixto target RUSTFLAGS, and since cargo is invoked with--target, host/proc-macro builds don't get it.I checked that remapping fixes this. Building serde_derive 1.0.228 with syn/quote/proc-macro2 from two checkouts' vendored dirs:
.rustcsection differ--remap-path-prefix=<checkout>=/topsrcdir: the syn/quote/proc-macro2 rlibs are byte-identical and serde_derive's.rustcsection is identical. The dylib as a whole still differs because of the output path, which is what rust: hash proc-macro externs by their crate metadata #2882 covers.So for projects that vendor crates (or use path deps, see #2870), getting cross-checkout Rust hits seems to need all of: #2813/#2814, normalizing
-C linker/CARGO_TARGET_*_LINKER, #2882, and remapping paths for host builds too. That last part is either up to the project (which needs-Zhost-config/target-applies-to-hosttoday) or sccache adding a remap for basedirs itself, like #2765 suggests.Also for anyone testing this locally: #2863 reproduces in client-side mode, which is Firefox's default, so I backed out my patched build until #2868 lands.
weihanglo commentedon Oct 11, 2026
From my experiment, to get full cross-workspace cache reuse, you probably need trim-paths support (cargo native
--remap-path-prefixsupport). It will be stabilized at 1.101.loganrosen commentedon Oct 19, 2026
Thanks, that was it. With nightly 1.101 and
trim-paths = "all", plus #2813, #2814, #2882 and a local patch normalizing the linker path, a second Firefox worktree got 705/712 Rust hits (details in #2813 (comment)).It's also enough to set it only for host builds (
CARGO_PROFILE_RELEASE_BUILD_OVERRIDE_TRIM_PATHS=all). Proc-macro metadata then no longer embeds the checkout path, and every target crate hit without remapping target builds at all. That's useful for projects like Firefox that don't want to change paths in shipped debug info.Kostoprav19 commentedon Oct 26, 2026
Hello! Thanks everyone pushing this change - when we can expect it to be shipped?