Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
3f1b1f9
Add SCCACHE_BASEDIR support
Felixoid Dec 18, 2025
5d5d735
Fix clippy, introduce multiple basedirs logic
Felixoid Dec 18, 2025
20c20d8
Make codecov happy
Felixoid Dec 18, 2025
42a4e63
Apply fmt to all files
Felixoid Dec 18, 2025
ba4d37d
Clean out `basedir` intermediate step, use `basedirs`
Felixoid Dec 22, 2025
da5d931
Cover Windows case for mixed slashes in paths
Felixoid Dec 23, 2025
fdf0795
Add `Base directories` to `--show-stats` output
Felixoid Dec 23, 2025
2e11934
Make `basedirs` match case insensitive on Windows
Felixoid Dec 23, 2025
03b869f
Add trace logs to strip_basedirs, fix remainings
Felixoid Dec 23, 2025
ec45156
Remove outdated test
Felixoid Dec 24, 2025
91ef467
Optimize strip_basedirs for big input
Felixoid Dec 28, 2025
513a291
Apply suggestions from code review
Felixoid Dec 29, 2025
b6b74ff
Move basedir validation to config building
Felixoid Dec 29, 2025
9f341d3
Add basedirs for remote cache implementations
Felixoid Dec 29, 2025
1458e71
Address review point for directories separator
Felixoid Dec 29, 2025
e687bd4
Simplify strip_basedirs a bit more
Felixoid Dec 29, 2025
29ddde0
Final cleanup of the code for leftovers
Felixoid Dec 30, 2025
316eb66
Review: less reallocations
Felixoid Dec 30, 2025
2f118f2
Apply suggestions from code review
Felixoid Dec 30, 2025
d8f6396
Move normalization to the config building, use bytes for basedirs
Felixoid Dec 30, 2025
477fccd
Return unnormalized output, fix tests
Felixoid Dec 30, 2025
9de64f5
Empty SCCACHE_BASEDIRS overrides, but unset does not
Felixoid Jan 9, 2026
6f011d4
Apply suggestions from code review
Felixoid Jan 9, 2026
880a007
Do not trim spaces from paths, safer env overwrite in tests
Felixoid Jan 9, 2026
15575d4
Add tests that check uniq basedir per case
Felixoid Jan 9, 2026
5346fe1
Return `Cow` from strip_basedirs
Felixoid Jan 9, 2026
d1720fc
Use typed_path::Utf8TypedPathBuf to normalize directories
Felixoid Jan 9, 2026
1d16ad8
Strip basedir completely, normalize once, add integration tests
Felixoid Jan 9, 2026
e14350c
Use ascii + utf in normalize_win_path
Felixoid Jan 9, 2026
b6e9c95
Another review round
Felixoid Jan 10, 2026
31f9f6b
Avoid config conflicts while set_env manipulations
Felixoid Jan 10, 2026
bd71f11
Update README.md
Felixoid Jan 13, 2026
aab37d0
Deduplicate basedirs in Config
Felixoid Jan 13, 2026
61c6747
Refactor hash_key to HashKeyParams::compute
Felixoid Jan 13, 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 @@ -103,6 +103,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 @@ -320,12 +320,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 @@ -134,6 +154,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
Loading