From c22e7e7cc5262984bc76cb461eb79112051b6612 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A9ctor=20Ramos?= Date: Thu, 20 Oct 2022 14:14:23 -0700 Subject: [PATCH] Do not build JSI in React-jsi when Hermes is enabled, resolve JSI ODR violation (#35038) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/35038 React-jsi provides JSI to allow React Native to interface with JavaScriptCore. The hermes-engine Pod provides a second copy of JSI, as Hermes is built and linked statically with JSI. This second copy of JSI would lead to an [ODR Violation](https://en.cppreference.com/w/cpp/language/definition). To resolve this, when Hermes is enabled: - React-hermes and hermes-engine are installed. - React-jsc is not installed. - React-jsi continues to be installed. - React-jsi will not build JSI. - React-jsi will declare a dependency on hermes-engine. The result is that the JSI dependency for React Native is satisfied by hermes-engine, and there is no duplicate JSI library in the project. When Hermes is disabled: - React-jsi and React-jsc are installed. - React-hermes and hermes-engine are not installed. - React-jsi will build JSI. Changelog: [iOS][Changed] Resolve JSI ODR violation, make hermes-engine the JSI provider when Hermes is enabled Reviewed By: cipolleschi Differential Revision: D40334913 fbshipit-source-id: 409407a193a35cbd21b0e8778537b3627e4c54a2 --- Libraries/Blob/React-RCTBlob.podspec | 1 - Libraries/Image/React-RCTImage.podspec | 1 - Libraries/LinkingIOS/React-RCTLinking.podspec | 1 - .../React-RCTAnimation.podspec | 1 - Libraries/Network/React-RCTNetwork.podspec | 1 - .../React-RCTPushNotification.podspec | 1 - Libraries/Settings/React-RCTSettings.podspec | 1 - .../Vibration/React-RCTVibration.podspec | 1 - React-Core.podspec | 1 - React/CoreModules/React-CoreModules.podspec | 1 - .../FBReactNativeSpec.podspec | 1 - ReactCommon/React-Fabric.podspec | 1 - ReactCommon/React-bridging.podspec | 1 - ReactCommon/ReactCommon.podspec | 1 - ReactCommon/cxxreact/React-cxxreact.podspec | 1 - ReactCommon/hermes/React-hermes.podspec | 2 +- ReactCommon/jsi/React-jsc.podspec | 1 - ReactCommon/jsi/React-jsi.podspec | 27 +++++++++---- ReactCommon/jsi/React-jsidynamic.podspec | 1 - .../React-runtimeexecutor.podspec | 1 - packages/rn-tester/Podfile.lock | 32 +++++---------- .../rn-tester/RCTTest/React-RCTTest.podspec | 1 - .../cocoapods/__tests__/codegen_utils-test.rb | 40 ++++++++++--------- scripts/cocoapods/__tests__/jsengine-test.rb | 6 +-- .../__tests__/test_utils/CodegenUtilsMock.rb | 3 +- scripts/cocoapods/codegen.rb | 5 ++- scripts/cocoapods/codegen_utils.rb | 19 +++++++-- scripts/cocoapods/jsengine.rb | 4 -- scripts/react_native_pods.rb | 1 + sdks/hermes-engine/hermes-engine.podspec | 4 ++ 30 files changed, 79 insertions(+), 83 deletions(-) diff --git a/Libraries/Blob/React-RCTBlob.podspec b/Libraries/Blob/React-RCTBlob.podspec index a4606fe2f06ee6..30cf7e14171060 100644 --- a/Libraries/Blob/React-RCTBlob.podspec +++ b/Libraries/Blob/React-RCTBlob.podspec @@ -42,7 +42,6 @@ Pod::Spec.new do |s| s.dependency "React-Codegen", version s.dependency "ReactCommon/turbomodule/core", version s.dependency "React-jsi", version - s.dependency "React-jsc", version s.dependency "React-Core/RCTBlobHeaders", version s.dependency "React-Core/RCTWebSocket", version s.dependency "React-RCTNetwork", version diff --git a/Libraries/Image/React-RCTImage.podspec b/Libraries/Image/React-RCTImage.podspec index 283f0994d5a36c..614245a225300d 100644 --- a/Libraries/Image/React-RCTImage.podspec +++ b/Libraries/Image/React-RCTImage.podspec @@ -44,7 +44,6 @@ Pod::Spec.new do |s| s.dependency "RCTTypeSafety", version s.dependency "ReactCommon/turbomodule/core", version s.dependency "React-jsi", version - s.dependency "React-jsc", version s.dependency "React-Core/RCTImageHeaders", version s.dependency "React-RCTNetwork", version end diff --git a/Libraries/LinkingIOS/React-RCTLinking.podspec b/Libraries/LinkingIOS/React-RCTLinking.podspec index d81a27204a1b12..1def01915d53d2 100644 --- a/Libraries/LinkingIOS/React-RCTLinking.podspec +++ b/Libraries/LinkingIOS/React-RCTLinking.podspec @@ -43,5 +43,4 @@ Pod::Spec.new do |s| s.dependency "React-Core/RCTLinkingHeaders", version s.dependency "ReactCommon/turbomodule/core", version s.dependency "React-jsi", version - s.dependency "React-jsc", version end diff --git a/Libraries/NativeAnimation/React-RCTAnimation.podspec b/Libraries/NativeAnimation/React-RCTAnimation.podspec index b8122e7844b1c6..2a15aed44359b7 100644 --- a/Libraries/NativeAnimation/React-RCTAnimation.podspec +++ b/Libraries/NativeAnimation/React-RCTAnimation.podspec @@ -43,6 +43,5 @@ Pod::Spec.new do |s| s.dependency "RCTTypeSafety", version s.dependency "ReactCommon/turbomodule/core", version s.dependency "React-jsi", version - s.dependency "React-jsc", version s.dependency "React-Core/RCTAnimationHeaders", version end diff --git a/Libraries/Network/React-RCTNetwork.podspec b/Libraries/Network/React-RCTNetwork.podspec index b1618e3c487788..c0bd78a8cfb8e3 100644 --- a/Libraries/Network/React-RCTNetwork.podspec +++ b/Libraries/Network/React-RCTNetwork.podspec @@ -44,6 +44,5 @@ Pod::Spec.new do |s| s.dependency "RCTTypeSafety", version s.dependency "ReactCommon/turbomodule/core", version s.dependency "React-jsi", version - s.dependency "React-jsc", version s.dependency "React-Core/RCTNetworkHeaders", version end diff --git a/Libraries/PushNotificationIOS/React-RCTPushNotification.podspec b/Libraries/PushNotificationIOS/React-RCTPushNotification.podspec index 01f9a21b8bce8d..4d410d7fdc5176 100644 --- a/Libraries/PushNotificationIOS/React-RCTPushNotification.podspec +++ b/Libraries/PushNotificationIOS/React-RCTPushNotification.podspec @@ -45,5 +45,4 @@ Pod::Spec.new do |s| s.dependency "React-Core/RCTPushNotificationHeaders", version s.dependency "ReactCommon/turbomodule/core", version s.dependency "React-jsi", version - s.dependency "React-jsc", version end diff --git a/Libraries/Settings/React-RCTSettings.podspec b/Libraries/Settings/React-RCTSettings.podspec index bc5f3bd3ff8456..11770ad527e999 100644 --- a/Libraries/Settings/React-RCTSettings.podspec +++ b/Libraries/Settings/React-RCTSettings.podspec @@ -44,6 +44,5 @@ Pod::Spec.new do |s| s.dependency "RCTTypeSafety", version s.dependency "ReactCommon/turbomodule/core", version s.dependency "React-jsi", version - s.dependency "React-jsc", version s.dependency "React-Core/RCTSettingsHeaders", version end diff --git a/Libraries/Vibration/React-RCTVibration.podspec b/Libraries/Vibration/React-RCTVibration.podspec index 577d03e4ad7465..28dcce4487b89a 100644 --- a/Libraries/Vibration/React-RCTVibration.podspec +++ b/Libraries/Vibration/React-RCTVibration.podspec @@ -44,6 +44,5 @@ Pod::Spec.new do |s| s.dependency "React-Codegen", version s.dependency "ReactCommon/turbomodule/core", version s.dependency "React-jsi", version - s.dependency "React-jsc", version s.dependency "React-Core/RCTVibrationHeaders", version end diff --git a/React-Core.podspec b/React-Core.podspec index 6997029a839b2e..7be727f36705bc 100644 --- a/React-Core.podspec +++ b/React-Core.podspec @@ -111,7 +111,6 @@ Pod::Spec.new do |s| s.dependency "React-cxxreact", version s.dependency "React-perflogger", version s.dependency "React-jsi", version - s.dependency "React-jsc", version s.dependency "React-jsiexecutor", version s.dependency "Yoga" s.dependency "glog" diff --git a/React/CoreModules/React-CoreModules.podspec b/React/CoreModules/React-CoreModules.podspec index e4b5a32085426f..a4a605aaf01257 100644 --- a/React/CoreModules/React-CoreModules.podspec +++ b/React/CoreModules/React-CoreModules.podspec @@ -44,5 +44,4 @@ Pod::Spec.new do |s| s.dependency "React-RCTImage", version s.dependency "ReactCommon/turbomodule/core", version s.dependency "React-jsi", version - s.dependency "React-jsc", version end diff --git a/React/FBReactNativeSpec/FBReactNativeSpec.podspec b/React/FBReactNativeSpec/FBReactNativeSpec.podspec index 26a2aafcab63c3..37f2a17d8dffb5 100644 --- a/React/FBReactNativeSpec/FBReactNativeSpec.podspec +++ b/React/FBReactNativeSpec/FBReactNativeSpec.podspec @@ -47,7 +47,6 @@ Pod::Spec.new do |s| s.dependency "RCTTypeSafety", version s.dependency "React-Core", version s.dependency "React-jsi", version - s.dependency "React-jsc", version s.dependency "ReactCommon/turbomodule/core", version use_react_native_codegen!(s, { diff --git a/ReactCommon/React-Fabric.podspec b/ReactCommon/React-Fabric.podspec index e89485ac991abd..c28eee60d06fbe 100644 --- a/ReactCommon/React-Fabric.podspec +++ b/ReactCommon/React-Fabric.podspec @@ -42,7 +42,6 @@ Pod::Spec.new do |s| s.dependency "RCTTypeSafety", version s.dependency "ReactCommon/turbomodule/core", version s.dependency "React-jsi", version - s.dependency "React-jsc", version s.subspec "animations" do |ss| ss.dependency folly_dep_name, folly_version diff --git a/ReactCommon/React-bridging.podspec b/ReactCommon/React-bridging.podspec index 13d9bec09ffcfb..660d0efdd9deb5 100644 --- a/ReactCommon/React-bridging.podspec +++ b/ReactCommon/React-bridging.podspec @@ -40,5 +40,4 @@ Pod::Spec.new do |s| s.dependency "RCT-Folly", folly_version s.dependency "React-jsi", version - s.dependency "React-jsc", version end diff --git a/ReactCommon/ReactCommon.podspec b/ReactCommon/ReactCommon.podspec index 538fc077f62004..4cd4f04e59c31a 100644 --- a/ReactCommon/ReactCommon.podspec +++ b/ReactCommon/ReactCommon.podspec @@ -46,7 +46,6 @@ Pod::Spec.new do |s| ss.dependency "React-Core", version ss.dependency "React-cxxreact", version ss.dependency "React-jsi", version - ss.dependency "React-jsc", version ss.dependency "RCT-Folly", folly_version s.dependency "React-logger", version ss.dependency "DoubleConversion" diff --git a/ReactCommon/cxxreact/React-cxxreact.podspec b/ReactCommon/cxxreact/React-cxxreact.podspec index d54906d0e1e512..c4498e9d3f1f80 100644 --- a/ReactCommon/cxxreact/React-cxxreact.podspec +++ b/ReactCommon/cxxreact/React-cxxreact.podspec @@ -45,6 +45,5 @@ Pod::Spec.new do |s| s.dependency "React-runtimeexecutor", version s.dependency "React-perflogger", version s.dependency "React-jsi", version - s.dependency "React-jsc", version s.dependency "React-logger", version end diff --git a/ReactCommon/hermes/React-hermes.podspec b/ReactCommon/hermes/React-hermes.podspec index 51d717b2655135..0b6432596c828b 100644 --- a/ReactCommon/hermes/React-hermes.podspec +++ b/ReactCommon/hermes/React-hermes.podspec @@ -44,7 +44,7 @@ Pod::Spec.new do |s| }.merge!(build_type == :debug ? { "GCC_PREPROCESSOR_DEFINITIONS" => "HERMES_ENABLE_DEBUGGER=1" } : {}) s.header_dir = "reacthermes" s.dependency "React-cxxreact", version - s.dependency "React-jsi", version + s.dependency "React-jsidynamic", version s.dependency "React-jsiexecutor", version s.dependency "React-jsinspector", version s.dependency "React-perflogger", version diff --git a/ReactCommon/jsi/React-jsc.podspec b/ReactCommon/jsi/React-jsc.podspec index ed6e923bfae6c7..ce59f0e69e6ac9 100644 --- a/ReactCommon/jsi/React-jsc.podspec +++ b/ReactCommon/jsi/React-jsc.podspec @@ -29,7 +29,6 @@ Pod::Spec.new do |s| s.exclude_files = "**/test/*" s.framework = "JavaScriptCore" s.dependency "React-jsi", version - s.default_subspec = "Default" s.subspec "Default" do diff --git a/ReactCommon/jsi/React-jsi.podspec b/ReactCommon/jsi/React-jsi.podspec index 96465cfa4d205e..ac21bada4f44b2 100644 --- a/ReactCommon/jsi/React-jsi.podspec +++ b/ReactCommon/jsi/React-jsi.podspec @@ -5,6 +5,10 @@ require "json" +js_engine = ENV['USE_HERMES'] == "0" ? + :jsc : + :hermes + package = JSON.parse(File.read(File.join(__dir__, "..", "..", "package.json"))) version = package['version'] @@ -25,12 +29,19 @@ Pod::Spec.new do |s| s.author = "Facebook, Inc. and its affiliates" s.platforms = { :ios => "12.4" } s.source = source - s.source_files = "jsi/*.{cpp,h}" - s.exclude_files = [ - "jsi/JSIDynamic.{h,cpp}", - "jsi/jsilib-posix.cpp", - "jsi/jsilib-windows.cpp", - "**/test/*" - ] - s.header_dir = "jsi" + + if js_engine == :jsc + s.source_files = "**/*.{cpp,h}" + s.exclude_files = [ + "jsi/JSIDynamic.{h,cpp}", + "jsi/jsilib-posix.cpp", + "jsi/jsilib-windows.cpp", + "**/test/*" + ] + s.header_dir = "jsi" + elsif js_engine == :hermes + # JSI is provided by hermes-engine when Hermes is enabled + s.source_files = "" + s.dependency "hermes-engine" + end end diff --git a/ReactCommon/jsi/React-jsidynamic.podspec b/ReactCommon/jsi/React-jsidynamic.podspec index 7e43baacfc7a6e..831c6b010fc461 100644 --- a/ReactCommon/jsi/React-jsidynamic.podspec +++ b/ReactCommon/jsi/React-jsidynamic.podspec @@ -39,5 +39,4 @@ Pod::Spec.new do |s| s.dependency "RCT-Folly", folly_version s.dependency "glog" s.dependency "React-jsi", version - s.dependency "React-jsc", version end diff --git a/ReactCommon/runtimeexecutor/React-runtimeexecutor.podspec b/ReactCommon/runtimeexecutor/React-runtimeexecutor.podspec index 09781b7d5a7e09..5cbadf30d531fe 100644 --- a/ReactCommon/runtimeexecutor/React-runtimeexecutor.podspec +++ b/ReactCommon/runtimeexecutor/React-runtimeexecutor.podspec @@ -33,5 +33,4 @@ Pod::Spec.new do |s| s.header_dir = "ReactCommon" s.dependency "React-jsi", version - s.dependency "React-jsc", version end diff --git a/packages/rn-tester/Podfile.lock b/packages/rn-tester/Podfile.lock index dbe96b11d6d167..fedd81b021de81 100644 --- a/packages/rn-tester/Podfile.lock +++ b/packages/rn-tester/Podfile.lock @@ -122,6 +122,7 @@ PODS: - React-callinvoker (1000.0.0) - React-Codegen (1000.0.0): - FBReactNativeSpec (= 1000.0.0) + - hermes-engine (= 1000.0.0) - RCT-Folly (= 2021.07.22.00) - RCTRequired (= 1000.0.0) - RCTTypeSafety (= 1000.0.0) @@ -615,26 +616,12 @@ PODS: - RCT-Folly (= 2021.07.22.00) - RCT-Folly/Futures (= 2021.07.22.00) - React-cxxreact (= 1000.0.0) - - React-jsi (= 1000.0.0) + - React-jsidynamic (= 1000.0.0) - React-jsiexecutor (= 1000.0.0) - React-jsinspector (= 1000.0.0) - React-perflogger (= 1000.0.0) - React-jsi (1000.0.0): - - boost (= 1.76.0) - - DoubleConversion - - glog - - RCT-Folly (= 2021.07.22.00) - - React-jsi/Default (= 1000.0.0) - - React-jsi/Default (1000.0.0): - - boost (= 1.76.0) - - DoubleConversion - - glog - - RCT-Folly (= 2021.07.22.00) - - React-jsi/Fabric (1000.0.0): - - boost (= 1.76.0) - - DoubleConversion - - glog - - RCT-Folly (= 2021.07.22.00) + - hermes-engine - React-jsidynamic (1000.0.0): - boost (= 1.76.0) - DoubleConversion @@ -810,7 +797,6 @@ DEPENDENCIES: - React-graphics (from `../../ReactCommon/react/renderer/graphics`) - React-hermes (from `../../ReactCommon/hermes`) - React-jsi (from `../../ReactCommon/jsi`) - - React-jsi/Fabric (from `../../ReactCommon/jsi`) - React-jsidynamic (from `../../ReactCommon/jsi`) - React-jsiexecutor (from `../../ReactCommon/jsiexecutor`) - React-jsinspector (from `../../ReactCommon/jsinspector`) @@ -959,7 +945,7 @@ SPEC CHECKSUMS: FlipperKit: cbdee19bdd4e7f05472a66ce290f1b729ba3cb86 fmt: ff9d55029c625d3757ed641535fd4a75fedc7ce9 glog: 04b94705f318337d7ead9e6d17c019bd9b1f6b1b - hermes-engine: 041c211d43030d9aeff8faa388c019d19e752172 + hermes-engine: 2c30267d0c2771edc2d369ac694d45f1278ab08b libevent: 4049cae6c81cdb3654a443be001fb9bdceff7913 OpenSSL-Universal: ebc357f1e6bc71fa463ccb2fe676756aff50e88c RCT-Folly: 0080d0a6ebf2577475bda044aa59e2ca1f909cda @@ -968,14 +954,14 @@ SPEC CHECKSUMS: React: 8d809d414723bb5763093ddec7658066a21ccabc React-bridging: c8806159f8ef90f27443857eed1efdb8c85940e1 React-callinvoker: 5f16202ad4e45f0607b1fae0f6955a8f7c87eef1 - React-Codegen: 5adf19af97eb37a7d441c040521191e446255086 - React-Core: ce4282fb714ffbe444b84d296d1728eaee4d0e9f + React-Codegen: d2434d5e4d238bceef25f40c4f58b199eb981ad0 + React-Core: 3965263aa4b4e1ebf7b4fdb50d2f49ce7bf28f63 React-CoreModules: 675170bccf156da3a3348e04e2036ce401b2010d React-cxxreact: 7276467c246302fedf598cc40d7003896ddb20ba React-Fabric: 141459e61c825acf02d26ece099acbd9cbd87b99 React-graphics: 5ccc9cc0d91794fd42bc1c693e9aea207554bbef - React-hermes: 7b9306aee1d58ba030614e54eb8041056119430f - React-jsi: c2a71fdc55642893768c517199fb8a71805159dc + React-hermes: 0a5145bae4207edf0def8e28fbcb6a8fd6e806c2 + React-jsi: c24dbcfdf7ea075138b73372387c7f17c0db56ef React-jsidynamic: 2b14ac1b6d3a1b7daa1e5a424b98de87da981698 React-jsiexecutor: 14e899380e3fe9ca74c4e19727540a03e7574721 React-jsinspector: 7733dd522d044aef87caa39f3eda77593358a7eb @@ -983,7 +969,7 @@ SPEC CHECKSUMS: React-perflogger: c4fdd48988c2d3047186fc1bc1772d634cfca2ea React-RCTActionSheet: 166fd1df85ac10219466b45d12a5884d3eaceac1 React-RCTAnimation: d6127046c6bb44bd3e67b7503c4ad7f91131b58e - React-RCTAppDelegate: 475ca9b80e26c1c4aed93ce04363092fa78cf788 + React-RCTAppDelegate: e427b692bf829e40f9b318e2a29dca2ab5f36cf6 React-RCTBlob: 68675c89ebe6edf310dddd0774ba07b685f090a9 React-RCTFabric: a98a6effece6719669b8c6b4d2c33fb0edddc613 React-RCTImage: 6de9f0f4402af859849e97cc73a56a52f400f4c9 diff --git a/packages/rn-tester/RCTTest/React-RCTTest.podspec b/packages/rn-tester/RCTTest/React-RCTTest.podspec index 377754901b2cbf..f6836ca2fa1e2d 100644 --- a/packages/rn-tester/RCTTest/React-RCTTest.podspec +++ b/packages/rn-tester/RCTTest/React-RCTTest.podspec @@ -44,5 +44,4 @@ Pod::Spec.new do |s| s.dependency "React-CoreModules", version s.dependency "ReactCommon/turbomodule/core", version s.dependency "React-jsi", version - s.dependency "React-jsc", version end diff --git a/scripts/cocoapods/__tests__/codegen_utils-test.rb b/scripts/cocoapods/__tests__/codegen_utils-test.rb index 606020bd9b0e7b..69a5f8c2dc0b35 100644 --- a/scripts/cocoapods/__tests__/codegen_utils-test.rb +++ b/scripts/cocoapods/__tests__/codegen_utils-test.rb @@ -39,9 +39,9 @@ def teardown Dir.reset() end - # ================================== # - # Test - GenerateReactCodegenPodspec # - # ================================== # + # ================================== # + # Test - GenerateReactCodegenPodspec # + # ================================== # def testGenerateReactCodegenPodspec_whenItHasBeenAlreadyGenerated_doesNothing # Arrange @@ -80,18 +80,19 @@ def testGenerateReactCodegenPodspec_whenItHasNotBeenAlreadyGenerated_generatesIt assert_true(CodegenUtils.react_codegen_podspec_generated) end - # ========================== # - # Test - GetReactCodegenSpec # - # ========================== # + # ========================== # + # Test - GetReactCodegenSpec # + # ========================== # def testGetReactCodegenSpec_whenFabricDisabledAndNoScriptPhases_generatesAPodspec - # Arrange + # Arrange File.files_to_read('package.json' => '{ "version": "99.98.97"}') - # Act + # Act podspec = CodegenUtils.new().get_react_codegen_spec( 'package.json', :fabric_enabled => false, + :hermes_enabled => true, :script_phases => nil ) @@ -101,13 +102,14 @@ def testGetReactCodegenSpec_whenFabricDisabledAndNoScriptPhases_generatesAPodspe end def testGetReactCodegenSpec_whenFabricEnabledAndScriptPhases_generatesAPodspec - # Arrange + # Arrange File.files_to_read('package.json' => '{ "version": "99.98.97"}') # Act podspec = CodegenUtils.new().get_react_codegen_spec( 'package.json', :fabric_enabled => true, + :hermes_enabled => true, :script_phases => "echo Test Script Phase" ) @@ -117,11 +119,11 @@ def testGetReactCodegenSpec_whenFabricEnabledAndScriptPhases_generatesAPodspec end # =============================== # - # Test - GetCodegenConfigFromFile # - # =============================== # + # Test - GetCodegenConfigFromFile # + # =============================== # def testGetCodegenConfigFromFile_whenFileDoesNotExists_returnEmpty - # Arrange + # Arrange # Act codegen = CodegenUtils.new().get_codegen_config_from_file('package.json', 'codegenConfig') @@ -131,7 +133,7 @@ def testGetCodegenConfigFromFile_whenFileDoesNotExists_returnEmpty end def testGetCodegenConfigFromFile_whenFileExistsButHasNoKey_returnEmpty - # Arrange + # Arrange File.mocked_existing_files(['package.json']) File.files_to_read('package.json' => '{ "codegenConfig": {}}') @@ -143,7 +145,7 @@ def testGetCodegenConfigFromFile_whenFileExistsButHasNoKey_returnEmpty end def testGetCodegenConfigFromFile_whenFileExistsAndHasKey_returnObject - # Arrange + # Arrange File.mocked_existing_files(['package.json']) File.files_to_read('package.json' => '{ "codegenConfig": {"name": "MySpec"}}') @@ -217,7 +219,7 @@ def testGetListOfJSSpecs_whenDoesNotUsesLibraries_returnAListOfFiles # ================================== # # Test - GetReactCodegenScriptPhases # - # ================================== # + # ================================== # def testGetReactCodegenScriptPhases_whenAppPathNotDefined_abort # Arrange @@ -370,9 +372,9 @@ def testUseReactCodegenDiscovery_whenParametersAreGood_executeCodegen ]) end - # ============================= # - # Test - CleanUpCodegenFolder # - # ============================= # + # ============================= # + # Test - CleanUpCodegenFolder # + # ============================= # def testCleanUpCodegenFolder_whenCleanupDone_doNothing # Arrange @@ -463,7 +465,7 @@ def get_podspec_no_fabric_no_script "RCTTypeSafety": ["99.98.97"], "React-Core": ["99.98.97"], "React-jsi": ["99.98.97"], - "React-jsc": ["99.98.97"], + "hermes-engine": ["99.98.97"], "ReactCommon/turbomodule/core": ["99.98.97"] } } diff --git a/scripts/cocoapods/__tests__/jsengine-test.rb b/scripts/cocoapods/__tests__/jsengine-test.rb index 51efcef5da565d..13ad540d5f25bf 100644 --- a/scripts/cocoapods/__tests__/jsengine-test.rb +++ b/scripts/cocoapods/__tests__/jsengine-test.rb @@ -98,7 +98,7 @@ def test_setupHermes_whenHermesScriptSucceeds_installsPods "returned by", "prepare-hermes-for-build", ]) - assert_equal($podInvocationCount, 5) + assert_equal($podInvocationCount, 4) assert_equal($podInvocation["React-jsi"][:path], "../../ReactCommon/jsi") assert_equal($podInvocation["React-hermes"][:path], "../../ReactCommon/hermes") assert_equal($podInvocation["libevent"][:version], "~> 2.1.12") @@ -113,10 +113,8 @@ def test_setupHermes_installsPods_installsFabricSubspecWhenFabricEnabled setup_hermes!(:react_native_path => @react_native_path, :fabric_enabled => fabric_enabled) # Assert - assert_equal($podInvocationCount, 6) + assert_equal($podInvocationCount, 4) assert_equal($podInvocation["React-jsi"][:path], "../../ReactCommon/jsi") - assert_equal($podInvocation["React-jsc"][:path], "../../ReactCommon/jsi") - assert_equal($podInvocation["React-jsc/Fabric"][:path], "../../ReactCommon/jsi") assert_equal($podInvocation["hermes-engine"][:podspec], "../../sdks/hermes/hermes-engine.podspec") assert_equal($podInvocation["React-hermes"][:path], "../../ReactCommon/hermes") assert_equal($podInvocation["libevent"][:version], "~> 2.1.12") diff --git a/scripts/cocoapods/__tests__/test_utils/CodegenUtilsMock.rb b/scripts/cocoapods/__tests__/test_utils/CodegenUtilsMock.rb index 8d9750157e2e84..d5d3f5b73bb653 100644 --- a/scripts/cocoapods/__tests__/test_utils/CodegenUtilsMock.rb +++ b/scripts/cocoapods/__tests__/test_utils/CodegenUtilsMock.rb @@ -66,7 +66,7 @@ def get_react_codegen_script_phases( return @react_codegen_script_phases end - def get_react_codegen_spec(package_json_file, folly_version: '2021.07.22.00', fabric_enabled: false, script_phases: nil) + def get_react_codegen_spec(package_json_file, folly_version: '2021.07.22.00', fabric_enabled: false, hermes_enabled: true, script_phases: nil) @get_react_codegen_spec_params.push({ package_json_file: package_json_file, folly_version: folly_version, @@ -88,6 +88,7 @@ def use_react_native_codegen_discovery!( app_path, react_native_path: "../node_modules/react-native", fabric_enabled: false, + hermes_enabled: true, config_file_dir: '', codegen_output_dir: 'build/generated/ios', config_key: 'codegenConfig', diff --git a/scripts/cocoapods/codegen.rb b/scripts/cocoapods/codegen.rb index fdf6a84bbbb985..f3c214de819360 100644 --- a/scripts/cocoapods/codegen.rb +++ b/scripts/cocoapods/codegen.rb @@ -73,6 +73,7 @@ def run_codegen!( disable_codegen: false, react_native_path: "../node_modules/react-native", fabric_enabled: false, + hermes_enabled: true, codegen_output_dir: 'build/generated/ios', config_key: 'codegenConfig', package_json_file: '~/app/package.json', @@ -86,6 +87,7 @@ def run_codegen!( app_path, :react_native_path => react_native_path, :fabric_enabled => fabric_enabled, + :hermes_enabled => hermes_enabled, :config_file_dir => config_file_dir, :codegen_output_dir => codegen_output_dir, :config_key => config_key, @@ -96,7 +98,8 @@ def run_codegen!( # This gets generated in use_react_native_codegen_discovery when codegen discovery is enabled. react_codegen_spec = codegen_utils.get_react_codegen_spec( package_json_file, - :fabric_enabled => fabric_enabled + :fabric_enabled => fabric_enabled, + :hermes_enabled => hermes_enabled ) codegen_utils.generate_react_codegen_podspec!(react_codegen_spec, codegen_output_dir) end diff --git a/scripts/cocoapods/codegen_utils.rb b/scripts/cocoapods/codegen_utils.rb index c1548f90bfdeb4..608d9f210cfd4d 100644 --- a/scripts/cocoapods/codegen_utils.rb +++ b/scripts/cocoapods/codegen_utils.rb @@ -65,8 +65,9 @@ def generate_react_codegen_podspec!(spec, codegen_output_dir) # Parameters # - package_json_file: the path to the `package.json`, required to extract the proper React Native version # - fabric_enabled: whether fabric is enabled or not. + # - hermes_enabled: whether hermes is enabled or not. # - script_phases: whether we want to add some build script phases or not. - def get_react_codegen_spec(package_json_file, folly_version: '2021.07.22.00', fabric_enabled: false, script_phases: nil) + def get_react_codegen_spec(package_json_file, folly_version: '2021.07.22.00', fabric_enabled: false, hermes_enabled: true, script_phases: nil) package = JSON.parse(File.read(package_json_file)) version = package['version'] @@ -104,7 +105,6 @@ def get_react_codegen_spec(package_json_file, folly_version: '2021.07.22.00', fa "RCTTypeSafety": [version], "React-Core": [version], "React-jsi": [version], - "React-jsc": [version], "ReactCommon/turbomodule/core": [version] } } @@ -116,6 +116,16 @@ def get_react_codegen_spec(package_json_file, folly_version: '2021.07.22.00', fa }); end + if hermes_enabled + spec[:'dependencies'].merge!({ + 'hermes-engine': [version], + }); + else + spec[:'dependencies'].merge!({ + 'React-jsc': [version], + }); + end + if script_phases Pod::UI.puts "[Codegen] Adding script_phases to React-Codegen." spec[:'script_phases'] = script_phases @@ -128,7 +138,7 @@ def get_react_codegen_spec(package_json_file, folly_version: '2021.07.22.00', fa # # Parameters # - config_path: a path to the configuration file - # - config_ket: the codegen configuration key + # - config_key: the codegen configuration key # # Returns: the list of dependencies as extracted from the package.json def get_codegen_config_from_file(config_path, config_key) @@ -182,6 +192,7 @@ def get_list_of_js_specs(app_codegen_config, app_path) def get_react_codegen_script_phases( app_path, fabric_enabled: false, + hermes_enabled: false, config_file_dir: '', react_native_path: "../node_modules/react-native", config_key: 'codegenConfig', @@ -230,6 +241,7 @@ def use_react_native_codegen_discovery!( app_path, react_native_path: "../node_modules/react-native", fabric_enabled: false, + hermes_enabled: true, config_file_dir: '', codegen_output_dir: 'build/generated/ios', config_key: 'codegenConfig', @@ -264,6 +276,7 @@ def use_react_native_codegen_discovery!( File.join(react_native_path, "package.json"), :folly_version => folly_version, :fabric_enabled => fabric_enabled, + :hermes_enabled => hermes_enabled, :script_phases => script_phases ) codegen_utils.generate_react_codegen_podspec!(react_codegen_spec, codegen_output_dir) diff --git a/scripts/cocoapods/jsengine.rb b/scripts/cocoapods/jsengine.rb index a07ff842806c5d..8ec69c59f0bafd 100644 --- a/scripts/cocoapods/jsengine.rb +++ b/scripts/cocoapods/jsengine.rb @@ -30,10 +30,6 @@ def setup_hermes!(react_native_path: "../node_modules/react-native", fabric_enab abort unless prep_status == 0 pod 'React-jsi', :path => "#{react_native_path}/ReactCommon/jsi" - pod 'React-jsc', :path => "#{react_native_path}/ReactCommon/jsi" - if fabric_enabled - pod 'React-jsc/Fabric', :path => "#{react_native_path}/ReactCommon/jsi" - end pod 'hermes-engine', :podspec => "#{react_native_path}/sdks/hermes/hermes-engine.podspec" pod 'React-hermes', :path => "#{react_native_path}/ReactCommon/hermes" pod 'libevent', '~> 2.1.12' diff --git a/scripts/react_native_pods.rb b/scripts/react_native_pods.rb index 995b6ca3e636e4..73b44c12bab708 100644 --- a/scripts/react_native_pods.rb +++ b/scripts/react_native_pods.rb @@ -124,6 +124,7 @@ def use_react_native! ( :disable_codegen => ENV['DISABLE_CODEGEN'] == '1', :react_native_path => prefix, :fabric_enabled => fabric_enabled, + :hermes_enabled => hermes_enabled, :codegen_output_dir => $CODEGEN_OUTPUT_DIR, :package_json_file => File.join(__dir__, "..", "package.json"), :folly_version => $FOLLY_VERSION diff --git a/sdks/hermes-engine/hermes-engine.podspec b/sdks/hermes-engine/hermes-engine.podspec index b2e7b238667585..c78269f2a75a4e 100644 --- a/sdks/hermes-engine/hermes-engine.podspec +++ b/sdks/hermes-engine/hermes-engine.podspec @@ -62,6 +62,10 @@ Pod::Spec.new do |spec| spec.preserve_paths = ["destroot/bin/*"].concat(build_type == :debug ? ["**/*.{h,c,cpp}"] : []) spec.source_files = "destroot/include/**/*.h" + spec.exclude_files = [ + "destroot/include/jsi/jsi/JSIDynamic.{h,cpp}", + "destroot/include/jsi/jsi/jsilib-*.{h,cpp}", + ] spec.header_mappings_dir = "destroot/include" spec.ios.vendored_frameworks = "destroot/Library/Frameworks/universal/hermes.xcframework"