Skip to content

Fix ccache being silently bypassed on iOS builds - #56612

Closed
wildan-m wants to merge 1 commit into
react:mainfrom
wildan-m:fix-ccache-binary-fallback
Closed

wildan-m wants to merge 1 commit into
react:mainfrom
wildan-m:fix-ccache-binary-fallback

Conversation

@wildan-m

Copy link
Copy Markdown

Summary:

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: as of recent Xcode versions (confirmed at least on Xcode 26.2 by the issue reporter, and reproducible by inspection — Xcode does not export user-defined build settings as environment variables for invoked scripts), $CCACHE_BINARY is empty when the wrapper runs. 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.

This change makes the wrappers fall back to command -v ccache when CCACHE_BINARY is unset, and only prepends ccache when an executable is actually available so projects without ccache installed still build.

Fixes #55381

Changelog:

[IOS] [FIXED] - ccache is no longer silently bypassed on iOS builds when Xcode does not propagate the CCACHE_BINARY user-defined build setting to scripts.

Test Plan:

Smoke-tested the modified wrappers under four scenarios with a fake ccache on PATH:

  1. CCACHE_BINARY set explicitly — ccache is invoked. ✅
  2. CCACHE_BINARY unset, ccache on PATH (the bug case) — wrapper now finds and invokes ccache via the PATH fallback. ✅
  3. C++ wrapper with CCACHE_BINARY unset, ccache on PATH — same behaviour for ccache-clang++.sh. ✅
  4. No ccache anywhere — wrapper falls through to direct clang/clang++ invocation, so projects without ccache still build (no regression vs. previous silent-bypass behaviour, just no longer a build error). ✅
# Reproducing T2 (the bug case):
env -i PATH="/path/with/ccache:/usr/bin:/bin" /bin/sh \
  packages/react-native/scripts/xcode/ccache-clang.sh --version
# Before this PR: ran clang directly, no ccache
# After this PR:  routes through ccache as expected

shellcheck is clean on both files.

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 #55381
@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 Apr 25, 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 Apr 25, 2026
troZee added a commit to callstack/react-native-pager-view that referenced this pull request Oct 9, 2026
Xcode does not export the CCACHE_BINARY build setting to the compiler
wrapper, so RN's ccache-clang.sh ran plain clang. Backport
react/react-native#56612 via a bun patch and drop the explicit
modules workaround.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@react-native-bot

Copy link
Copy Markdown
Collaborator

This PR is stale because it has been open for 180 days with no activity. It will be closed in 7 days unless you comment on it or remove the "Stale" label.

@react-native-bot

Copy link
Copy Markdown
Collaborator

This PR is stale because it has been open 180 days with no activity. Remove stale label or comment or this will be closed in 7 days.

@react-native-bot react-native-bot added Stale There has been a lack of activity on this issue and it may be closed soon. and removed Stale There has been a lack of activity on this issue and it may be closed soon. labels Oct 23, 2026
@migueldaipre

Copy link
Copy Markdown
Collaborator

Any news?

@PsukheDelos

PsukheDelos commented Nov 20, 2026 •

Copy link
Copy Markdown

Thanks for putting this together, @wildan-m, and for keeping it going.

Tested on React Native 0.88.1 with Xcode 27.2: without this change, CCACHE_BINARY is empty in the wrappers and ccache is skipped.

One gap: builds started from the Xcode app don't have Homebrew on PATH, so command -v ccache finds nothing there. We fall back to Homebrew's paths locally:

if [ -z "$CCACHE_BINARY" ]; then
  for candidate in "$(command -v ccache)" /opt/homebrew/bin/ccache /usr/local/bin/ccache; do
    if [ -x "$candidate" ]; then
      CCACHE_BINARY=$candidate
      break
    fi
  done
fi

A more general option: since utils.rb already finds ccache at pod install time, it could write the wrappers with that path baked in, so any install location works.

@wildan-m wildan-m closed this by deleting the head repository Nov 21, 2026
@wildan-m

Copy link
Copy Markdown
Author

@migueldaipre @PsukheDelos I've moved this to #60199. GitHub locked my fork during the move to react/react-native and I couldn't push to it, so I had to delete and re-create the fork, which closed this PR.

#60199 adds the Homebrew fallback (/opt/homebrew/bin/ccache, then /usr/local/bin/ccache) for builds started from the Xcode app. I kept the lookup in the wrappers rather than writing the path in at pod install, since that would mean generating the scripts per project. Happy to switch if the maintainers prefer that.

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

4 participants