Skip to content

server: scope SCCACHE_BASEDIRS to compile requests - #2981

Closed
fbartho wants to merge 8 commits into
mozilla:mainfrom
fbartho:fb/request-scoped-basedirs
Closed

fbartho wants to merge 8 commits into
mozilla:mainfrom
fbartho:fb/request-scoped-basedirs

Conversation

@fbartho

@fbartho fbartho commented Nov 4, 2026 •

Copy link
Copy Markdown

Why

Working with git-worktrees (as I've heavily leaned into this year), I realized that my configuration of sccache wasn't giving me the wall-clock speed savings I expected. Tracing the setup, I realized that I needed basedirs to be updated every time I created a new worktree (if I wanted the worktrees to share a cache for shared dependencies & unchanged crates) and I couldn't use globs or some other patterns.

I found #2814 by @tcashel, and didn't want it to be closed due to inactivity. (If that PR gets merged first, then I imagine this one can be closed)

What changes

  • Before: the server reads SCCACHE_BASEDIRS once, at startup, so each new worktree needs a server restart.
  • After: each build sends its own SCCACHE_BASEDIRS. The config file's basedirs is the default, and SCCACHE_BASEDIRS="" turns it off.
  • Behavior change: SCCACHE_BASEDIRS set when starting the server is ignored; use the config file.

Related PRs

Review feedback from #2814

  • No Storage wrapper; basedirs goes straight to hashing.
  • A relative path skips the cache instead of failing the compile.
  • One parser for SCCACHE_BASEDIRS, working on bytes.

Testing

  • New unit and tests/sccache_cargo.rs tests, including concurrent builds with different roots.
  • fmt, clippy (1.91.0), and tests pass on Apple silicon, except test_hash_env_dep_equal_to_basedir_is_not_unset, which also fails on main.

Fixes #2595.

@fbartho

fbartho commented Nov 4, 2026

Copy link
Copy Markdown
Author

@sylvestre please let me know if you need me to do anything to improve this, thanks!

@fbartho fbartho closed this Nov 4, 2026
@fbartho fbartho reopened this Nov 4, 2026
@fbartho
fbartho force-pushed the fb/request-scoped-basedirs branch from f3ef77c to ed338fc Compare November 4, 2026 11:19
@ahartmetz

Copy link
Copy Markdown
Collaborator

I didn't spot any human-written text in this PR including for documentation changes(!)
That stuff is near unreadable. Write it yourself instead.

@codecov-commenter

codecov-commenter commented Nov 4, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 96.48760% with 17 lines in your changes missing coverage. Please review.
✅ Project coverage is 75.57%. Comparing base (e770454) to head (e21d2b3).

Files with missing lines Patch % Lines
src/server.rs 90.16% 12 Missing ⚠️
tests/sccache_cargo.rs 98.46% 3 Missing ⚠️
src/compiler/compiler.rs 97.43% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2981      +/-   ##
==========================================
- Coverage   76.27%   75.57%   -0.70%     
==========================================
  Files          74       74              
  Lines       45805    45029     -776     
==========================================
- Hits        34937    34032     -905     
- Misses      10868    10997     +129     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@fbartho
fbartho force-pushed the fb/request-scoped-basedirs branch from 82c5276 to b2c81a4 Compare November 4, 2026 21:13
@fbartho

fbartho commented Nov 4, 2026

Copy link
Copy Markdown
Author

Sorry about the lack of clarity there @ahartmetz. I was a bit too in the weeds focused on updating a PR that I was worried was going to be closed, and I focused too much on the code and not enough on the documentation, that won't happen again from me.

I've taken a manual pass at authoring the documentation changes in more plain and understandable language. This is my first time contributing here, so I appreciate your feedback.

@fbartho fbartho closed this Nov 4, 2026
@fbartho fbartho reopened this Nov 4, 2026
@fbartho

fbartho commented Nov 4, 2026

Copy link
Copy Markdown
Author

(I'm working on the codecov report now)

@fbartho

fbartho commented Nov 5, 2026

Copy link
Copy Markdown
Author

I believe I improved the code-coverage, but main is red, and #2982 has a fix, so I'll rebase after that lands.

@sylvestre
sylvestre force-pushed the fb/request-scoped-basedirs branch from b7632c8 to 407b17e Compare November 5, 2026 07:43
tcashel and others added 8 commits November 5, 2026 09:34
`generate_hash_key` and `get_cached_or_compile` take the basedirs next to the storage, so a request's `SCCACHE_BASEDIRS` reaches the C and Rust hashers without a `Storage` wrapper that forwards every method.
A relative path in a compile's `SCCACHE_BASEDIRS` failed the whole request, so the build saw an error rather than a compile. The server now answers `UnhandledCompile`, the client runs the real compiler, and the stats count the compile as not cacheable under `SCCACHE_BASEDIRS`.
The server and `--show-stats` take their basedirs from the config file and each compile request carries its own, so `config_from_env` has no reader for `SCCACHE_BASEDIRS`. Dropping it removes the hardcoded command list in `run_command` and the second, `to_string_lossy` parse that mangled non-UTF-8 paths; `parse_basedirs_env` is the one parser.
`config_from_env` no longer reads `SCCACHE_BASEDIRS`, so the test feeds the value through `parse_basedirs_env`.
Check that the request's SCCACHE_BASEDIRS and the config file fallback reach the hasher through the server, that the last request value wins, and that equal basedirs collapse to one.
@sylvestre
sylvestre force-pushed the fb/request-scoped-basedirs branch from 407b17e to e21d2b3 Compare November 5, 2026 08:34
@ahartmetz

Copy link
Copy Markdown
Collaborator

#2984 does (almost) the same thing but it's a cleaner PR

@fbartho

fbartho commented Nov 15, 2026

Copy link
Copy Markdown
Author

I'm still interested in this feature, but I'm comfortable if #2984 successfully merges.

Let me know what I can do to help. Happy to keep rebasing this PR if a maintainer is interested in this solution.

@sylvestre

Copy link
Copy Markdown
Collaborator

it has been conflicting for more than 7 days, sorry! please rebase it

@sylvestre

Copy link
Copy Markdown
Collaborator

thanks for tackling this!
This can't land until #2868 is merged. Per-request basedirs make #2863 (wrong object handed out with the preprocessor cache) much easier to hit.
Please rebase once #2868 and #2982 are in.

@fbartho

fbartho commented Nov 30, 2026 •

Copy link
Copy Markdown
Author

Actually, my PR is superseded by #3065, which merged earlier, so I think I'm all set here, Thanks @sylvestre!

@fbartho fbartho closed this Nov 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SCCACHE_BASEDIRS support for Worktree workflow

5 participants