From 23226bae2aa4a5dd0d8086e49f427ac615ca2875 Mon Sep 17 00:00:00 2001 From: Wildan Muhlis Date: Sat, 25 Apr 2026 21:13:20 +0700 Subject: [PATCH] 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 "$@"