Repository navigation
Conversation
Xcode does not export user-defined build settings as environment variables for invoked scripts, so the CCACHE_BINARY value set on the project by react_native_post_install never reached ccache-clang.sh / ccache-clang++.sh. Because the original exec command collapsed an empty $CCACHE_BINARY, builds silently invoked clang directly and ccache was never used. Fall back to a PATH lookup when CCACHE_BINARY is unset, and only prepend ccache when an executable is actually available so projects without ccache still build. Fixes react#55381
Builds started from the Xcode app do not get the shell PATH, so on Apple Silicon `command -v ccache` finds nothing and the wrappers fall back to plain clang. Check /opt/homebrew/bin and /usr/local/bin before giving up.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary:
This replaces #56612. GitHub locked my fork during the move from facebook/react-native to react/react-native, so I couldn't push to that PR anymore. I had to delete and re-create the fork, which closed it. The change is the same, plus the Homebrew fallback suggested in the review there.
When ccache is enabled for an iOS build via
react_native_post_install(orUSE_CCACHE=1),packages/react-native/scripts/cocoapods/utils.rbwires upccache-clang.sh/ccache-clang++.shasCC/CXXand writes the resolved ccache path to aCCACHE_BINARYXcode build setting. The shell wrappers then runexec $CCACHE_BINARY clang "$@".The problem: Xcode passes user-defined build settings to Run Script phases but not to compile tasks, so
$CCACHE_BINARYis empty when the wrapper runs asCC/CXX(reported on Xcode 26.2 and 26.5 in #55381, and confirmed on Xcode 27.2 with React Native 0.88.1 in #56612). Because the variable was unquoted, the empty value collapsed and the line silently becameexec clang "$@", so ccache was never invoked, even though everything else was set up correctly.When
CCACHE_BINARYis unset, the wrappers now look for ccache themselves: first withcommand -v ccache, then at/opt/homebrew/bin/ccacheand/usr/local/bin/ccache, because builds started from the Xcode app don't get the shell'sPATH. ccache is only prepended when an executable is found, so projects without ccache still build.Fixes #55381
Changelog:
[IOS] [FIXED] - ccache is no longer silently bypassed on iOS builds when Xcode does not pass the
CCACHE_BINARYbuild setting to compile tasks, including builds started from the Xcode app.Test Plan:
Ran both wrappers with a fake
ccachethat prints how it was called:CCACHE_BINARYset: that ccache is used.CCACHE_BINARYunset,ccacheonPATH(the bug case): ccache is found withcommand -vand used, in bothccache-clang.shandccache-clang++.sh.CCACHE_BINARYunset,ccachenot onPATHbut in the Apple Silicon or Intel Homebrew prefix: ccache is found there and used (tested with copies of the wrappers whose Homebrew paths point at a temp directory).ccacheonPATHand in a Homebrew prefix: thePATHone wins, and an explicitCCACHE_BINARYwins over both.clang/clang++, so projects without ccache still build.CCACHE_CONFIGPATHstill defaults to the bundledccache.confunless it is already set.shellcheckis clean on both files.I also built RNTester from the Xcode app (Xcode 26.3 opened from the Dock, Apple Silicon, ccache 4.14.3 from Homebrew, pods installed with
USE_CCACHE=1), with a temporary log line in the wrappers:CCACHE_BINARYwas unset andPATHhad no Homebrew directory (/Applications/Xcode-26.3.0.app/Contents/Developer/usr/bin:/usr/bin:/bin:/usr/sbin:/sbinfor compiles), socommand -v ccachefound nothing. The wrappers picked/opt/homebrew/bin/ccachefrom the fallback for all 840 calls.This branch predates #56585, so for that build I applied the podspec fix from #56585 locally; it isn't part of this PR.