From c5e549e694607cd576be8fcb5ed909fec2ed6dce Mon Sep 17 00:00:00 2001 From: Riccardo Cipolleschi Date: Thu, 8 Jun 2023 12:28:43 +0100 Subject: [PATCH] [LOCAL] Make 0.70 compatible with Xcode 15 (thanks to @AlexanderEggers for the commit in main) --- scripts/cocoapods/__tests__/utils-test.rb | 54 +++++++++++++++++++++++ scripts/cocoapods/utils.rb | 12 +++++ scripts/react_native_pods.rb | 1 + 3 files changed, 67 insertions(+) diff --git a/scripts/cocoapods/__tests__/utils-test.rb b/scripts/cocoapods/__tests__/utils-test.rb index bef4b5f9fb33cd..050bd7cbf13722 100644 --- a/scripts/cocoapods/__tests__/utils-test.rb +++ b/scripts/cocoapods/__tests__/utils-test.rb @@ -474,6 +474,60 @@ def test_applyMacCatalystPatches_correctlyAppliesNecessaryPatches assert_equal(user_project_mock.save_invocation_count, 1) end + # ================================= # + # Test - Apply Xcode 15 Patch # + # ================================= # + + def test_applyXcode15Patch_correctlyAppliesNecessaryPatch + # Arrange + first_target = prepare_target("FirstTarget") + second_target = prepare_target("SecondTarget") + third_target = TargetMock.new("ThirdTarget", [ + BuildConfigurationMock.new("Debug", { + "GCC_PREPROCESSOR_DEFINITIONS" => '$(inherited) "SomeFlag=1" ' + }), + BuildConfigurationMock.new("Release", { + "GCC_PREPROCESSOR_DEFINITIONS" => '$(inherited) "SomeFlag=1" ' + }), + ], nil) + + user_project_mock = UserProjectMock.new("a/path", [ + prepare_config("Debug"), + prepare_config("Release"), + ], + :native_targets => [ + first_target, + second_target + ] + ) + pods_projects_mock = PodsProjectMock.new([], {"hermes-engine" => {}}, :native_targets => [ + third_target + ]) + installer = InstallerMock.new(pods_projects_mock, [ + AggregatedProjectMock.new(user_project_mock) + ]) + + # Act + ReactNativePodsUtils.apply_xcode_15_patch(installer) + + # Assert + first_target.build_configurations.each do |config| + assert_equal(config.build_settings["GCC_PREPROCESSOR_DEFINITIONS"].strip, + '$(inherited) "_LIBCPP_ENABLE_CXX17_REMOVED_UNARY_BINARY_FUNCTION"' + ) + end + second_target.build_configurations.each do |config| + assert_equal(config.build_settings["GCC_PREPROCESSOR_DEFINITIONS"].strip, + '$(inherited) "_LIBCPP_ENABLE_CXX17_REMOVED_UNARY_BINARY_FUNCTION"' + ) + end + third_target.build_configurations.each do |config| + assert_equal(config.build_settings["GCC_PREPROCESSOR_DEFINITIONS"].strip, + '$(inherited) "SomeFlag=1" "_LIBCPP_ENABLE_CXX17_REMOVED_UNARY_BINARY_FUNCTION"' + ) + end + end + # ==================================== # # Test - Set Node_Modules User Setting # # ==================================== # diff --git a/scripts/cocoapods/utils.rb b/scripts/cocoapods/utils.rb index cb8d288fd020ce..dd395412af0fd0 100644 --- a/scripts/cocoapods/utils.rb +++ b/scripts/cocoapods/utils.rb @@ -119,6 +119,18 @@ def self.fix_react_bridging_header_search_paths(installer) end end + def self.apply_xcode_15_patch(installer) + installer.target_installation_results.pod_target_installation_results + .each do |pod_name, target_installation_result| + target_installation_result.native_target.build_configurations.each do |config| + # unary_function and binary_function are no longer provided in C++17 and newer standard modes as part of Xcode 15. They can be re-enabled with setting _LIBCPP_ENABLE_CXX17_REMOVED_UNARY_BINARY_FUNCTION + # Ref: https://developer.apple.com/documentation/xcode-release-notes/xcode-15-release-notes#Deprecations + config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] ||= '$(inherited) ' + config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] << '"_LIBCPP_ENABLE_CXX17_REMOVED_UNARY_BINARY_FUNCTION" ' + end + end + end + def self.apply_mac_catalyst_patches(installer) # Fix bundle signing issues installer.pods_project.targets.each do |target| diff --git a/scripts/react_native_pods.rb b/scripts/react_native_pods.rb index 1d789933966caa..d866464d312729 100644 --- a/scripts/react_native_pods.rb +++ b/scripts/react_native_pods.rb @@ -162,6 +162,7 @@ def react_native_post_install(installer, react_native_path = "../node_modules/re ReactNativePodsUtils.fix_library_search_paths(installer) ReactNativePodsUtils.fix_react_bridging_header_search_paths(installer) ReactNativePodsUtils.set_node_modules_user_settings(installer, react_native_path) + ReactNativePodsUtils.apply_xcode_15_patch(installer) NewArchitectureHelper.set_clang_cxx_language_standard_if_needed(installer) is_new_arch_enabled = ENV['RCT_NEW_ARCH_ENABLED'] == '1'