Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 9 additions & 16 deletions packages/react-native/scripts/cocoapods/utils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For context:

Without this change we would see lots of repeated warnings during build:

Explicit modules is enabled but the compiler was not recognized; disable explicit modules with
CLANG_ENABLE_EXPLICIT_MODULES=NO, or use
C_COMPILER_LAUNCHER with CLANG_ENABLE_EXPLICIT_MODULES_WITH_COMPILER_LAUNCHER=YES if using a compatible launcher

config.build_settings["CLANG_ENABLE_EXPLICIT_MODULES_WITH_COMPILER_LAUNCHER"] = "YES"
end

project.save()
Expand All @@ -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()
Expand Down
19 changes: 19 additions & 0 deletions packages/react-native/scripts/xcode/c-compiler-launcher.sh
Original file line number Diff line number Diff line change
@@ -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
14 changes: 0 additions & 14 deletions packages/react-native/scripts/xcode/ccache-clang++.sh

This file was deleted.

14 changes: 0 additions & 14 deletions packages/react-native/scripts/xcode/ccache-clang.sh

This file was deleted.

Loading