Skip to content

Commit 23226ba

Browse files
committed
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
1 parent 11d894d commit 23226ba

2 files changed

Lines changed: 20 additions & 2 deletions

File tree

packages/react-native/scripts/xcode/ccache-clang++.sh

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,13 @@ REACT_NATIVE_CCACHE_CONFIGPATH=$SCRIPT_DIR/ccache.conf
1111
# Provide our config file if none is already provided
1212
export CCACHE_CONFIGPATH="${CCACHE_CONFIGPATH:-$REACT_NATIVE_CCACHE_CONFIGPATH}"
1313

14-
exec $CCACHE_BINARY clang++ "$@"
14+
# Xcode does not export user-defined build settings as environment variables
15+
# for invoked scripts, so $CCACHE_BINARY may be empty even when set in the
16+
# project. Fall back to a PATH lookup so ccache is still used.
17+
CCACHE_BINARY="${CCACHE_BINARY:-$(command -v ccache)}"
18+
19+
if [ -n "$CCACHE_BINARY" ]; then
20+
exec "$CCACHE_BINARY" clang++ "$@"
21+
fi
22+
23+
exec clang++ "$@"

packages/react-native/scripts/xcode/ccache-clang.sh

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,13 @@ REACT_NATIVE_CCACHE_CONFIGPATH=$SCRIPT_DIR/ccache.conf
1111
# Provide our config file if none is already provided
1212
export CCACHE_CONFIGPATH="${CCACHE_CONFIGPATH:-$REACT_NATIVE_CCACHE_CONFIGPATH}"
1313

14-
exec $CCACHE_BINARY clang "$@"
14+
# Xcode does not export user-defined build settings as environment variables
15+
# for invoked scripts, so $CCACHE_BINARY may be empty even when set in the
16+
# project. Fall back to a PATH lookup so ccache is still used.
17+
CCACHE_BINARY="${CCACHE_BINARY:-$(command -v ccache)}"
18+
19+
if [ -n "$CCACHE_BINARY" ]; then
20+
exec "$CCACHE_BINARY" clang "$@"
21+
fi
22+
23+
exec clang "$@"

0 commit comments

Comments
 (0)