From ace690aba9cd4cc73932f404a03ef36af0de53e7 Mon Sep 17 00:00:00 2001 From: Riccardo Cipolleschi Date: Thu, 7 Nov 2024 04:08:58 -0800 Subject: [PATCH] Generate RN specific Files in RN (#47458) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/47458 We are in a weird situation where React Native depends on some files that are generated by Codegen. Codegen runs in the user project, so those dependencies are not available to React Native if we try to build it in isolation. This is a problem and a blocker to prepare the prebuilds for iOS. This image show the changes we are introducing: On the right we have the current situation. On the left the new one. {F1954418630} ## Changelog: [Internal] - Generate React Native specific code inside React Native Reviewed By: cortinico, blakef Differential Revision: D65541505 fbshipit-source-id: 1412d7f23c4d2230b795af41f1e832c8a70d5859 --- .gitignore | 2 +- .../AppDelegate/React-RCTAppDelegate.podspec | 2 +- .../Libraries/Blob/React-RCTBlob.podspec | 2 +- .../Libraries/Image/React-RCTImage.podspec | 2 +- .../LinkingIOS/React-RCTLinking.podspec | 2 +- .../React-RCTAnimation.podspec | 2 +- .../Network/React-RCTNetwork.podspec | 2 +- .../React-RCTPushNotification.podspec | 2 +- .../Settings/React-RCTSettings.podspec | 2 +- .../Vibration/React-RCTVibration.podspec | 2 +- .../CoreModules/React-CoreModules.podspec | 2 +- .../React/React-RCTFBReactNativeSpec.podspec | 84 +++++++++++++++++++ .../React-FabricComponents.podspec | 2 +- .../ReactCommon/jsi/React-jsi.podspec | 7 +- .../React-defaultsnativemodule.podspec | 20 ++++- .../dom/React-domnativemodule.podspec | 24 +++++- .../React-featureflagsnativemodule.podspec | 22 ++++- .../React-idlecallbacksnativemodule.podspec | 21 ++++- .../React-microtasksnativemodule.podspec | 21 ++++- .../samples/ReactCommon-Samples.podspec | 4 +- .../platform/ios/React-RuntimeApple.podspec | 2 +- .../codegen/generate-artifacts-executor.js | 62 ++++++++++++-- packages/react-native/scripts/prepack.js | 2 + .../react-native/scripts/react_native_pods.rb | 1 + 24 files changed, 255 insertions(+), 39 deletions(-) create mode 100644 packages/react-native/React/React-RCTFBReactNativeSpec.podspec diff --git a/.gitignore b/.gitignore index e734a3cffbb..b26247390fb 100644 --- a/.gitignore +++ b/.gitignore @@ -124,7 +124,7 @@ vendor/ !/packages/rn-tester/Pods/__offline_mirrors_jsc__ # @react-native/codegen -/packages/react-native/React/FBReactNativeSpec/FBReactNativeSpec +/packages/react-native/React/FBReactNativeSpec/ /packages/react-native-codegen/lib /packages/react-native-codegen/tmp/ /packages/react-native/ReactCommon/react/renderer/components/rncore/ diff --git a/packages/react-native/Libraries/AppDelegate/React-RCTAppDelegate.podspec b/packages/react-native/Libraries/AppDelegate/React-RCTAppDelegate.podspec index b54f1e41af5..edaf73d1f06 100644 --- a/packages/react-native/Libraries/AppDelegate/React-RCTAppDelegate.podspec +++ b/packages/react-native/Libraries/AppDelegate/React-RCTAppDelegate.podspec @@ -74,7 +74,7 @@ Pod::Spec.new do |s| s.dependency "React-RCTImage" s.dependency "React-CoreModules" s.dependency "React-nativeconfig" - s.dependency "ReactCodegen" + s.dependency "React-RCTFBReactNativeSpec" s.dependency "React-defaultsnativemodule" add_dependency(s, "ReactCommon", :subspec => "turbomodule/core", :additional_framework_paths => ["react/nativemodule/core"]) diff --git a/packages/react-native/Libraries/Blob/React-RCTBlob.podspec b/packages/react-native/Libraries/Blob/React-RCTBlob.podspec index c592234ed13..9d758c174cf 100644 --- a/packages/react-native/Libraries/Blob/React-RCTBlob.podspec +++ b/packages/react-native/Libraries/Blob/React-RCTBlob.podspec @@ -57,7 +57,7 @@ Pod::Spec.new do |s| s.dependency "React-Core/RCTWebSocket" s.dependency "React-RCTNetwork" - add_dependency(s, "ReactCodegen") + add_dependency(s, "React-RCTFBReactNativeSpec") add_dependency(s, "React-NativeModulesApple") add_dependency(s, "React-jsinspector", :framework_name => 'jsinspector_modern') add_dependency(s, "ReactCommon", :subspec => "turbomodule/core", :additional_framework_paths => ["react/nativemodule/core"]) diff --git a/packages/react-native/Libraries/Image/React-RCTImage.podspec b/packages/react-native/Libraries/Image/React-RCTImage.podspec index f0a56a7d67d..5e9d333701a 100644 --- a/packages/react-native/Libraries/Image/React-RCTImage.podspec +++ b/packages/react-native/Libraries/Image/React-RCTImage.podspec @@ -53,7 +53,7 @@ Pod::Spec.new do |s| s.dependency "React-Core/RCTImageHeaders" s.dependency "React-RCTNetwork" - add_dependency(s, "ReactCodegen") + add_dependency(s, "React-RCTFBReactNativeSpec") add_dependency(s, "ReactCommon", :subspec => "turbomodule/core", :additional_framework_paths => ["react/nativemodule/core"]) add_dependency(s, "React-NativeModulesApple") diff --git a/packages/react-native/Libraries/LinkingIOS/React-RCTLinking.podspec b/packages/react-native/Libraries/LinkingIOS/React-RCTLinking.podspec index 2988120a174..c2120fd2d4a 100644 --- a/packages/react-native/Libraries/LinkingIOS/React-RCTLinking.podspec +++ b/packages/react-native/Libraries/LinkingIOS/React-RCTLinking.podspec @@ -50,7 +50,7 @@ Pod::Spec.new do |s| s.dependency "ReactCommon/turbomodule/core", version s.dependency "React-jsi", version - add_dependency(s, "ReactCodegen", :additional_framework_paths => ["build/generated/ios"]) + add_dependency(s, "React-RCTFBReactNativeSpec") add_dependency(s, "ReactCommon", :subspec => "turbomodule/core", :additional_framework_paths => ["react/nativemodule/core"]) add_dependency(s, "React-NativeModulesApple", :additional_framework_paths => ["build/generated/ios"]) end diff --git a/packages/react-native/Libraries/NativeAnimation/React-RCTAnimation.podspec b/packages/react-native/Libraries/NativeAnimation/React-RCTAnimation.podspec index 8a10d02f1fe..7143d45c72c 100644 --- a/packages/react-native/Libraries/NativeAnimation/React-RCTAnimation.podspec +++ b/packages/react-native/Libraries/NativeAnimation/React-RCTAnimation.podspec @@ -50,7 +50,7 @@ Pod::Spec.new do |s| s.dependency "React-jsi" s.dependency "React-Core/RCTAnimationHeaders" - add_dependency(s, "ReactCodegen", :additional_framework_paths => ["build/generated/ios"]) + add_dependency(s, "React-RCTFBReactNativeSpec") add_dependency(s, "ReactCommon", :subspec => "turbomodule/core", :additional_framework_paths => ["react/nativemodule/core"]) add_dependency(s, "React-NativeModulesApple") end diff --git a/packages/react-native/Libraries/Network/React-RCTNetwork.podspec b/packages/react-native/Libraries/Network/React-RCTNetwork.podspec index 3ad05bd8904..b3292864b2c 100644 --- a/packages/react-native/Libraries/Network/React-RCTNetwork.podspec +++ b/packages/react-native/Libraries/Network/React-RCTNetwork.podspec @@ -50,7 +50,7 @@ Pod::Spec.new do |s| s.dependency "React-jsi" s.dependency "React-Core/RCTNetworkHeaders" - add_dependency(s, "ReactCodegen", :additional_framework_paths => ["build/generated/ios"]) + add_dependency(s, "React-RCTFBReactNativeSpec") add_dependency(s, "ReactCommon", :subspec => "turbomodule/core", :additional_framework_paths => ["react/nativemodule/core"]) add_dependency(s, "React-NativeModulesApple", :additional_framework_paths => ["build/generated/ios"]) end diff --git a/packages/react-native/Libraries/PushNotificationIOS/React-RCTPushNotification.podspec b/packages/react-native/Libraries/PushNotificationIOS/React-RCTPushNotification.podspec index 899cbb03ffc..0ea9322132f 100644 --- a/packages/react-native/Libraries/PushNotificationIOS/React-RCTPushNotification.podspec +++ b/packages/react-native/Libraries/PushNotificationIOS/React-RCTPushNotification.podspec @@ -50,7 +50,7 @@ Pod::Spec.new do |s| s.dependency "React-Core/RCTPushNotificationHeaders" s.dependency "React-jsi" - add_dependency(s, "ReactCodegen", :additional_framework_paths => ["build/generated/ios"]) + add_dependency(s, "React-RCTFBReactNativeSpec") add_dependency(s, "ReactCommon", :subspec => "turbomodule/core", :additional_framework_paths => ["react/nativemodule/core"]) add_dependency(s, "React-NativeModulesApple") end diff --git a/packages/react-native/Libraries/Settings/React-RCTSettings.podspec b/packages/react-native/Libraries/Settings/React-RCTSettings.podspec index ff18fb036ef..b2a41b3d239 100644 --- a/packages/react-native/Libraries/Settings/React-RCTSettings.podspec +++ b/packages/react-native/Libraries/Settings/React-RCTSettings.podspec @@ -50,7 +50,7 @@ Pod::Spec.new do |s| s.dependency "React-jsi" s.dependency "React-Core/RCTSettingsHeaders" - add_dependency(s, "ReactCodegen", :additional_framework_paths => ["build/generated/ios"]) + add_dependency(s, "React-RCTFBReactNativeSpec") add_dependency(s, "ReactCommon", :subspec => "turbomodule/core", :additional_framework_paths => ["react/nativemodule/core"]) add_dependency(s, "React-NativeModulesApple", :additional_framework_paths => ["build/generated/ios"]) end diff --git a/packages/react-native/Libraries/Vibration/React-RCTVibration.podspec b/packages/react-native/Libraries/Vibration/React-RCTVibration.podspec index 9454476fd80..f54d4862c75 100644 --- a/packages/react-native/Libraries/Vibration/React-RCTVibration.podspec +++ b/packages/react-native/Libraries/Vibration/React-RCTVibration.podspec @@ -50,7 +50,7 @@ Pod::Spec.new do |s| s.dependency "React-jsi" s.dependency "React-Core/RCTVibrationHeaders" - add_dependency(s, "ReactCodegen", :additional_framework_paths => ["build/generated/ios"]) + add_dependency(s, "React-RCTFBReactNativeSpec") add_dependency(s, "ReactCommon", :subspec => "turbomodule/core", :additional_framework_paths => ["react/nativemodule/core"]) add_dependency(s, "React-NativeModulesApple") end diff --git a/packages/react-native/React/CoreModules/React-CoreModules.podspec b/packages/react-native/React/CoreModules/React-CoreModules.podspec index 43ef20bc2e9..d41b66c0f5a 100644 --- a/packages/react-native/React/CoreModules/React-CoreModules.podspec +++ b/packages/react-native/React/CoreModules/React-CoreModules.podspec @@ -71,7 +71,7 @@ Pod::Spec.new do |s| s.dependency "SocketRocket", socket_rocket_version add_dependency(s, "React-jsinspector", :framework_name => 'jsinspector_modern') - add_dependency(s, "ReactCodegen") + add_dependency(s, "React-RCTFBReactNativeSpec") add_dependency(s, "ReactCommon", :subspec => "turbomodule/core", :additional_framework_paths => ["react/nativemodule/core"]) add_dependency(s, "React-NativeModulesApple") end diff --git a/packages/react-native/React/React-RCTFBReactNativeSpec.podspec b/packages/react-native/React/React-RCTFBReactNativeSpec.podspec new file mode 100644 index 00000000000..84513f04a43 --- /dev/null +++ b/packages/react-native/React/React-RCTFBReactNativeSpec.podspec @@ -0,0 +1,84 @@ +# 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 + +module_name = "FBReactNativeSpec" +header_dir = "FBReactNativeSpec" + +folly_config = get_folly_config() +folly_compiler_flags = folly_config[:compiler_flags] +folly_version = folly_config[:version] +boost_config = get_boost_config() +boost_compiler_flags = boost_config[:compiler_flags] +new_arch_flags = ENV['RCT_NEW_ARCH_ENABLED'] == '1' ? ' -DRCT_NEW_ARCH_ENABLED=1' : '' + +header_search_paths = [ + "\"$(PODS_ROOT)/RCT-Folly\"", +] + +Pod::Spec.new do |s| + s.name = "React-RCTFBReactNativeSpec" + s.version = version + s.summary = "FBReactNativeSpec for React Native." + s.homepage = "https://reactnative.dev/" + s.license = package["license"] + s.author = "Meta Platforms, Inc. and its affiliates" + s.platforms = min_supported_versions + s.source = source + s.source_files = "FBReactNativeSpec/**/*.{c,h,m,mm,S,cpp}" + s.compiler_flags = folly_compiler_flags + ' ' + boost_compiler_flags + new_arch_flags + s.header_dir = header_dir + s.module_name = module_name + s.pod_target_xcconfig = { + "HEADER_SEARCH_PATHS" => header_search_paths, + "OTHER_CFLAGS" => "$(inherited) " + folly_compiler_flags + new_arch_flags, + "CLANG_CXX_LANGUAGE_STANDARD" => rct_cxx_language_standard() + } + + s.dependency "React-jsi" + s.dependency "React-jsiexecutor" + s.dependency "RCT-Folly" + s.dependency "RCTRequired" + s.dependency "RCTTypeSafety" + s.dependency "React-Core" + s.dependency "React-NativeModulesApple" + add_dependency(s, "ReactCommon", :subspec => "turbomodule/core", :additional_framework_paths => ["react/nativemodule/core"]) + add_dependency(s, "ReactCommon", :subspec => "turbomodule/bridging", :additional_framework_paths => ["react/nativemodule/bridging"]) + + if ENV["USE_HERMES"] == nil || ENV["USE_HERMES"] == "1" + s.dependency "hermes-engine" + else + s.dependency "React-jsc" + end + + + s.script_phases = [ + { + :name => '[RN]Check FBReactNativeSpec', + :execution_position => :before_compile, + :script => <<-EOS +echo "Checking whether Codegen has run..." +fbReactNativeSpecPath="$REACT_NATIVE_PATH/React/FBReactNativeSpec" + +if [[ ! -d "$fbReactNativeSpecPath" ]]; then + echo 'error: Codegen did not run properly in your project. Please reinstall cocoapods with `bundle exec pod install`.' + exit 1 +fi + EOS + } + ] +end diff --git a/packages/react-native/ReactCommon/React-FabricComponents.podspec b/packages/react-native/ReactCommon/React-FabricComponents.podspec index 0ee54032135..0d4e55a1475 100644 --- a/packages/react-native/ReactCommon/React-FabricComponents.podspec +++ b/packages/react-native/ReactCommon/React-FabricComponents.podspec @@ -92,7 +92,7 @@ Pod::Spec.new do |s| "react/renderer/components/view/platform/cxx", "react/renderer/imagemanager/platform/ios" ]) - add_dependency(s, "ReactCodegen", :additional_framework_paths => ["build/generated/ios"]) + # add_dependency(s, "React-RCTFBReactNativeSpec") if ENV["USE_HERMES"] == nil || ENV["USE_HERMES"] == "1" s.dependency "hermes-engine" diff --git a/packages/react-native/ReactCommon/jsi/React-jsi.podspec b/packages/react-native/ReactCommon/jsi/React-jsi.podspec index 9425d6761f4..fb3cbe9556f 100644 --- a/packages/react-native/ReactCommon/jsi/React-jsi.podspec +++ b/packages/react-native/ReactCommon/jsi/React-jsi.podspec @@ -38,8 +38,11 @@ Pod::Spec.new do |s| s.header_dir = "jsi" 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)/fast_float/include\" \"$(PODS_ROOT)/fmt/include\"", - "DEFINES_MODULE" => "YES" } + s.pod_target_xcconfig = { + "HEADER_SEARCH_PATHS" => "\"$(PODS_ROOT)/boost\" \"$(PODS_ROOT)/RCT-Folly\" \"$(PODS_ROOT)/DoubleConversion\" \"$(PODS_ROOT)/fast_float/include\" \"$(PODS_ROOT)/fmt/include\"", + "CLANG_CXX_LANGUAGE_STANDARD" => rct_cxx_language_standard(), + "DEFINES_MODULE" => "YES" + } s.dependency "boost" s.dependency "DoubleConversion" diff --git a/packages/react-native/ReactCommon/react/nativemodule/defaults/React-defaultsnativemodule.podspec b/packages/react-native/ReactCommon/react/nativemodule/defaults/React-defaultsnativemodule.podspec index 77cc249c1bf..ec20ddc21f0 100644 --- a/packages/react-native/ReactCommon/react/nativemodule/defaults/React-defaultsnativemodule.podspec +++ b/packages/react-native/ReactCommon/react/nativemodule/defaults/React-defaultsnativemodule.podspec @@ -16,7 +16,13 @@ else source[:tag] = "v#{version}" end -header_search_paths = [] +header_search_paths = [ + "\"$(PODS_ROOT)/RCT-Folly\"", +] + +folly_config = get_folly_config() +folly_compiler_flags = folly_config[:compiler_flags] +folly_version = folly_config[:version] if ENV['USE_FRAMEWORKS'] header_search_paths << "\"$(PODS_TARGET_SRCROOT)/../../..\"" # this is needed to allow the defaultsnativemodule to access its own files @@ -31,10 +37,12 @@ Pod::Spec.new do |s| s.author = "Meta Platforms, Inc. and its affiliates" s.platforms = min_supported_versions s.source = source + s.compiler_flags = folly_compiler_flags s.source_files = "*.{cpp,h}" s.header_dir = "react/nativemodule/defaults" s.pod_target_xcconfig = { "CLANG_CXX_LANGUAGE_STANDARD" => rct_cxx_language_standard(), "HEADER_SEARCH_PATHS" => header_search_paths.join(' '), + "OTHER_CFLAGS" => "$(inherited) " + folly_compiler_flags, "DEFINES_MODULE" => "YES" } if ENV['USE_FRAMEWORKS'] @@ -42,10 +50,18 @@ Pod::Spec.new do |s| s.header_mappings_dir = "../.." end - install_modules_dependencies(s) + s.dependency "RCT-Folly" + s.dependency "React-jsi" + s.dependency "React-jsiexecutor" + if ENV["USE_HERMES"] == nil || ENV["USE_HERMES"] == "1" + s.dependency "hermes-engine" + else + s.dependency "React-jsc" + end s.dependency "React-domnativemodule" s.dependency "React-featureflagsnativemodule" s.dependency "React-microtasksnativemodule" s.dependency "React-idlecallbacksnativemodule" + add_dependency(s, "React-RCTFBReactNativeSpec") end diff --git a/packages/react-native/ReactCommon/react/nativemodule/dom/React-domnativemodule.podspec b/packages/react-native/ReactCommon/react/nativemodule/dom/React-domnativemodule.podspec index 03b8f843d01..21a02fdc096 100644 --- a/packages/react-native/ReactCommon/react/nativemodule/dom/React-domnativemodule.podspec +++ b/packages/react-native/ReactCommon/react/nativemodule/dom/React-domnativemodule.podspec @@ -16,7 +16,14 @@ else source[:tag] = "v#{version}" end -header_search_paths = [] +header_search_paths = [ + "\"$(PODS_ROOT)/RCT-Folly\"", + "\"$(PODS_ROOT)/Headers/Private/Yoga\"", +] + +folly_config = get_folly_config() +folly_compiler_flags = folly_config[:compiler_flags] +folly_version = folly_config[:version] if ENV['USE_FRAMEWORKS'] header_search_paths << "\"$(PODS_TARGET_SRCROOT)/../../..\"" # this is needed to allow the domnativemodule to access its own files @@ -31,10 +38,12 @@ Pod::Spec.new do |s| s.author = "Meta Platforms, Inc. and its affiliates" s.platforms = min_supported_versions s.source = source + s.compiler_flags = folly_compiler_flags s.source_files = "*.{cpp,h}" s.header_dir = "react/nativemodule/dom" s.pod_target_xcconfig = { "CLANG_CXX_LANGUAGE_STANDARD" => rct_cxx_language_standard(), "HEADER_SEARCH_PATHS" => header_search_paths.join(' '), + "OTHER_CFLAGS" => "$(inherited) " + folly_compiler_flags, "DEFINES_MODULE" => "YES" } if ENV['USE_FRAMEWORKS'] @@ -42,9 +51,18 @@ Pod::Spec.new do |s| s.header_mappings_dir = "../.." end - install_modules_dependencies(s) - + s.dependency "RCT-Folly" + s.dependency "React-jsi" + s.dependency "React-jsiexecutor" + if ENV["USE_HERMES"] == nil || ENV["USE_HERMES"] == "1" + s.dependency "hermes-engine" + else + s.dependency "React-jsc" + end + s.dependency "Yoga" s.dependency "ReactCommon/turbomodule/core" s.dependency "React-Fabric" s.dependency "React-FabricComponents" + add_dependency(s, "React-graphics", :additional_framework_paths => ["react/renderer/graphics/platform/ios"]) + add_dependency(s, "React-RCTFBReactNativeSpec") end diff --git a/packages/react-native/ReactCommon/react/nativemodule/featureflags/React-featureflagsnativemodule.podspec b/packages/react-native/ReactCommon/react/nativemodule/featureflags/React-featureflagsnativemodule.podspec index 6e87da441ef..272b06566e1 100644 --- a/packages/react-native/ReactCommon/react/nativemodule/featureflags/React-featureflagsnativemodule.podspec +++ b/packages/react-native/ReactCommon/react/nativemodule/featureflags/React-featureflagsnativemodule.podspec @@ -16,7 +16,13 @@ else source[:tag] = "v#{version}" end -header_search_paths = [] +header_search_paths = [ + "\"$(PODS_ROOT)/RCT-Folly\"", +] + +folly_config = get_folly_config() +folly_compiler_flags = folly_config[:compiler_flags] +folly_version = folly_config[:version] if ENV['USE_FRAMEWORKS'] header_search_paths << "\"$(PODS_TARGET_SRCROOT)/../../..\"" # this is needed to allow the feature flags access its own files @@ -31,10 +37,12 @@ Pod::Spec.new do |s| s.author = "Meta Platforms, Inc. and its affiliates" s.platforms = min_supported_versions s.source = source + s.compiler_flags = folly_compiler_flags s.source_files = "*.{cpp,h}" s.header_dir = "react/nativemodule/featureflags" s.pod_target_xcconfig = { "CLANG_CXX_LANGUAGE_STANDARD" => rct_cxx_language_standard(), "HEADER_SEARCH_PATHS" => header_search_paths.join(' '), + "OTHER_CFLAGS" => "$(inherited) " + folly_compiler_flags, "DEFINES_MODULE" => "YES" } if ENV['USE_FRAMEWORKS'] @@ -42,7 +50,15 @@ Pod::Spec.new do |s| s.header_mappings_dir = "../.." end - install_modules_dependencies(s) - + s.dependency "RCT-Folly" + s.dependency "React-jsi" + s.dependency "React-jsiexecutor" + if ENV["USE_HERMES"] == nil || ENV["USE_HERMES"] == "1" + s.dependency "hermes-engine" + else + s.dependency "React-jsc" + end s.dependency "ReactCommon/turbomodule/core" + s.dependency "React-RCTFBReactNativeSpec" + s.dependency "React-featureflags" end diff --git a/packages/react-native/ReactCommon/react/nativemodule/idlecallbacks/React-idlecallbacksnativemodule.podspec b/packages/react-native/ReactCommon/react/nativemodule/idlecallbacks/React-idlecallbacksnativemodule.podspec index e29f942205b..c526a7f290b 100644 --- a/packages/react-native/ReactCommon/react/nativemodule/idlecallbacks/React-idlecallbacksnativemodule.podspec +++ b/packages/react-native/ReactCommon/react/nativemodule/idlecallbacks/React-idlecallbacksnativemodule.podspec @@ -16,7 +16,13 @@ else source[:tag] = "v#{version}" end -header_search_paths = [] +header_search_paths = [ + "\"$(PODS_ROOT)/RCT-Folly\"", +] + +folly_config = get_folly_config() +folly_compiler_flags = folly_config[:compiler_flags] +folly_version = folly_config[:version] if ENV['USE_FRAMEWORKS'] header_search_paths << "\"$(PODS_TARGET_SRCROOT)/../../..\"" # this is needed to allow the module access its own files @@ -31,10 +37,12 @@ Pod::Spec.new do |s| s.author = "Meta Platforms, Inc. and its affiliates" s.platforms = min_supported_versions s.source = source + s.compiler_flags = folly_compiler_flags s.source_files = "*.{cpp,h}" s.header_dir = "react/nativemodule/idlecallbacks" s.pod_target_xcconfig = { "CLANG_CXX_LANGUAGE_STANDARD" => rct_cxx_language_standard(), "HEADER_SEARCH_PATHS" => header_search_paths.join(' '), + "OTHER_CFLAGS" => "$(inherited) " + folly_compiler_flags, "DEFINES_MODULE" => "YES" } if ENV['USE_FRAMEWORKS'] @@ -42,8 +50,15 @@ Pod::Spec.new do |s| s.header_mappings_dir = "../.." end - install_modules_dependencies(s) - + s.dependency "RCT-Folly" + s.dependency "React-jsi" + s.dependency "React-jsiexecutor" + if ENV["USE_HERMES"] == nil || ENV["USE_HERMES"] == "1" + s.dependency "hermes-engine" + else + s.dependency "React-jsc" + end s.dependency "ReactCommon/turbomodule/core" s.dependency "React-runtimescheduler" + add_dependency(s, "React-RCTFBReactNativeSpec") end diff --git a/packages/react-native/ReactCommon/react/nativemodule/microtasks/React-microtasksnativemodule.podspec b/packages/react-native/ReactCommon/react/nativemodule/microtasks/React-microtasksnativemodule.podspec index 20d26d847b9..e490082e17b 100644 --- a/packages/react-native/ReactCommon/react/nativemodule/microtasks/React-microtasksnativemodule.podspec +++ b/packages/react-native/ReactCommon/react/nativemodule/microtasks/React-microtasksnativemodule.podspec @@ -16,7 +16,13 @@ else source[:tag] = "v#{version}" end -header_search_paths = [] +header_search_paths = [ + "\"$(PODS_ROOT)/RCT-Folly\"", +] + +folly_config = get_folly_config() +folly_compiler_flags = folly_config[:compiler_flags] +folly_version = folly_config[:version] if ENV['USE_FRAMEWORKS'] header_search_paths << "\"$(PODS_TARGET_SRCROOT)/../../..\"" # this is needed to allow the microtasks module access its own files @@ -31,9 +37,11 @@ Pod::Spec.new do |s| s.author = "Meta Platforms, Inc. and its affiliates" s.platforms = min_supported_versions s.source = source + s.compiler_flags = folly_compiler_flags s.source_files = "*.{cpp,h}" s.header_dir = "react/nativemodule/microtasks" s.pod_target_xcconfig = { "CLANG_CXX_LANGUAGE_STANDARD" => rct_cxx_language_standard(), + "OTHER_CFLAGS" => "$(inherited) " + folly_compiler_flags, "HEADER_SEARCH_PATHS" => header_search_paths.join(' '), "DEFINES_MODULE" => "YES" } @@ -42,7 +50,14 @@ Pod::Spec.new do |s| s.header_mappings_dir = "../.." end - install_modules_dependencies(s) - + s.dependency "RCT-Folly" + s.dependency "React-jsi" + s.dependency "React-jsiexecutor" + if ENV["USE_HERMES"] == nil || ENV["USE_HERMES"] == "1" + s.dependency "hermes-engine" + else + s.dependency "React-jsc" + end s.dependency "ReactCommon/turbomodule/core" + add_dependency(s, "React-RCTFBReactNativeSpec") end diff --git a/packages/react-native/ReactCommon/react/nativemodule/samples/ReactCommon-Samples.podspec b/packages/react-native/ReactCommon/react/nativemodule/samples/ReactCommon-Samples.podspec index b6155cbb19d..5c35ba1eab3 100644 --- a/packages/react-native/ReactCommon/react/nativemodule/samples/ReactCommon-Samples.podspec +++ b/packages/react-native/ReactCommon/react/nativemodule/samples/ReactCommon-Samples.podspec @@ -69,9 +69,9 @@ Pod::Spec.new do |s| s.dependency "React-Core" s.dependency "React-cxxreact" s.dependency "React-jsi" - add_dependency(s, "ReactCodegen", :additional_framework_paths => ["build/generated/ios"]) + add_dependency(s, "React-RCTFBReactNativeSpec") add_dependency(s, "ReactCommon", :subspec => "turbomodule/core", :additional_framework_paths => ["react/nativemodule/core"]) - add_dependency(s, "React-NativeModulesApple", :additional_framework_paths => ["build/generated/ios"]) + add_dependency(s, "React-NativeModulesApple") if using_hermes s.dependency "hermes-engine" diff --git a/packages/react-native/ReactCommon/react/runtime/platform/ios/React-RuntimeApple.podspec b/packages/react-native/ReactCommon/react/runtime/platform/ios/React-RuntimeApple.podspec index ed57c3c9a9a..7bf217816fa 100644 --- a/packages/react-native/ReactCommon/react/runtime/platform/ios/React-RuntimeApple.podspec +++ b/packages/react-native/ReactCommon/react/runtime/platform/ios/React-RuntimeApple.podspec @@ -71,7 +71,7 @@ Pod::Spec.new do |s| s.dependency "React-jsinspector" s.dependency "React-featureflags" - add_dependency(s, "ReactCodegen") + add_dependency(s, "React-RCTFBReactNativeSpec") if ENV["USE_HERMES"] == nil || ENV["USE_HERMES"] == "1" s.dependency "hermes-engine" diff --git a/packages/react-native/scripts/codegen/generate-artifacts-executor.js b/packages/react-native/scripts/codegen/generate-artifacts-executor.js index d9af18b0806..f50288816f3 100644 --- a/packages/react-native/scripts/codegen/generate-artifacts-executor.js +++ b/packages/react-native/scripts/codegen/generate-artifacts-executor.js @@ -47,7 +47,11 @@ const RNCORE_CONFIGS = { const CORE_LIBRARIES_WITH_OUTPUT_FOLDER = { rncore: RNCORE_CONFIGS, FBReactNativeSpec: { - ios: null, + ios: path.join( + REACT_NATIVE_PACKAGE_ROOT_FOLDER, + 'React', + 'FBReactNativeSpec', + ), android: path.join( REACT_NATIVE_PACKAGE_ROOT_FOLDER, 'ReactAndroid', @@ -451,13 +455,7 @@ function shouldSkipGenerationForRncore(schemaInfo, platform) { if (platform !== 'ios' || schemaInfo.library.config.name !== 'rncore') { return false; } - const rncoreOutputPath = path.join( - RNCORE_CONFIGS.ios, - 'react', - 'renderer', - 'components', - 'rncore', - ); + const rncoreOutputPath = CORE_LIBRARIES_WITH_OUTPUT_FOLDER.rncore.ios; const rncoreAbsolutePath = path.resolve(rncoreOutputPath); return ( rncoreAbsolutePath.includes('node_modules') && @@ -466,6 +464,26 @@ function shouldSkipGenerationForRncore(schemaInfo, platform) { ); } +function shouldSkipGenerationForFBReactNativeSpec(schemaInfo, platform) { + if ( + platform !== 'ios' || + schemaInfo.library.config.name !== 'FBReactNativeSpec' + ) { + return false; + } + + const fbReactNativeSpecOutputPath = + CORE_LIBRARIES_WITH_OUTPUT_FOLDER.FBReactNativeSpec.ios; + const fbReactNativeSpecAbsolutePath = path.resolve( + fbReactNativeSpecOutputPath, + ); + return ( + fbReactNativeSpecAbsolutePath.includes('node_modules') && + fs.existsSync(fbReactNativeSpecAbsolutePath) && + fs.readdirSync(fbReactNativeSpecAbsolutePath).length > 0 + ); +} + function generateCode(outputPath, schemaInfo, includesGeneratedCode, platform) { if (shouldSkipGenerationForRncore(schemaInfo, platform)) { codegenLog( @@ -475,6 +493,14 @@ function generateCode(outputPath, schemaInfo, includesGeneratedCode, platform) { return; } + if (shouldSkipGenerationForFBReactNativeSpec(schemaInfo, platform)) { + codegenLog( + '[Codegen - FBReactNativeSpec] Skipping iOS code generation for FBReactNativeSpec as it has been generated already.', + true, + ); + return; + } + const libraryName = schemaInfo.library.config.name; const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), libraryName)); const tmpOutputDir = path.join(tmpDir, 'out'); @@ -615,6 +641,8 @@ function generateCustomURLHandlers(libraries, outputDir) { .replace(/{imageDataDecoderClassNames}/, customImageDataDecoderClasses) .replace(/{requestHandlersClassNames}/, customURLHandlerClasses); + fs.mkdirSync(outputDir, {recursive: true}); + fs.writeFileSync( path.join(outputDir, 'RCTModulesConformingToProtocolsProvider.mm'), finalMMFile, @@ -676,6 +704,23 @@ function generateRNCoreComponentsIOS(projectRoot /*: string */) /*: void*/ { generateCode('', rncoreSchemaInfo, false, ios); } +function generateFBReactNativeSpecIOS(projectRoot /*: string */) /*: void*/ { + const ios = 'ios'; + buildCodegenIfNeeded(); + const pkgJson = readPkgJsonInDirectory(projectRoot); + const fbReactNativeSpecLib = findProjectRootLibraries( + pkgJson, + projectRoot, + ).filter(library => library.config.name === 'FBReactNativeSpec')[0]; + if (!fbReactNativeSpecLib) { + throw new Error( + "[Codegen] Can't find FBReactNativeSpec library. Failed to generate rncore artifacts", + ); + } + const fbReactNativeSchemaInfo = generateSchemaInfo(fbReactNativeSpecLib, ios); + generateCode('', fbReactNativeSchemaInfo, false, ios); +} + // Execute /** @@ -773,6 +818,7 @@ function execute(projectRoot, targetPlatform, baseOutputPath) { module.exports = { execute, generateRNCoreComponentsIOS, + generateFBReactNativeSpecIOS, // exported for testing purposes only: _extractLibrariesFromJSON: extractLibrariesFromJSON, _cleanupEmptyFilesAndFolders: cleanupEmptyFilesAndFolders, diff --git a/packages/react-native/scripts/prepack.js b/packages/react-native/scripts/prepack.js index 694e891117d..c88cb4638f1 100644 --- a/packages/react-native/scripts/prepack.js +++ b/packages/react-native/scripts/prepack.js @@ -10,6 +10,7 @@ */ const { + generateFBReactNativeSpecIOS, generateRNCoreComponentsIOS, } = require('./codegen/generate-artifacts-executor'); const fs = require('fs'); @@ -18,6 +19,7 @@ function main() { console.info('[Prepack] Copying README.md'); fs.copyFileSync('../../README.md', './README.md'); generateRNCoreComponentsIOS('.'); + generateFBReactNativeSpecIOS('.'); } if (require.main === module) { diff --git a/packages/react-native/scripts/react_native_pods.rb b/packages/react-native/scripts/react_native_pods.rb index 14cb67b102d..7d99f2b9e7d 100644 --- a/packages/react-native/scripts/react_native_pods.rb +++ b/packages/react-native/scripts/react_native_pods.rb @@ -130,6 +130,7 @@ def use_react_native! ( pod 'React-jserrorhandler', :path => "#{prefix}/ReactCommon/jserrorhandler" pod 'React-nativeconfig', :path => "#{prefix}/ReactCommon" pod 'RCTDeprecation', :path => "#{prefix}/ReactApple/Libraries/RCTFoundation/RCTDeprecation" + pod 'React-RCTFBReactNativeSpec', :path => "#{prefix}/React" if hermes_enabled setup_hermes!(:react_native_path => prefix)