Skip to content

Commit 8ed2cfd

Browse files
AlexanderEggerskelset
authored andcommitted
Add support for building with Xcode 15 (#37758)
Summary: Fixes #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: #37758 Reviewed By: cortinico Differential Revision: D46524009 Pulled By: cipolleschi fbshipit-source-id: 9f6c12e12a15c154467282a7b4a00e80e5cc0af2
1 parent 73f4a78 commit 8ed2cfd

File tree

3 files changed

+67
-0
lines changed

3 files changed

+67
-0
lines changed

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

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -434,6 +434,60 @@ def test_applyMacCatalystPatches_correctlyAppliesNecessaryPatches
434434
assert_equal(user_project_mock.save_invocation_count, 1)
435435
end
436436

437+
# ================================= #
438+
# Test - Apply Xcode 15 Patch #
439+
# ================================= #
440+
441+
def test_applyXcode15Patch_correctlyAppliesNecessaryPatch
442+
# Arrange
443+
first_target = prepare_target("FirstTarget")
444+
second_target = prepare_target("SecondTarget")
445+
third_target = TargetMock.new("ThirdTarget", [
446+
BuildConfigurationMock.new("Debug", {
447+
"GCC_PREPROCESSOR_DEFINITIONS" => '$(inherited) "SomeFlag=1" '
448+
}),
449+
BuildConfigurationMock.new("Release", {
450+
"GCC_PREPROCESSOR_DEFINITIONS" => '$(inherited) "SomeFlag=1" '
451+
}),
452+
], nil)
453+
454+
user_project_mock = UserProjectMock.new("a/path", [
455+
prepare_config("Debug"),
456+
prepare_config("Release"),
457+
],
458+
:native_targets => [
459+
first_target,
460+
second_target
461+
]
462+
)
463+
pods_projects_mock = PodsProjectMock.new([], {"hermes-engine" => {}}, :native_targets => [
464+
third_target
465+
])
466+
installer = InstallerMock.new(pods_projects_mock, [
467+
AggregatedProjectMock.new(user_project_mock)
468+
])
469+
470+
# Act
471+
ReactNativePodsUtils.apply_xcode_15_patch(installer)
472+
473+
# Assert
474+
first_target.build_configurations.each do |config|
475+
assert_equal(config.build_settings["GCC_PREPROCESSOR_DEFINITIONS"].strip,
476+
'$(inherited) "_LIBCPP_ENABLE_CXX17_REMOVED_UNARY_BINARY_FUNCTION"'
477+
)
478+
end
479+
second_target.build_configurations.each do |config|
480+
assert_equal(config.build_settings["GCC_PREPROCESSOR_DEFINITIONS"].strip,
481+
'$(inherited) "_LIBCPP_ENABLE_CXX17_REMOVED_UNARY_BINARY_FUNCTION"'
482+
)
483+
end
484+
third_target.build_configurations.each do |config|
485+
assert_equal(config.build_settings["GCC_PREPROCESSOR_DEFINITIONS"].strip,
486+
'$(inherited) "SomeFlag=1" "_LIBCPP_ENABLE_CXX17_REMOVED_UNARY_BINARY_FUNCTION"'
487+
)
488+
end
489+
end
490+
437491
# ==================================== #
438492
# Test - Set Node_Modules User Setting #
439493
# ==================================== #

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,18 @@ def self.apply_mac_catalyst_patches(installer)
121121
end
122122
end
123123

124+
def self.apply_xcode_15_patch(installer)
125+
installer.target_installation_results.pod_target_installation_results
126+
.each do |pod_name, target_installation_result|
127+
target_installation_result.native_target.build_configurations.each do |config|
128+
# 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
129+
# Ref: https://developer.apple.com/documentation/xcode-release-notes/xcode-15-release-notes#Deprecations
130+
config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] ||= '$(inherited) '
131+
config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] << '"_LIBCPP_ENABLE_CXX17_REMOVED_UNARY_BINARY_FUNCTION" '
132+
end
133+
end
134+
end
135+
124136
def self.apply_flags_for_fabric(installer, fabric_enabled: false)
125137
fabric_flag = "-DRN_FABRIC_ENABLED"
126138
if fabric_enabled

packages/react-native/scripts/react_native_pods.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,7 @@ def react_native_post_install(
244244
ReactNativePodsUtils.update_search_paths(installer)
245245
ReactNativePodsUtils.set_node_modules_user_settings(installer, react_native_path)
246246
ReactNativePodsUtils.apply_flags_for_fabric(installer, fabric_enabled: fabric_enabled)
247+
ReactNativePodsUtils.apply_xcode_15_patch(installer)
247248

248249
NewArchitectureHelper.set_clang_cxx_language_standard_if_needed(installer)
249250
is_new_arch_enabled = ENV['RCT_NEW_ARCH_ENABLED'] == "1"

0 commit comments

Comments
 (0)