From f5fed4d42e661164a7e057db9298515fdad29b81 Mon Sep 17 00:00:00 2001 From: Christoph Purrer Date: Mon, 7 Nov 2022 02:16:10 -0800 Subject: [PATCH] TurboModules: Simplify React-bridging usage (#35212) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/35212 A previous change - https://github.com/facebook/react-native/pull/34011 - already fixed basic usage of Any other header besides from header via the React-Codegen CocoaPod. Hence adding bridging now as a sub-spec to the ReactCommon CocoaPod Changelog: [Internal] Differential Revision: D41057878 fbshipit-source-id: 9125933c3590ac26ea51c66c5fd8d1a215e9f0d8 --- ReactCommon/React-bridging.podspec | 43 --------------- ReactCommon/ReactCommon.podspec | 11 +++- .../cocoapods/__tests__/codegen_utils-test.rb | 1 + .../__tests__/new_architecture-test.rb | 1 + scripts/cocoapods/__tests__/utils-test.rb | 54 ------------------- scripts/cocoapods/codegen_utils.rb | 5 +- scripts/cocoapods/new_architecture.rb | 1 + scripts/cocoapods/utils.rb | 12 ----- scripts/react_native_pods.rb | 2 - 9 files changed, 15 insertions(+), 115 deletions(-) delete mode 100644 ReactCommon/React-bridging.podspec diff --git a/ReactCommon/React-bridging.podspec b/ReactCommon/React-bridging.podspec deleted file mode 100644 index 660d0efdd9deb5..00000000000000 --- a/ReactCommon/React-bridging.podspec +++ /dev/null @@ -1,43 +0,0 @@ -# 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. - -require "json" - -package = JSON.parse(File.read(File.join(__dir__, "..", "package.json"))) -version = package['version'] - -source = { :git => 'https://github.com/facebook/react-native.git' } -if version == '1000.0.0' - # This is an unpublished version, use the latest commit hash of the react-native repo, which we’re presumably in. - source[:commit] = `git rev-parse HEAD`.strip if system("git rev-parse --git-dir > /dev/null 2>&1") -else - source[:tag] = "v#{version}" -end - -folly_compiler_flags = '-DFOLLY_NO_CONFIG -DFOLLY_MOBILE=1 -DFOLLY_USE_LIBCPP=1 -Wno-comma -Wno-shorten-64-to-32 -Wno-gnu-zero-variadic-macro-arguments' -folly_version = '2021.07.22.00' - -Pod::Spec.new do |s| - s.name = "React-bridging" - s.version = version - s.summary = "-" # TODO - s.homepage = "https://reactnative.dev/" - s.license = package["license"] - s.author = "Facebook, Inc. and its affiliates" - s.platforms = { :ios => "12.4" } - s.source = source - s.source_files = "react/bridging/**/*.{cpp,h}" - s.exclude_files = "react/bridging/tests" - s.header_dir = "react/bridging" - s.header_mappings_dir = "." - s.compiler_flags = folly_compiler_flags - s.pod_target_xcconfig = { "HEADER_SEARCH_PATHS" => "\"$(PODS_ROOT)/RCT-Folly\"", - "USE_HEADERMAP" => "YES", - "CLANG_CXX_LANGUAGE_STANDARD" => "c++17", - "GCC_WARN_PEDANTIC" => "YES" } - - s.dependency "RCT-Folly", folly_version - s.dependency "React-jsi", version -end diff --git a/ReactCommon/ReactCommon.podspec b/ReactCommon/ReactCommon.podspec index 4cd4f04e59c31a..46af7c0411ba15 100644 --- a/ReactCommon/ReactCommon.podspec +++ b/ReactCommon/ReactCommon.podspec @@ -32,7 +32,7 @@ Pod::Spec.new do |s| s.source = source s.header_dir = "ReactCommon" # Use global header_dir for all subspecs for use_frameworks! compatibility s.compiler_flags = folly_compiler_flags + ' ' + boost_compiler_flags - s.pod_target_xcconfig = { "HEADER_SEARCH_PATHS" => "\"$(PODS_ROOT)/boost\" \"$(PODS_ROOT)/RCT-Folly\" \"$(PODS_ROOT)/DoubleConversion\" \"$(PODS_ROOT)/Headers/Private/React-Core\" \"$(PODS_ROOT)/Headers/Private/React-bridging/react/bridging\" \"$(PODS_CONFIGURATION_BUILD_DIR)/React-bridging/react_bridging.framework/Headers\"", + s.pod_target_xcconfig = { "HEADER_SEARCH_PATHS" => "\"$(PODS_ROOT)/boost\" \"$(PODS_ROOT)/RCT-Folly\" \"$(PODS_ROOT)/DoubleConversion\" \"$(PODS_ROOT)/Headers/Private/React-Core\"", "USE_HEADERMAP" => "YES", "CLANG_CXX_LANGUAGE_STANDARD" => "c++17", "GCC_WARN_PEDANTIC" => "YES" } @@ -40,7 +40,6 @@ Pod::Spec.new do |s| # TODO (T48588859): Restructure this target to align with dir structure: "react/nativemodule/..." # Note: Update this only when ready to minimize breaking changes. s.subspec "turbomodule" do |ss| - ss.dependency "React-bridging", version ss.dependency "React-callinvoker", version ss.dependency "React-perflogger", version ss.dependency "React-Core", version @@ -51,6 +50,14 @@ Pod::Spec.new do |s| ss.dependency "DoubleConversion" ss.dependency "glog" + ss.subspec "bridging" do |sss| + sss.dependency "React-jsi", version + sss.source_files = "react/bridging/**/*.{cpp,h}" + sss.exclude_files = "react/bridging/tests" + sss.header_dir = "react/bridging" + sss.pod_target_xcconfig = { "HEADER_SEARCH_PATHS" => "\"$(PODS_TARGET_SRCROOT)/ReactCommon\" \"$(PODS_ROOT)/RCT-Folly\"" } + end + ss.subspec "core" do |sss| sss.source_files = "react/nativemodule/core/ReactCommon/**/*.{cpp,h}", "react/nativemodule/core/platform/ios/**/*.{mm,cpp,h}" diff --git a/scripts/cocoapods/__tests__/codegen_utils-test.rb b/scripts/cocoapods/__tests__/codegen_utils-test.rb index 69a5f8c2dc0b35..989b7e87857788 100644 --- a/scripts/cocoapods/__tests__/codegen_utils-test.rb +++ b/scripts/cocoapods/__tests__/codegen_utils-test.rb @@ -466,6 +466,7 @@ def get_podspec_no_fabric_no_script "React-Core": ["99.98.97"], "React-jsi": ["99.98.97"], "hermes-engine": ["99.98.97"], + "ReactCommon/turbomodule/bridging": ["99.98.97"], "ReactCommon/turbomodule/core": ["99.98.97"] } } diff --git a/scripts/cocoapods/__tests__/new_architecture-test.rb b/scripts/cocoapods/__tests__/new_architecture-test.rb index 2f1c3cad1aa5ba..98ceecdc37a3a1 100644 --- a/scripts/cocoapods/__tests__/new_architecture-test.rb +++ b/scripts/cocoapods/__tests__/new_architecture-test.rb @@ -134,6 +134,7 @@ def test_installModulesDependencies_whenNewArchEnabledAndNewArchAndNoSearchPaths { :dependency_name => "React-Codegen" }, { :dependency_name => "RCTRequired" }, { :dependency_name => "RCTTypeSafety" }, + { :dependency_name => "ReactCommon/turbomodule/bridging" }, { :dependency_name => "ReactCommon/turbomodule/core" } ]) end diff --git a/scripts/cocoapods/__tests__/utils-test.rb b/scripts/cocoapods/__tests__/utils-test.rb index 76d316505ebe0e..429055cf4ca28b 100644 --- a/scripts/cocoapods/__tests__/utils-test.rb +++ b/scripts/cocoapods/__tests__/utils-test.rb @@ -328,60 +328,6 @@ def test_fixLibrarySearchPaths_correctlySetsTheSearchPathsForAllProjects assert_equal(pods_projects_mock.save_invocation_count, 1) end - # ============================================= # - # Test - Fix React-bridging Header Search Paths # - # ============================================= # - - def test_fixReactBridgingHeaderSearchPaths_correctlySetsTheHeaderSearchPathsForAllTargets - # Arrange - first_target = prepare_target("FirstTarget") - second_target = prepare_target("SecondTarget") - third_target = TargetMock.new("ThirdTarget", [ - BuildConfigurationMock.new("Debug", { - "HEADER_SEARCH_PATHS" => '$(inherited) "${PODS_ROOT}/Headers/Public" ' - }), - BuildConfigurationMock.new("Release", { - "HEADER_SEARCH_PATHS" => '$(inherited) "${PODS_ROOT}/Headers/Public" ' - }), - ], 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.fix_react_bridging_header_search_paths(installer) - - # Assert - first_target.build_configurations.each do |config| - assert_equal(config.build_settings["HEADER_SEARCH_PATHS"].strip, - '$(inherited) "$(PODS_ROOT)/Headers/Private/React-bridging/react/bridging" "$(PODS_CONFIGURATION_BUILD_DIR)/React-bridging/react_bridging.framework/Headers"' - ) - end - second_target.build_configurations.each do |config| - assert_equal(config.build_settings["HEADER_SEARCH_PATHS"].strip, - '$(inherited) "$(PODS_ROOT)/Headers/Private/React-bridging/react/bridging" "$(PODS_CONFIGURATION_BUILD_DIR)/React-bridging/react_bridging.framework/Headers"' - ) - end - third_target.build_configurations.each do |config| - assert_equal(config.build_settings["HEADER_SEARCH_PATHS"].strip, - '$(inherited) "${PODS_ROOT}/Headers/Public" "$(PODS_ROOT)/Headers/Private/React-bridging/react/bridging" "$(PODS_CONFIGURATION_BUILD_DIR)/React-bridging/react_bridging.framework/Headers"' - ) - end - end - # ===================================== # # Test - Apply Xcode14 React-Core patch # # ===================================== # diff --git a/scripts/cocoapods/codegen_utils.rb b/scripts/cocoapods/codegen_utils.rb index 608d9f210cfd4d..bd1c4648049eb9 100644 --- a/scripts/cocoapods/codegen_utils.rb +++ b/scripts/cocoapods/codegen_utils.rb @@ -98,13 +98,14 @@ def get_react_codegen_spec(package_json_file, folly_version: '2021.07.22.00', fa ].join(' ') }, 'dependencies': { - "FBReactNativeSpec": [version], - "React-jsiexecutor": [version], + "FBReactNativeSpec": [version], + "React-jsiexecutor": [version], "RCT-Folly": [folly_version], "RCTRequired": [version], "RCTTypeSafety": [version], "React-Core": [version], "React-jsi": [version], + "ReactCommon/turbomodule/bridging": [version], "ReactCommon/turbomodule/core": [version] } } diff --git a/scripts/cocoapods/new_architecture.rb b/scripts/cocoapods/new_architecture.rb index 5382b8fb2e5b80..0ce4b91f8b8f1f 100644 --- a/scripts/cocoapods/new_architecture.rb +++ b/scripts/cocoapods/new_architecture.rb @@ -87,6 +87,7 @@ def self.install_modules_dependencies(spec, new_arch_enabled, folly_version) spec.dependency "RCTRequired" spec.dependency "RCTTypeSafety" + spec.dependency "ReactCommon/turbomodule/bridging" spec.dependency "ReactCommon/turbomodule/core" end end diff --git a/scripts/cocoapods/utils.rb b/scripts/cocoapods/utils.rb index ffec05d27a79c1..dcf8642206498d 100644 --- a/scripts/cocoapods/utils.rb +++ b/scripts/cocoapods/utils.rb @@ -107,18 +107,6 @@ def self.fix_library_search_paths(installer) end end - def self.fix_react_bridging_header_search_paths(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| - # For third party modules who have React-bridging dependency to search correct headers - config.build_settings['HEADER_SEARCH_PATHS'] ||= '$(inherited) ' - config.build_settings['HEADER_SEARCH_PATHS'] << '"$(PODS_ROOT)/Headers/Private/React-bridging/react/bridging" ' - config.build_settings['HEADER_SEARCH_PATHS'] << '"$(PODS_CONFIGURATION_BUILD_DIR)/React-bridging/react_bridging.framework/Headers" ' - 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 0a64c7b221e3e6..074965bfbd63a6 100644 --- a/scripts/react_native_pods.rb +++ b/scripts/react_native_pods.rb @@ -93,7 +93,6 @@ def use_react_native! ( pod 'React-RCTVibration', :path => "#{prefix}/Libraries/Vibration" pod 'React-Core/RCTWebSocket', :path => "#{prefix}/" - pod 'React-bridging', :path => "#{prefix}/ReactCommon" pod 'React-cxxreact', :path => "#{prefix}/ReactCommon/cxxreact" if hermes_enabled @@ -212,7 +211,6 @@ def react_native_post_install(installer, react_native_path = "../node_modules/re ReactNativePodsUtils.exclude_i386_architecture_while_using_hermes(installer) ReactNativePodsUtils.fix_library_search_paths(installer) - ReactNativePodsUtils.fix_react_bridging_header_search_paths(installer) ReactNativePodsUtils.set_node_modules_user_settings(installer, react_native_path) NewArchitectureHelper.set_clang_cxx_language_standard_if_needed(installer)