From 8119e6c7d4d9e52381f9af1c45e781abdc9077ac Mon Sep 17 00:00:00 2001 From: Christoph Purrer Date: Sat, 5 Nov 2022 00:52:43 -0700 Subject: [PATCH] TurboModules: Simplify React-bridging usage Summary: A previous change - https://github.com/facebook/react-native/pull/34011 - already fixed basic usage of For C++ TurboModules we need to be able to access *any* 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: 41d5e38d298695fe2084fd650b5cc8abc740217b --- ReactCommon/React-bridging.podspec | 43 ------------------ ReactCommon/ReactCommon.podspec | 11 ++++- scripts/cocoapods/__tests__/utils-test.rb | 54 ----------------------- scripts/cocoapods/codegen_utils.rb | 7 +-- scripts/cocoapods/new_architecture.rb | 1 + scripts/react_native_pods.rb | 1 - 6 files changed, 14 insertions(+), 103 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..9635bd0725546f 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 @@ -57,6 +56,14 @@ Pod::Spec.new do |s| sss.dependency "React-jsidynamic", version end + ss.subspec "bridging" do |sss| + sss.dependency "React-jsi", version + sss.source_files = "react/bridging/**/*.{m,mm,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 + s.subspec "react_debug_core" do |sss| sss.source_files = "react/debug/*.{cpp,h}" 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..b222aa1de5d634 100644 --- a/scripts/cocoapods/codegen_utils.rb +++ b/scripts/cocoapods/codegen_utils.rb @@ -98,14 +98,15 @@ 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/core": [version] + "ReactCommon/turbomodule/core": [version], + "ReactCommon/turbomodule/bridging": [version] } } diff --git a/scripts/cocoapods/new_architecture.rb b/scripts/cocoapods/new_architecture.rb index 5382b8fb2e5b80..f7610f575c7b0e 100644 --- a/scripts/cocoapods/new_architecture.rb +++ b/scripts/cocoapods/new_architecture.rb @@ -88,6 +88,7 @@ def self.install_modules_dependencies(spec, new_arch_enabled, folly_version) spec.dependency "RCTRequired" spec.dependency "RCTTypeSafety" spec.dependency "ReactCommon/turbomodule/core" + spec.dependency "ReactCommon/turbomodule/bridging" end end diff --git a/scripts/react_native_pods.rb b/scripts/react_native_pods.rb index 6d6df22fe35e6c..4989616305f958 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