From 6dd83cbb3510b204974d4f9876a789b127e1bfef Mon Sep 17 00:00:00 2001 From: Riccardo Cipolleschi Date: Mon, 15 Apr 2024 10:11:03 -0700 Subject: [PATCH] Backport fix for Ccache from 0.74 to main (#44089) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/44089 While doing the release of 0.74.0-RC.9, we encountered some failures while building because the committed project had some new flags that have been added by cocoapods and that required Ccache. However, Ccache is not a hard requirement to run React Native and the build started failing on systems that does not have ccache installed. That happened because we were missing the piece of code that removed Ccache from the project in case the tool is not installed in the system. We already committed such commit in the stable branch of 0.74, with [this commit](https://github.com/facebook/react-native/commit/2b18fdf8063b423a0fb5762f2c6044244b4c35e6). This change will port the same fix in main. ## Changelog [iOS][Fixed] - Make sure to remove ccache scripts when ccache is not installed Reviewed By: cortinico Differential Revision: D56140015 fbshipit-source-id: 24e7ebb4e5c08766b29705e8b6f03c3f164a96ab --- .../react-native/scripts/cocoapods/utils.rb | 21 ++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/packages/react-native/scripts/cocoapods/utils.rb b/packages/react-native/scripts/cocoapods/utils.rb index 06c07b986a60b7..a41b2997888ae9 100644 --- a/packages/react-native/scripts/cocoapods/utils.rb +++ b/packages/react-native/scripts/cocoapods/utils.rb @@ -98,11 +98,12 @@ def self.set_ccache_compiler_and_linker_build_settings(installer, react_native_p 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') + 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 - 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') projects.each do |project| project.build_configurations.each do |config| @@ -119,6 +120,20 @@ def self.set_ccache_compiler_and_linker_build_settings(installer, react_native_p Pod::UI.puts("#{message_prefix}: Pass ':ccache_enabled => true' to 'react_native_post_install' in your Podfile or set environment variable 'USE_CCACHE=1' to increase the speed of subsequent builds") 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") + + 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"] ? config.build_settings["CC"].gsub(/#{Regexp.escape(ccache_clang_sh)}/, '') : "" + config.build_settings["LD"] = config.build_settings["LD"] ? config.build_settings["LD"].gsub(/#{Regexp.escape(ccache_clang_sh)}/, "") : "" + config.build_settings["CXX"] = config.build_settings["CXX"] ? config.build_settings["CXX"].gsub(/#{Regexp.escape(ccache_clangpp_sh)}/, "") : "" + config.build_settings["LDPLUSPLUS"] = config.build_settings["LDPLUSPLUS"] ? config.build_settings["LDPLUSPLUS"].gsub(/#{Regexp.escape(ccache_clangpp_sh)}/, "") : "" + end + + project.save() + end end end