Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
ced74fe
Add SCCACHE_BASEDIR support
Felixoid Dec 18, 2025
62812bf
Fix clippy, introduce multiple basedirs logic
Felixoid Dec 18, 2025
da031db
Make codecov happy
Felixoid Dec 18, 2025
ec44d37
Apply fmt to all files
Felixoid Dec 18, 2025
d494e0e
Clean out `basedir` intermediate step, use `basedirs`
Felixoid Dec 22, 2025
2f87d8c
Cover Windows case for mixed slashes in paths
Felixoid Dec 23, 2025
af542be
Add `Base directories` to `--show-stats` output
Felixoid Dec 23, 2025
066b85f
Make `basedirs` match case insensitive on Windows
Felixoid Dec 23, 2025
a1781f0
Add trace logs to strip_basedirs, fix remainings
Felixoid Dec 23, 2025
0d78f76
Remove outdated test
Felixoid Dec 24, 2025
7af43ea
Optimize strip_basedirs for big input
Felixoid Dec 28, 2025
23688fc
Apply suggestions from code review
Felixoid Dec 29, 2025
52f77d1
Move basedir validation to config building
Felixoid Dec 29, 2025
27a617f
Add basedirs for remote cache implementations
Felixoid Dec 29, 2025
5be4d03
Address review point for directories separator
Felixoid Dec 29, 2025
9034c80
Simplify strip_basedirs a bit more
Felixoid Dec 29, 2025
9ff31bf
Final cleanup of the code for leftovers
Felixoid Dec 30, 2025
aa4d6f1
Review: less reallocations
Felixoid Dec 30, 2025
f078a57
Apply suggestions from code review
Felixoid Dec 30, 2025
91bbce7
Move normalization to the config building, use bytes for basedirs
Felixoid Dec 30, 2025
f94565a
Return unnormalized output, fix tests
Felixoid Dec 30, 2025
c76e858
Empty SCCACHE_BASEDIRS overrides, but unset does not
Felixoid Jan 9, 2026
65703c5
Apply suggestions from code review
Felixoid Jan 9, 2026
dd3b7d8
Do not trim spaces from paths, safer env overwrite in tests
Felixoid Jan 9, 2026
428c961
Add tests that check uniq basedir per case
Felixoid Jan 9, 2026
777b3ef
Return `Cow` from strip_basedirs
Felixoid Jan 9, 2026
a9e59c7
Use typed_path::Utf8TypedPathBuf to normalize directories
Felixoid Jan 9, 2026
a0f0740
Strip basedir completely, normalize once, add integration tests
Felixoid Jan 9, 2026
c6c2e1c
Use ascii + utf in normalize_win_path
Felixoid Jan 9, 2026
81d6535
Another review round
Felixoid Jan 10, 2026
f3d4576
Avoid config conflicts while set_env manipulations
Felixoid Jan 10, 2026
11ccdb6
Update README.md
Felixoid Jan 13, 2026
fa346df
Deduplicate basedirs in Config
Felixoid Jan 13, 2026
b32d59c
Refactor hash_key to HashKeyParams::compute
Felixoid Jan 13, 2026
ebbd0fb
Add integration tests for basdirs
Felixoid Jan 21, 2026
a383d35
Improve basedirs integration tests
Felixoid Jan 22, 2026
f8e0ecb
Sort profiles and services in Makefile
Felixoid Jan 22, 2026
8bc4ca5
Check CACHE_MISSES did not change between runs for autotools
Felixoid Jan 22, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ tokio-serde = "0.8"
tokio-util = { version = "0.7", features = ["codec", "io"] }
toml = "0.8"
tower-service = "0.3"
typed-path = "0.12.0"
url = { version = "2", optional = true }
uuid = { version = "1.9", features = ["v4"] }
walkdir = "2"
Expand Down
39 changes: 38 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -321,12 +321,49 @@ This is most useful when using sccache for Rust compilation, as rustc supports u

---

Normalizing Paths with `SCCACHE_BASEDIRS`
-----------------------------------------

By default, sccache requires absolute paths to match for cache hits. To enable cache sharing across different build directories, you can set `SCCACHE_BASEDIRS` to strip a base directory from paths before hashing:

```bash
export SCCACHE_BASEDIRS=/home/user/project
```

You can also specify multiple base directories by separating them by `;` on Windows hosts and by `:` on any other operating system. When multiple directories are provided, the longest matching prefix is used:

```bash
export SCCACHE_BASEDIRS="/home/user/project:/home/user/workspace"
```

Path matching is **case-insensitive** on Windows and **case-sensitive** on other operating systems.

This is similar to ccache's `CCACHE_BASEDIR` and helps when:
* Building the same project from different directories
* Sharing cache between CI jobs with different checkout paths
* Multiple developers working with different username paths
* Working with multiple project checkouts simultaneously

**Note:** Only absolute paths are supported. Relative paths will prevent server from starting.

You can also configure this in the sccache config file:

```toml
# Single directory
basedirs = ["/home/user/project"]

# Or multiple directories
basedirs = ["/home/user/project", "/home/user/workspace"]
```

---

Known Caveats
-------------

### General

* Absolute paths to files must match to get a cache hit. This means that even if you are using a shared cache, everyone will have to build at the same absolute path (i.e. not in `$HOME`) in order to benefit each other. In Rust this includes the source for third party crates which are stored in `$HOME/.cargo/registry/cache` by default.
* By default, absolute paths to files must match to get a cache hit. To work around this, use `SCCACHE_BASEDIRS` (see above) to normalize paths before hashing.

### Rust

Expand Down
21 changes: 21 additions & 0 deletions docs/Configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,26 @@
# If specified, wait this long for the server to start up.
server_startup_timeout_ms = 10000

# Base directories to strip from source paths during cache key
# computation.
#
# Similar to ccache's CCACHE_BASEDIR, but supports multiple paths.
#
# 'basedirs' enables cache hits across different absolute root
# paths when compiling the same source code, such as between
# parallel checkouts of the same project, Git worktrees, or different
# users in a shared environment.
# When multiple matching paths are provided, the longest prefix
# is used.
#
# Path matching is case-insensitive on Windows and case-sensitive on other OSes.
#
# Example:
# basedir = ["/home/user/project"] results in the path prefix rewrite:
# "/home/user/project/src/main.c" -> "src/main.c"
basedirs = ["/home/user/project"]
# basedirs = ["/home/user/project", "/home/user/workspace"]

[dist]
# where to find the scheduler
scheduler_url = "http://1.2.3.4:10600"
Expand Down Expand Up @@ -139,6 +159,7 @@ Note that some env variables may need sccache server restart to take effect.

* `SCCACHE_ALLOW_CORE_DUMPS` to enable core dumps by the server
* `SCCACHE_CONF` configuration file path
* `SCCACHE_BASEDIRS` base directory (or directories) to strip from paths for cache key computation. This is similar to ccache's `CCACHE_BASEDIR` and enables cache hits across different absolute paths when compiling the same source code. Multiple directories can be separated by `;` on Windows hosts and by `:` on any other operating system. When multiple directories are specified, the longest matching prefix is used. Path matching is **case-insensitive** on Windows and **case-sensitive** on other operating systems. Environment variable takes precedence over file configuration. Only absolute paths are supported; relative paths will cause an error and prevent the server from start.
* `SCCACHE_CACHED_CONF`
* `SCCACHE_IDLE_TIMEOUT` how long the local daemon process waits for more client requests before exiting, in seconds. Set to `0` to run sccache permanently
* `SCCACHE_STARTUP_NOTIFY` specify a path to a socket which will be used for server completion notification
Expand Down
Loading