From 477e5a7e7b6df4f16ea23bf616506a99ac298c45 Mon Sep 17 00:00:00 2001 From: pasta Date: Mon, 3 Aug 2026 19:07:03 -0500 Subject: [PATCH 1/2] build: only wrap darwin CC/CXX in env -u when include paths are set 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. --- depends/hosts/darwin.mk | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/depends/hosts/darwin.mk b/depends/hosts/darwin.mk index 977931c14855..f2f8545fa3fd 100644 --- a/depends/hosts/darwin.mk +++ b/depends/hosts/darwin.mk @@ -57,15 +57,24 @@ darwin_STRIP=$(shell $(SHELL) $(.SHELLFLAGS) "command -v llvm-strip") # in the SDK, where __has_feature(modules) is used to define USE_CLANG_TYPES, # which is in turn used as an include guard. -# 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 +# darwin cross-build and conflict with the SDK headers. Guix exports them +# (contrib/guix/libexec/build.sh), so strip them there with an `env -u` +# prefix. The prefix must not be emitted when the variables aren't set: +# ccache cannot parse a compiler command starting with `env` (it treats +# `env` as the compiler and the absolute clang path as a second source +# file), so an unconditional prefix silently disables ccache for every +# darwin compile. Unlike upstream (bitcoin#30451, which dropped the prefix +# entirely), our Guix environment still sets these variables. +ifneq ($(origin C_INCLUDE_PATH) $(origin CPLUS_INCLUDE_PATH),undefined undefined) +darwin_env_unset=env -u C_INCLUDE_PATH -u CPLUS_INCLUDE_PATH +endif + +darwin_CC=$(darwin_env_unset) $(clang_prog) --target=$(host) \ -isysroot$(OSX_SDK) -nostdlibinc \ -iwithsysroot/usr/include -iframeworkwithsysroot/System/Library/Frameworks -# 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_CXX=env -u C_INCLUDE_PATH -u CPLUS_INCLUDE_PATH $(clangxx_prog) --target=$(host) \ +darwin_CXX=$(darwin_env_unset) $(clangxx_prog) --target=$(host) \ -isysroot$(OSX_SDK) -nostdlibinc \ -iwithsysroot/usr/include/c++/v1 \ -iwithsysroot/usr/include -iframeworkwithsysroot/System/Library/Frameworks From 1dc8e9b396ae29262985a3e3547685b3790b7869 Mon Sep 17 00:00:00 2001 From: pasta Date: Tue, 4 Aug 2026 10:51:11 -0500 Subject: [PATCH 2/2] build: keep TODO comment on darwin C_INCLUDE_PATH workaround --- depends/hosts/darwin.mk | 1 + 1 file changed, 1 insertion(+) diff --git a/depends/hosts/darwin.mk b/depends/hosts/darwin.mk index f2f8545fa3fd..971347de5ae9 100644 --- a/depends/hosts/darwin.mk +++ b/depends/hosts/darwin.mk @@ -57,6 +57,7 @@ darwin_STRIP=$(shell $(SHELL) $(.SHELLFLAGS) "command -v llvm-strip") # in the SDK, where __has_feature(modules) is used to define USE_CLANG_TYPES, # which is in turn used as an include guard. +# TODO: remove C_INCLUDE_PATH/darwin_env_unset when bitcoin#30451 is fully backported. # C_INCLUDE_PATH/CPLUS_INCLUDE_PATH leak native-toolchain headers into the # darwin cross-build and conflict with the SDK headers. Guix exports them # (contrib/guix/libexec/build.sh), so strip them there with an `env -u`