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
{{ message }}
Repository navigation
SCCACHE_BASEDIRS support for Worktree workflow #2595
SCCACHE_BASEDIRS added in 7e02a2f is a great step to help enable cache hits across copies of repos, but doesn't work well for common git worktree workflows, since we need to statically set each base dir. This breaks a few workflows.
For example, consider a project at /home/projects/hello-world. Some common workflows I have seen are...
Worktrees in /home/projects/hello-world/.worktrees/<branchname>/...
It would be nice to be able to have these all use the shared cache. This is especially important with AI coding use cases (which is a common usage for worktrees), where all new work is done in a new branch. Usage of sccache (if this can be supported) would cut multiple minute build times at the start of each piece of work
Reacted by Nicolas Ettlin, Nick Mitchell, Brian, Günter Zöchbauer, Lee Butts, Marco Caccin, André Breda, Logan Rosen, rbingham, 1mamute and 1 more
I have tried SCCACHE_BASEDIRS and it seems to work. For examples, my project is at /foo and one of my worktree is at /foo/.worktree/bar. SCCACHE_BASEDIRS should be /foo:/foo/.worktree/bar.
Was able to get cross-worktree Rust dedup working in a fork and wanted to share what was needed to actually get it working end-to-end,. Fork is on top of the existing Vercel rust-basedirs work.
Glob patterns in SCCACHE_BASEDIRS (so $HOME/repos/*/worktrees/*/*/* works without enumerating random worktree names).
Per-token argv strip before concatenation — cargo emits --remap-path-prefix /abs=virtual as two tokens, and the post-concat blob scan can't see the / boundary. Stripping each token in isolation catches it.
Strip every CARGO_* env value, not a hand-coded allowlist. devenv injects CARGO_INSTALL_ROOT per-project; the existing allowlist missed it and that one var broke the hash key for every workspace crate.
Companion requirement: set RUSTFLAGS=--remap-path-prefix=$PROJECT_ROOT=/proj per project. sccache normalises what it hashes, but it also hashes extern .rmeta content, and rustc embeds absolute paths inside rmeta. Without the remap, workspace-internal dep rmetas differ between worktrees and the dedup chain breaks downstream.
Result on a real workspace (vault-server, 7 crates, ~300 rustc invocations): 0% → 98.6% cross-worktree Rust hit rate, ~2m → ~1m wall-clock. The 4 remaining misses are cargo build probes (path-sensitive fingerprint in OUT_DIR); not a sccache-side fix.
I’m working on this because I build the same Rust project from several worktrees at once. Those checkouts have different absolute paths, so they currently miss the cache even when the source is identical.
I split the work into two draft PRs so each behavior can be reviewed on its own:
PR #2813 makes Rust cache keys honor SCCACHE_BASEDIRS.
PR #2814 lets each compiler invocation tell one long-running sccache daemon which checkout root applies to that request. If SCCACHE_BASEDIRS is absent, sccache uses the config-file value. If it is present but empty, that request does not use a basedir.
The same rules apply in normal daemon mode and with SCCACHE_CLIENT_SIDE=1. The caller passes one exact checkout root; sccache does not scan Git worktrees, expand wildcards, or special-case the tools that create them. The follow-up uses environment data already in compile requests, so it does not change the wire protocol.
PR #2813 overlaps #2678 and #2794, so I opened it as a draft alternative.
I took a closer look at the earlier implementations before asking anyone to choose between them. #2678 established the Rust basedir work. #2794 builds on it and takes a stricter artifact-safety approach: it requires rustc path remapping and rebuilds cached dep-info. John Ferguson’s Vercel-based experiment adds glob roots and reports 287/291 hits on a real workspace. A configured glob can cover future worktrees when their paths follow a known pattern.
The separate piece in this stack is #2814. It lets each compiler invocation supply one exact checkout root to the same running daemon, regardless of where that worktree was created. This avoids requiring every checkout to match a daemon-wide wildcard and keeps concurrent requests isolated. #2813 is a smaller opt-in alternative for the Rust-key portion, but it has a documented tradeoff: a cache hit can retain the producer checkout’s embedded path, while #2794 is more conservative. If maintainers prefer #2794’s Rust-key model, I’m happy to adapt the request-scoped work from #2814 to it.
Activity
howardjohn commentedon Feb 13, 2026
Actually looking a bit more closely it seems like this only works for C anyways not rust so it wouldn't be relevant for my use
HuaHuaY commentedon May 11, 2026
I have tried
SCCACHE_BASEDIRSand it seems to work. For examples, my project is at/fooand one of my worktree is at/foo/.worktree/bar.SCCACHE_BASEDIRSshould be/foo:/foo/.worktree/bar.johnkferguson commentedon May 26, 2026
Was able to get cross-worktree Rust dedup working in a fork and wanted to share what was needed to actually get it working end-to-end,. Fork is on top of the existing Vercel
rust-basedirswork.SCCACHE_BASEDIRS(so$HOME/repos/*/worktrees/*/*/*works without enumerating random worktree names).--remap-path-prefix /abs=virtualas two tokens, and the post-concat blob scan can't see the/boundary. Stripping each token in isolation catches it.CARGO_*env value, not a hand-coded allowlist.devenvinjectsCARGO_INSTALL_ROOTper-project; the existing allowlist missed it and that one var broke the hash key for every workspace crate.Companion requirement: set
RUSTFLAGS=--remap-path-prefix=$PROJECT_ROOT=/projper project. sccache normalises what it hashes, but it also hashes extern.rmetacontent, and rustc embeds absolute paths inside rmeta. Without the remap, workspace-internal dep rmetas differ between worktrees and the dedup chain breaks downstream.Result on a real workspace (
vault-server, 7 crates, ~300 rustc invocations): 0% → 98.6% cross-worktree Rust hit rate, ~2m → ~1m wall-clock. The 4 remaining misses are cargo build probes (path-sensitive fingerprint inOUT_DIR); not a sccache-side fix.Full patches + writeup: johnkferguson#1
tcashel commentedon Aug 18, 2026
I’m working on this because I build the same Rust project from several worktrees at once. Those checkouts have different absolute paths, so they currently miss the cache even when the source is identical.
I split the work into two draft PRs so each behavior can be reviewed on its own:
SCCACHE_BASEDIRS.SCCACHE_BASEDIRSis absent, sccache uses the config-file value. If it is present but empty, that request does not use a basedir.The same rules apply in normal daemon mode and with
SCCACHE_CLIENT_SIDE=1. The caller passes one exact checkout root; sccache does not scan Git worktrees, expand wildcards, or special-case the tools that create them. The follow-up uses environment data already in compile requests, so it does not change the wire protocol.PR #2814 is one commit on top of #2813. Until #2813 merges, GitHub includes both commits in the second PR; view the follow-up-only diff. I’ll rebase #2814 onto
mainafter #2813 merges.PR #2813 overlaps #2678 and #2794, so I opened it as a draft alternative.
I took a closer look at the earlier implementations before asking anyone to choose between them. #2678 established the Rust basedir work. #2794 builds on it and takes a stricter artifact-safety approach: it requires rustc path remapping and rebuilds cached dep-info. John Ferguson’s Vercel-based experiment adds glob roots and reports 287/291 hits on a real workspace. A configured glob can cover future worktrees when their paths follow a known pattern.
The separate piece in this stack is #2814. It lets each compiler invocation supply one exact checkout root to the same running daemon, regardless of where that worktree was created. This avoids requiring every checkout to match a daemon-wide wildcard and keeps concurrent requests isolated. #2813 is a smaller opt-in alternative for the Rust-key portion, but it has a documented tradeoff: a cache hit can retain the producer checkout’s embedded path, while #2794 is more conservative. If maintainers prefer #2794’s Rust-key model, I’m happy to adapt the request-scoped work from #2814 to it.