From 23226bae2aa4a5dd0d8086e49f427ac615ca2875 Mon Sep 17 00:00:00 2001 From: Wildan Muhlis Date: Sat, 25 Apr 2026 21:13:20 +0700 Subject: [PATCH 1/2] Fix ccache being silently bypassed on iOS builds 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 --- packages/react-native/scripts/xcode/ccache-clang++.sh | 11 ++++++++++- packages/react-native/scripts/xcode/ccache-clang.sh | 11 ++++++++++- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/packages/react-native/scripts/xcode/ccache-clang++.sh b/packages/react-native/scripts/xcode/ccache-clang++.sh index 54ff8ba5816d..b4dee6cfe74b 100755 --- a/packages/react-native/scripts/xcode/ccache-clang++.sh +++ b/packages/react-native/scripts/xcode/ccache-clang++.sh @@ -11,4 +11,13 @@ REACT_NATIVE_CCACHE_CONFIGPATH=$SCRIPT_DIR/ccache.conf # Provide our config file if none is already provided export CCACHE_CONFIGPATH="${CCACHE_CONFIGPATH:-$REACT_NATIVE_CCACHE_CONFIGPATH}" -exec $CCACHE_BINARY clang++ "$@" +# Xcode does not export user-defined build settings as environment variables +# for invoked scripts, so $CCACHE_BINARY may be empty even when set in the +# project. Fall back to a PATH lookup so ccache is still used. +CCACHE_BINARY="${CCACHE_BINARY:-$(command -v ccache)}" + +if [ -n "$CCACHE_BINARY" ]; then + exec "$CCACHE_BINARY" clang++ "$@" +fi + +exec clang++ "$@" diff --git a/packages/react-native/scripts/xcode/ccache-clang.sh b/packages/react-native/scripts/xcode/ccache-clang.sh index 9b1a355c2cce..be632004cf10 100755 --- a/packages/react-native/scripts/xcode/ccache-clang.sh +++ b/packages/react-native/scripts/xcode/ccache-clang.sh @@ -11,4 +11,13 @@ REACT_NATIVE_CCACHE_CONFIGPATH=$SCRIPT_DIR/ccache.conf # Provide our config file if none is already provided export CCACHE_CONFIGPATH="${CCACHE_CONFIGPATH:-$REACT_NATIVE_CCACHE_CONFIGPATH}" -exec $CCACHE_BINARY clang "$@" +# Xcode does not export user-defined build settings as environment variables +# for invoked scripts, so $CCACHE_BINARY may be empty even when set in the +# project. Fall back to a PATH lookup so ccache is still used. +CCACHE_BINARY="${CCACHE_BINARY:-$(command -v ccache)}" + +if [ -n "$CCACHE_BINARY" ]; then + exec "$CCACHE_BINARY" clang "$@" +fi + +exec clang "$@" From 8c79958d2b06bc75153a868b8d59bb3a9f98600e Mon Sep 17 00:00:00 2001 From: Wildan Muhlis Date: Fri, 20 Nov 2026 21:46:58 +0700 Subject: [PATCH 2/2] Look for ccache in Homebrew prefixes when it is not on PATH 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. --- .../react-native/scripts/xcode/ccache-clang++.sh | 13 +++++++++---- packages/react-native/scripts/xcode/ccache-clang.sh | 13 +++++++++---- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/packages/react-native/scripts/xcode/ccache-clang++.sh b/packages/react-native/scripts/xcode/ccache-clang++.sh index b4dee6cfe74b..4e5198116985 100755 --- a/packages/react-native/scripts/xcode/ccache-clang++.sh +++ b/packages/react-native/scripts/xcode/ccache-clang++.sh @@ -11,10 +11,15 @@ REACT_NATIVE_CCACHE_CONFIGPATH=$SCRIPT_DIR/ccache.conf # Provide our config file if none is already provided export CCACHE_CONFIGPATH="${CCACHE_CONFIGPATH:-$REACT_NATIVE_CCACHE_CONFIGPATH}" -# Xcode does not export user-defined build settings as environment variables -# for invoked scripts, so $CCACHE_BINARY may be empty even when set in the -# project. Fall back to a PATH lookup so ccache is still used. -CCACHE_BINARY="${CCACHE_BINARY:-$(command -v ccache)}" +# CCACHE_BINARY does not reach compile tasks, and Xcode app builds may not have Homebrew on PATH. +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 if [ -n "$CCACHE_BINARY" ]; then exec "$CCACHE_BINARY" clang++ "$@" diff --git a/packages/react-native/scripts/xcode/ccache-clang.sh b/packages/react-native/scripts/xcode/ccache-clang.sh index be632004cf10..4696aae8f74d 100755 --- a/packages/react-native/scripts/xcode/ccache-clang.sh +++ b/packages/react-native/scripts/xcode/ccache-clang.sh @@ -11,10 +11,15 @@ REACT_NATIVE_CCACHE_CONFIGPATH=$SCRIPT_DIR/ccache.conf # Provide our config file if none is already provided export CCACHE_CONFIGPATH="${CCACHE_CONFIGPATH:-$REACT_NATIVE_CCACHE_CONFIGPATH}" -# Xcode does not export user-defined build settings as environment variables -# for invoked scripts, so $CCACHE_BINARY may be empty even when set in the -# project. Fall back to a PATH lookup so ccache is still used. -CCACHE_BINARY="${CCACHE_BINARY:-$(command -v ccache)}" +# CCACHE_BINARY does not reach compile tasks, and Xcode app builds may not have Homebrew on PATH. +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 if [ -n "$CCACHE_BINARY" ]; then exec "$CCACHE_BINARY" clang "$@"