build: fix mac CI ccache, only wrap darwin CC/CXX in env -u when include paths are set - #7540
build: fix mac CI ccache, only wrap darwin CC/CXX in env -u when include paths are set#7540PastaPastaPasta wants to merge 2 commits into
Conversation
The unconditional 'env -u C_INCLUDE_PATH -u CPLUS_INCLUDE_PATH' prefix on darwin_CC/darwin_CXX silently disables ccache for every macOS cross-compile in CI: configure prepends ccache to CC, producing 'ccache env -u VAR /path/to/clang ...'. ccache treats 'env' as the compiler (type 'other'), consumes '-u VAR' as an option taking an argument, and then classifies the absolute clang path -- an existing file not starting with '-' -- as a second source file. Every compile is rejected as 'multiple_source_files' and falls back to the real compiler, so the mac CI job recompiles all ~1000 objects from scratch (~22 min) on every run while saving a 17 KB ccache cache entry. The prefix exists to stop Guix (contrib/guix/libexec/build.sh) from leaking native-GCC include paths into the darwin cross-build. CI never sets those variables, so emit the prefix only when C_INCLUDE_PATH or CPLUS_INCLUDE_PATH is actually defined: Guix behavior is unchanged (variables set, and Guix does not use ccache), and CI gets a working mac ccache. depends build ids are unaffected in CI because gen_id hashes compiler -v output, which is byte-identical with and without the prefix when the variables are unset.
|
🕓 Ready for review — 17 ahead in queue (commit 1dc8e9b) |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
WalkthroughThe Darwin host configuration adds a conditional Estimated code review effort: 2 (Simple) | ~10 minutes Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
I don't fully follow this one; but ccache for Mac builds have been broken since Jan, we should probably fix that :) this is fable's proposal. |
|
Much better |
There was a problem hiding this comment.
Final validation — Codex + Sonnet
The change correctly applies the Darwin compiler environment wrapper only when either include-path variable is defined, preserving Guix header isolation while allowing ccache to invoke clang directly in CI. The implementation is narrowly scoped, handles unset, set, and set-but-empty variables correctly, and introduces no actionable defects.
Source: reviewers gpt-5.6-sol (general, dash-core-commit-history) and claude-sonnet-5 (general, dash-core-commit-history); final verifier gpt-5.6-sol (fallback after two unparseable claude-sonnet-5 verifier attempts).
Review provenance
- Codex reviewers:
gpt-5.6-sol— general (completed),gpt-5.6-sol— dash-core-commit-history (completed) - Verifier:
gpt-5.6-sol— final-verifier (fallback) - Sonnet reviewers:
claude-sonnet-5— general (failed),claude-sonnet-5— dash-core-commit-history (completed),claude-sonnet-5— general (completed)
| # TODO: remove C_INCLUDE_PATH when it is indeed useless | ||
| # https://github.com/bitcoin/bitcoin/pull/30451 has been partiall reverted in #7184 and should be re-applied | ||
| darwin_CC=env -u C_INCLUDE_PATH -u CPLUS_INCLUDE_PATH $(clang_prog) --target=$(host) \ | ||
| # C_INCLUDE_PATH/CPLUS_INCLUDE_PATH leak native-toolchain headers into the |
There was a problem hiding this comment.
keep TODO; bitcoin#30451 has been done partially and this workaround should be removed when 30451 is fully backported.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 1dc8e9b396
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| ifneq ($(origin C_INCLUDE_PATH) $(origin CPLUS_INCLUDE_PATH),undefined undefined) | ||
| darwin_env_unset=env -u C_INCLUDE_PATH -u CPLUS_INCLUDE_PATH |
There was a problem hiding this comment.
Invalidate the depends workflow cache for this host change
In the checked .github/workflows/build-depends.yml, PACKAGES_HASH includes only depends/packages/* and depends/Makefile (:78), so this change leaves the exact mac depends cache key unchanged and causes the producer job to be skipped. However, depends/funcs.mk:43-45 hashes hosts/darwin.mk into every package recipe ID, so the source consumer restores only old-ID package archives and rebuilds the entire mac dependency tree; because that consumer does not save the depends cache, this repeats on every mac run. Include the host file in the workflow cache key or otherwise force the producer to refresh the cache.
AGENTS.md reference: AGENTS.md:L195-L197
Useful? React with 👍 / 👎.
Issue being fixed or feature implemented
ccache is silently disabled for the entire
mac-buildCI job, and has been since d201e43 (2026-01-19) re-added theenv -uprefix todarwin_CC/darwin_CXX(it was previously broken from 2020-08 until the bitcoin#30451 backport in 1d8868b removed the prefix in 2025-02).Every mac CI run shows:
and recompiles all objects from scratch (~22 min compile in run 30848679596), while saving a 17 KB ccache cache entry.
Root cause: configure prepends ccache to
CC, producingccache env -u C_INCLUDE_PATH -u CPLUS_INCLUDE_PATH /usr/bin/clang .... ccache treatsenvas the compiler (typeother), consumes-u VARas an option taking an argument, then classifies the absolute clang path — an existing file not starting with-— as a second source file.CCACHE_DEBUGshows the verdict:Every call is rejected and silently falls back to the real compiler, so the build succeeds and nothing ever flagged it. Current ccache master has the same parsing behavior; this is not fixed by upgrading ccache.
What was done?
The
env -uprefix exists to stop Guix (contrib/guix/libexec/build.shexportsC_INCLUDE_PATH="${NATIVE_GCC}/include"etc.) from leaking native-toolchain headers into the darwin cross-build — the conflict d201e43 fixed. CI never sets those variables, so the prefix does nothing there except break ccache.The prefix is now emitted only when
C_INCLUDE_PATHorCPLUS_INCLUDE_PATHis actually defined (checked via$(origin ...), so set-but-empty still counts as set):$(clang_prog)→ ccache wraps clang directly and caching works.Upstream removed the prefix entirely (bitcoin#30451) because their Guix build.sh no longer exports these variables; ours still does, so the conditional keeps the Guix protection while re-applying the effect of bitcoin#30451 everywhere else. The stale TODO comments pointing at bitcoin#30451/#7184 are replaced with an explanation of both constraints.
Cached depends are not invalidated by this change:
depends/gen_idhashes compiler-voutput, which is byte-identical with and without the prefix when the variables are unset (verified below).How Has This Been Tested?
All in
ubuntu:24.04(same ccache 4.9.1 + clang 18 as the CI image), plus a make-level check:ccache env -u C_INCLUDE_PATH -u CPLUS_INCLUDE_PATH /usr/bin/clang --target=x86_64-apple-darwin -isysroot... -nostdlibinc ... -c t.c→Uncacheable calls: 1/1,CCACHE_DEBUGlog showsResult: multiple_source_files. Bareclanginstead of an absolute path does not trigger it, confirming the source-file misparse.Cacheable calls: 2/2, second compile is a cache hit.depends/hosts/darwin.mk: with both variables unsetdarwin_CChas no prefix; withC_INCLUDE_PATHset (or set-but-empty) the prefix is emitted.{clang -v; clang -v -E -xc -o /dev/null -}output (thegen_idpreimage components) is byte-identical with and without theenv -uprefix when the variables are unset, so CI's cached depends remain valid.Guix builds are unaffected by construction (the conditional evaluates true in that environment), but a
guix-buildrun on this PR will confirm.Breaking Changes
None.
Checklist: