Skip to content

Commit 0b29756

Browse files
committed
Bring back ccache support on new Xcode versions
1 parent eb13eba commit 0b29756

4 files changed

Lines changed: 28 additions & 44 deletions

File tree

packages/react-native/scripts/cocoapods/utils.rb

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -102,23 +102,19 @@ def self.set_ccache_compiler_and_linker_build_settings(installer, react_native_p
102102

103103
if ccache_available
104104
Pod::UI.puts("#{message_prefix}: Ccache found at #{ccache_path}")
105-
end
106-
107-
# Using scripts wrapping the ccache executable, to allow injection of configurations
108-
ccache_clang_sh = File.join("$(REACT_NATIVE_PATH)", 'scripts', 'xcode', 'ccache-clang.sh')
109-
ccache_clangpp_sh = File.join("$(REACT_NATIVE_PATH)", 'scripts', 'xcode', 'ccache-clang++.sh')
105+
end
110106

111107
if ccache_available and ccache_enabled
112108
Pod::UI.puts("#{message_prefix}: Setting CC, LD, CXX & LDPLUSPLUS build settings")
113109

110+
# Using scripts wrapping the ccache executable, to allow injection of configurations
111+
c_compiler_launcher = File.join("$(REACT_NATIVE_PATH)", 'scripts', 'xcode', 'c-compiler-launcher.sh')
112+
114113
projects.each do |project|
115114
project.build_configurations.each do |config|
116115
# Using the un-qualified names means you can swap in different implementations, for example ccache
117-
config.build_settings["CC"] = ccache_clang_sh
118-
config.build_settings["LD"] = ccache_clang_sh
119-
config.build_settings["CXX"] = ccache_clangpp_sh
120-
config.build_settings["LDPLUSPLUS"] = ccache_clangpp_sh
121-
config.build_settings["CCACHE_BINARY"] = ccache_path
116+
config.build_settings["C_COMPILER_LAUNCHER"] = c_compiler_launcher
117+
config.build_settings["CLANG_ENABLE_EXPLICIT_MODULES_WITH_COMPILER_LAUNCHER"] = "YES"
122118
end
123119

124120
project.save()
@@ -128,15 +124,12 @@ def self.set_ccache_compiler_and_linker_build_settings(installer, react_native_p
128124
elsif !ccache_available and ccache_enabled
129125
Pod::UI.warn("#{message_prefix}: Install ccache or ensure your neither passing ':ccache_enabled => true' nor setting environment variable 'USE_CCACHE=1'")
130126
else
131-
Pod::UI.puts("#{message_prefix}: Removing Ccache from CC, LD, CXX & LDPLUSPLUS build settings")
127+
Pod::UI.puts("#{message_prefix}: Removing Ccache compiler launcher build settings")
132128

133129
projects.each do |project|
134130
project.build_configurations.each do |config|
135-
# Using the un-qualified names means you can swap in different implementations, for example ccache
136-
config.build_settings["CC"] = config.build_settings["CC"].gsub(/#{Regexp.escape(ccache_clang_sh)}/, '') if config.build_settings["CC"]
137-
config.build_settings["LD"] = config.build_settings["LD"].gsub(/#{Regexp.escape(ccache_clang_sh)}/, "") if config.build_settings["LD"]
138-
config.build_settings["CXX"] = config.build_settings["CXX"].gsub(/#{Regexp.escape(ccache_clangpp_sh)}/, "") if config.build_settings["CXX"]
139-
config.build_settings["LDPLUSPLUS"] = config.build_settings["LDPLUSPLUS"].gsub(/#{Regexp.escape(ccache_clangpp_sh)}/, "") if config.build_settings["LDPLUSPLUS"]
131+
config.build_settings.delete "C_COMPILER_LAUNCHER"
132+
config.build_settings.delete "CLANG_ENABLE_EXPLICIT_MODULES_WITH_COMPILER_LAUNCHER"
140133
end
141134

142135
project.save()
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/bin/sh
2+
# Copyright (c) Meta Platforms, Inc. and affiliates.
3+
#
4+
# This source code is licensed under the MIT license found in the
5+
# LICENSE file in the root directory of this source tree.
6+
7+
# Get the absolute path of this script
8+
SCRIPT_DIR="$(dirname "$(readlink -f "$0")")"
9+
CCACHE_BINARY="$(command -v ccache)"
10+
11+
# If ccache is available, use it with our config
12+
if [ -n "$CCACHE_BINARY" ] && [ -x "$CCACHE_BINARY" ]; then
13+
REACT_NATIVE_CCACHE_CONFIGPATH=$SCRIPT_DIR/ccache.conf
14+
export CCACHE_CONFIGPATH="${CCACHE_CONFIGPATH:-$REACT_NATIVE_CCACHE_CONFIGPATH}"
15+
exec "$CCACHE_BINARY" "$@"
16+
else
17+
# Fallback to direct execution
18+
exec "$@"
19+
fi

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

Lines changed: 0 additions & 14 deletions
This file was deleted.

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

Lines changed: 0 additions & 14 deletions
This file was deleted.

0 commit comments

Comments
 (0)