Skip to content

feat: add sccache support to CMake build backend - #5590

Open
wolfv wants to merge 3 commits into
mainfrom
claude/add-sccache-cmake-emFYd
Open

feat: add sccache support to CMake build backend#5590
wolfv wants to merge 3 commits into
mainfrom
claude/add-sccache-cmake-emFYd

Conversation

@wolfv

@wolfv wolfv commented Mar 3, 2026

Copy link
Copy Markdown
Member

I believe we had this in a PR for the (old) buidl backends repository. Apparently we only merged sccache for Rust. This is the same for CMake.

Description

This PR adds support for sccache (a distributed compiler cache) to the CMake build backend. When sccache environment variables are detected, the build system automatically:

  1. Adds sccache as a build requirement
  2. Configures CMake to use sccache as a compiler launcher for C and C++
  3. Marks sccache-related environment variables from the system environment as secrets (so they don't leak in logs)
  4. Sets SCCACHE_BASEDIRS to the source directory for proper cache invalidation

https://claude.ai/code/session_01H5aie9HxzQqm5DHaHKUPGB

@wolfv wolfv changed the title Add sccache support to CMake build backend feat: add sccache support to CMake build backend Mar 3, 2026
@wolfv
wolfv requested a review from nichmor March 3, 2026 09:37
Comment thread crates/pixi_build_cmake/src/config.rs Outdated
Comment thread crates/pixi_build_cmake/src/config.rs Outdated
Comment thread crates/pixi_build_cmake/src/config.rs Outdated
@baszalmstra

Copy link
Copy Markdown
Contributor

Please resolve conflicts.

@traversaro

traversaro commented Mar 24, 2026

Copy link
Copy Markdown
Contributor

Sets SCCACHE_BASEDIRS to the source directory for proper cache invalidation

FYI, I did some experiments on using sccache and SCCACHE_BASEDIRS, and the outcome was not great. Let me stress that this was done outside of the pixi-build context, just pixi workspace and tasks that "happen" to build a CMake project (something like https://github.com/gbionics/bipedal-locomotion-framework/blob/51e0fda9cea3288cb9ca43be29b684262f4e8b43/pixi.toml) and to be honest the experience was not great, and I went back to ccache.

The main reason for this (that is also not immediate to debug) is that sccache has a shared daemon, and SCCACHE_BASEDIRS is considered only when the daemon first starts. So if you are building multiple projects, the sccache will only see the SCCACHE_BASEDIRS of the first invoked project, with some unexpected behaviours that was tricky to debug.

fyi @EdoardoGruppi

@wolfv

wolfv commented Mar 24, 2026

Copy link
Copy Markdown
Member Author

I think with the setup as proposed here we could relatively easily extend support for ccache as well, because the compiler cache would be configurable. I'll try to get back to this PR soon :)

@traversaro

Copy link
Copy Markdown
Contributor

I think with the setup as proposed here we could relatively easily extend support for ccache as well, because the compiler cache would be configurable. I'll try to get back to this PR soon :)

Sure, great. I wanted to write down my experience with pixi+sccache somewhere in public, so that search engines and LLM could find it. :D

…onfig

Introduce an explicit `compiler-cache` configuration option instead of
auto-detecting sccache from `SCCACHE_*` environment variables.

- Add `CompilerCache` enum + `build.compiler-cache` to pixi config, with
  `config get/set` support.
- Thread the default compiler cache through the command dispatcher's
  compute-engine architecture via a new `CompilerCacheKey`, merging it into
  each backend's configuration JSON unless the package already sets it.
- Add config-gated sccache support to the CMake backend (compiler launchers,
  build dependency, secret handling, `--show-stats`).
- Migrate the Rust backend off `SCCACHE_*` env-var auto-detection to the same
  `compiler-cache` config option.
- Document the option and update backend docs.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@wolfv
wolfv force-pushed the claude/add-sccache-cmake-emFYd branch from ef92297 to 923a62c Compare May 27, 2026 05:42
The doc comment on with_compiler_cache linked to the private
CompilerCacheKey type, which fails rustdoc::private_intra_doc_links
under -D warnings. Use plain inline code instead.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@baszalmstra

Copy link
Copy Markdown
Contributor

I think we need to always add sccache to the build dependencies otherwise the lockfile is unsatisfiable based on environment variables. Should also do this for rust!

@wolfv

wolfv commented May 27, 2026

Copy link
Copy Markdown
Member Author

You mean based on the config value, right?

@baszalmstra

Copy link
Copy Markdown
Contributor

Ah, I misread! (The description has not been updated yet).

But yeah, if we now have two users, one has the compiler-cache set in their user config, they will get an unsatisfiability error because sccache is added as a build dependency, whereas the other user doesnt have that.

A compiler cache configured globally (in the user's pixi config) is a
per-machine preference, so adding its tool to a source package's build
requirements made the lockfile flip-flop depending on whether the
machine running the resolve had the cache configured.

Distinguish the two origins via a single `compiler-cache` key whose
value shape carries provenance: a bare string (`"sccache"`) is what a
package writes in its manifest and is locked as a build dependency,
while the command dispatcher injects the tagged `{ "default": "sccache" }`
form for a global default. The global default is used as a compiler
launcher only and never locked; the tool must already be on PATH, and
the build fails with a hint to run `pixi global install sccache` if it
is missing.

Applies to both the cmake and rust backends.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@lucascolley

Copy link
Copy Markdown
Collaborator

I think with the setup as proposed here we could relatively easily extend support for ccache as well, because the compiler cache would be configurable. I'll try to get back to this PR soon :)

I think we will want this soon for SciPy 😉

@traversaro

Copy link
Copy Markdown
Contributor

For sccache to be really useful in this context, we basically need mozilla/sccache#2814 to be merged and released in a sccache release.

@lucascolley

Copy link
Copy Markdown
Collaborator

@traversaro

Copy link
Copy Markdown
Contributor

I got ccache working to a satisfactory level with pixi-build-cmake with the following:

* https://github.com/scipy/xsf/blob/1b7a3a3f6f8ac6985c0c03662066e1d40b41bc8a/packages/tests-release/pixi.toml#L13-L19

* https://github.com/scipy/xsf/blob/1b7a3a3f6f8ac6985c0c03662066e1d40b41bc8a/.github/setup-test-env/action.yml#L11-L16

* https://github.com/scipy/xsf/blob/1b7a3a3f6f8ac6985c0c03662066e1d40b41bc8a/.github/ccache/action.yml#L11-L33

Would be cool if some of that was made automatic

I may be missing something, but if you are using RECIPE_DIR as CCACHE_BASEDIR, I guess the build and host environment are not included as part the folder considered by CCACHE_BASEDIR, so if the location where the package is built change, the ccache is invalidated? For GitHub Actions I think that is ok, but in general I guess it would be great to be able to reuse ccache across different machines.

@lucascolley

Copy link
Copy Markdown
Collaborator

Indeed, this is only setup for a single machine right now

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.

5 participants