From 8ed2cfded51d47731686c1060915bee7dd63647e Mon Sep 17 00:00:00 2001 From: Alexander Eggers Date: Thu, 8 Jun 2023 03:06:31 -0700 Subject: [PATCH] Add support for building with Xcode 15 (#37758) Summary: Fixes https://github.com/facebook/react-native/issues/37748 This PR adds a patch which fixes a build issue in Xcode 15. ## Changelog: [IOS] [ADDED] - Add support for building with Xcode 15 Pull Request resolved: https://github.com/facebook/react-native/pull/37758 Reviewed By: cortinico Differential Revision: D46524009 Pulled By: cipolleschi fbshipit-source-id: 9f6c12e12a15c154467282a7b4a00e80e5cc0af2 --- .../scripts/cocoapods/__tests__/utils-test.rb | 54 +++++++++++++++++++ .../react-native/scripts/cocoapods/utils.rb | 12 +++++ .../react-native/scripts/react_native_pods.rb | 1 + 3 files changed, 67 insertions(+) diff --git a/packages/react-native/scripts/cocoapods/__tests__/utils-test.rb b/packages/react-native/scripts/cocoapods/__tests__/utils-test.rb index 843b58336fb6e7..5a1c98e6bc6f5d 100644 --- a/packages/react-native/scripts/cocoapods/__tests__/utils-test.rb +++ b/packages/react-native/scripts/cocoapods/__tests__/utils-test.rb @@ -434,6 +434,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/packages/react-native/scripts/cocoapods/utils.rb b/packages/react-native/scripts/cocoapods/utils.rb index 79c216f74ed754..44b2579e49a483 100644 --- a/packages/react-native/scripts/cocoapods/utils.rb +++ b/packages/react-native/scripts/cocoapods/utils.rb @@ -121,6 +121,18 @@ def self.apply_mac_catalyst_patches(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_flags_for_fabric(installer, fabric_enabled: false) fabric_flag = "-DRN_FABRIC_ENABLED" if fabric_enabled diff --git a/packages/react-native/scripts/react_native_pods.rb b/packages/react-native/scripts/react_native_pods.rb index 6f1c24143ca78c..653385ed12eaeb 100644 --- a/packages/react-native/scripts/react_native_pods.rb +++ b/packages/react-native/scripts/react_native_pods.rb @@ -244,6 +244,7 @@ def react_native_post_install( ReactNativePodsUtils.update_search_paths(installer) ReactNativePodsUtils.set_node_modules_user_settings(installer, react_native_path) ReactNativePodsUtils.apply_flags_for_fabric(installer, fabric_enabled: fabric_enabled) + 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"