From 0b29756d3943bea6e835c161f147d413e765a57a Mon Sep 17 00:00:00 2001 From: Mateusz Rajski Date: Mon, 24 Nov 2025 15:01:16 +0100 Subject: [PATCH] Bring back ccache support on new Xcode versions --- .../react-native/scripts/cocoapods/utils.rb | 25 +++++++------------ .../scripts/xcode/c-compiler-launcher.sh | 19 ++++++++++++++ .../scripts/xcode/ccache-clang++.sh | 14 ----------- .../scripts/xcode/ccache-clang.sh | 14 ----------- 4 files changed, 28 insertions(+), 44 deletions(-) create mode 100755 packages/react-native/scripts/xcode/c-compiler-launcher.sh delete mode 100755 packages/react-native/scripts/xcode/ccache-clang++.sh delete mode 100755 packages/react-native/scripts/xcode/ccache-clang.sh diff --git a/packages/react-native/scripts/cocoapods/utils.rb b/packages/react-native/scripts/cocoapods/utils.rb index a457bd48d79558..f5d4863b7ce074 100644 --- a/packages/react-native/scripts/cocoapods/utils.rb +++ b/packages/react-native/scripts/cocoapods/utils.rb @@ -102,23 +102,19 @@ def self.set_ccache_compiler_and_linker_build_settings(installer, react_native_p if ccache_available Pod::UI.puts("#{message_prefix}: Ccache found at #{ccache_path}") - end - - # Using scripts wrapping the ccache executable, to allow injection of configurations - ccache_clang_sh = File.join("$(REACT_NATIVE_PATH)", 'scripts', 'xcode', 'ccache-clang.sh') - ccache_clangpp_sh = File.join("$(REACT_NATIVE_PATH)", 'scripts', 'xcode', 'ccache-clang++.sh') + end if ccache_available and ccache_enabled Pod::UI.puts("#{message_prefix}: Setting CC, LD, CXX & LDPLUSPLUS build settings") + # Using scripts wrapping the ccache executable, to allow injection of configurations + c_compiler_launcher = File.join("$(REACT_NATIVE_PATH)", 'scripts', 'xcode', 'c-compiler-launcher.sh') + projects.each do |project| project.build_configurations.each do |config| # Using the un-qualified names means you can swap in different implementations, for example ccache - config.build_settings["CC"] = ccache_clang_sh - config.build_settings["LD"] = ccache_clang_sh - config.build_settings["CXX"] = ccache_clangpp_sh - config.build_settings["LDPLUSPLUS"] = ccache_clangpp_sh - config.build_settings["CCACHE_BINARY"] = ccache_path + config.build_settings["C_COMPILER_LAUNCHER"] = c_compiler_launcher + config.build_settings["CLANG_ENABLE_EXPLICIT_MODULES_WITH_COMPILER_LAUNCHER"] = "YES" end project.save() @@ -128,15 +124,12 @@ def self.set_ccache_compiler_and_linker_build_settings(installer, react_native_p elsif !ccache_available and ccache_enabled Pod::UI.warn("#{message_prefix}: Install ccache or ensure your neither passing ':ccache_enabled => true' nor setting environment variable 'USE_CCACHE=1'") else - Pod::UI.puts("#{message_prefix}: Removing Ccache from CC, LD, CXX & LDPLUSPLUS build settings") + Pod::UI.puts("#{message_prefix}: Removing Ccache compiler launcher build settings") projects.each do |project| project.build_configurations.each do |config| - # Using the un-qualified names means you can swap in different implementations, for example ccache - config.build_settings["CC"] = config.build_settings["CC"].gsub(/#{Regexp.escape(ccache_clang_sh)}/, '') if config.build_settings["CC"] - config.build_settings["LD"] = config.build_settings["LD"].gsub(/#{Regexp.escape(ccache_clang_sh)}/, "") if config.build_settings["LD"] - config.build_settings["CXX"] = config.build_settings["CXX"].gsub(/#{Regexp.escape(ccache_clangpp_sh)}/, "") if config.build_settings["CXX"] - config.build_settings["LDPLUSPLUS"] = config.build_settings["LDPLUSPLUS"].gsub(/#{Regexp.escape(ccache_clangpp_sh)}/, "") if config.build_settings["LDPLUSPLUS"] + config.build_settings.delete "C_COMPILER_LAUNCHER" + config.build_settings.delete "CLANG_ENABLE_EXPLICIT_MODULES_WITH_COMPILER_LAUNCHER" end project.save() diff --git a/packages/react-native/scripts/xcode/c-compiler-launcher.sh b/packages/react-native/scripts/xcode/c-compiler-launcher.sh new file mode 100755 index 00000000000000..e161c90230cd73 --- /dev/null +++ b/packages/react-native/scripts/xcode/c-compiler-launcher.sh @@ -0,0 +1,19 @@ +#!/bin/sh +# Copyright (c) Meta Platforms, Inc. and affiliates. +# +# This source code is licensed under the MIT license found in the +# LICENSE file in the root directory of this source tree. + +# Get the absolute path of this script +SCRIPT_DIR="$(dirname "$(readlink -f "$0")")" +CCACHE_BINARY="$(command -v ccache)" + +# If ccache is available, use it with our config +if [ -n "$CCACHE_BINARY" ] && [ -x "$CCACHE_BINARY" ]; then + REACT_NATIVE_CCACHE_CONFIGPATH=$SCRIPT_DIR/ccache.conf + export CCACHE_CONFIGPATH="${CCACHE_CONFIGPATH:-$REACT_NATIVE_CCACHE_CONFIGPATH}" + exec "$CCACHE_BINARY" "$@" +else + # Fallback to direct execution + exec "$@" +fi diff --git a/packages/react-native/scripts/xcode/ccache-clang++.sh b/packages/react-native/scripts/xcode/ccache-clang++.sh deleted file mode 100755 index 54ff8ba5816dd9..00000000000000 --- a/packages/react-native/scripts/xcode/ccache-clang++.sh +++ /dev/null @@ -1,14 +0,0 @@ -#!/bin/sh -# Copyright (c) Meta Platforms, Inc. and affiliates. -# -# This source code is licensed under the MIT license found in the -# LICENSE file in the root directory of this source tree. - -# Get the absolute path of this script -SCRIPT_DIR="$(dirname "$(readlink -f "$0")")" - -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++ "$@" diff --git a/packages/react-native/scripts/xcode/ccache-clang.sh b/packages/react-native/scripts/xcode/ccache-clang.sh deleted file mode 100755 index 9b1a355c2ccef0..00000000000000 --- a/packages/react-native/scripts/xcode/ccache-clang.sh +++ /dev/null @@ -1,14 +0,0 @@ -#!/bin/sh -# Copyright (c) Meta Platforms, Inc. and affiliates. -# -# This source code is licensed under the MIT license found in the -# LICENSE file in the root directory of this source tree. - -# Get the absolute path of this script -SCRIPT_DIR="$(dirname "$(readlink -f "$0")")" - -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 "$@"