Skip to content

Fix ccache being silently bypassed on iOS builds - #60199

Open
wildan-m wants to merge 2 commits into
react:mainfrom
wildan-m:fix-ccache-binary-fallback
Open

wildan-m wants to merge 2 commits into
react:mainfrom
wildan-m:fix-ccache-binary-fallback

Conversation

@wildan-m

@wildan-m wildan-m commented Nov 21, 2026 •

Copy link
Copy Markdown

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 (or USE_CCACHE=1), packages/react-native/scripts/cocoapods/utils.rb wires up ccache-clang.sh / ccache-clang++.sh as CC / CXX and writes the resolved ccache path to a CCACHE_BINARY Xcode build setting. The shell wrappers then run exec $CCACHE_BINARY clang "$@".

The problem: Xcode passes user-defined build settings to Run Script phases but not to compile tasks, so $CCACHE_BINARY is empty when the wrapper runs as CC / 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 became exec clang "$@", so ccache was never invoked, even though everything else was set up correctly.

When CCACHE_BINARY is unset, the wrappers now look for ccache themselves: first with command -v ccache, then at /opt/homebrew/bin/ccache and /usr/local/bin/ccache, because builds started from the Xcode app don't get the shell's PATH. 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_BINARY build setting to compile tasks, including builds started from the Xcode app.

Test Plan:

Ran both wrappers with a fake ccache that prints how it was called:

  1. CCACHE_BINARY set: that ccache is used.
  2. CCACHE_BINARY unset, ccache on PATH (the bug case): ccache is found with command -v and used, in both ccache-clang.sh and ccache-clang++.sh.
  3. CCACHE_BINARY unset, ccache not on PATH but 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).
  4. ccache on PATH and in a Homebrew prefix: the PATH one wins, and an explicit CCACHE_BINARY wins over both.
  5. No ccache anywhere: the wrappers fall back to plain clang / clang++, so projects without ccache still build.
  6. Arguments with spaces are passed through unchanged, and CCACHE_CONFIGPATH still defaults to the bundled ccache.conf unless it is already set.
# The bug case: CCACHE_BINARY unset, ccache only on PATH
env -i PATH="/path/with/ccache:/usr/bin:/bin" /bin/sh \
  packages/react-native/scripts/xcode/ccache-clang.sh --version
# Before: runs clang directly, no ccache
# After:  goes through ccache

shellcheck is 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:

  • In every compile and link step CCACHE_BINARY was unset and PATH had no Homebrew directory (/Applications/Xcode-26.3.0.app/Contents/Developer/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin for compiles), so command -v ccache found nothing. The wrappers picked /opt/homebrew/bin/ccache from the fallback for all 840 calls.
  • First build: 838 cache misses, build succeeded in about 95 s. After deleting the build folder, the rebuild got 838/838 cache hits and took about 18 s.

This branch predates #56585, so for that build I applied the podspec fix from #56585 locally; it isn't part of this PR.

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.
@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Nov 21, 2026
@facebook-github-tools facebook-github-tools Bot added the Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team. label Nov 21, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ccache isn't used by iOS builds because CCACHE_BINARY is missing

1 participant