Skip to content

Commit 176bed7

Browse files
Kudofacebook-github-bot
authored andcommitted
decouple jsc when USE_THIRD_PARTY_JSC=1 on ios (#49371)
Summary: an effort of lean core for jsc: https://github.com/Kudo/discussions-and-proposals/blob/%40kudo/lean-core-jsc/proposals/0836-lean-core-jsc.md. this pr tries to decouple all jsc code when `USE_THIRD_PARTY_JSC=1` on ios this pr includes these changes: - exclude `React-jsc` pod and pod dependency when `USE_THIRD_PARTY_JSC=1` - in objcpp code, remove `JSCExecutorFactory` / `RCTJscInstance` references when `USE_THIRD_PARTY_JSC=1`. it throws c++ errors like `No JSRuntimeFactory specified.` when no engine is specified (USE_HERMES=0 && USE_THIRD_PARTY_JSC=1). people need to override delegate methods to specify a JSRuntimeFactory. ## Changelog: [IOS] [CHANGED] - Decouple JSC when `USE_THIRD_PARTY_JSC=1` Pull Request resolved: #49371 Test Plan: - ci passed - rn-tester build success for `RCT_NEW_ARCH_ENABLED=1 USE_THIRD_PARTY_JSC=1 USE_HERMES=0 USE_FRAMEWORKS=dynamic bundle exec pod install` - rn-tester build success for `RCT_NEW_ARCH_ENABLED=0 USE_THIRD_PARTY_JSC=1 USE_HERMES=0 USE_FRAMEWORKS=dynamic bundle exec pod install` - rn-tester build success for `RCT_NEW_ARCH_ENABLED=0 USE_THIRD_PARTY_JSC=1 USE_HERMES=0 bundle exec pod install` Reviewed By: cortinico Differential Revision: D69662457 Pulled By: cipolleschi fbshipit-source-id: b272f46dde896d0981cfca75c9bfcf6775507307
1 parent 7368265 commit 176bed7

File tree

12 files changed

+79
-42
lines changed

12 files changed

+79
-42
lines changed

packages/react-native/Libraries/AppDelegate/RCTAppDelegate.mm

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@
2525
#import <React/RCTComponentViewProtocol.h>
2626
#if USE_HERMES
2727
#import <ReactCommon/RCTHermesInstance.h>
28-
#else
28+
#elif USE_THIRD_PARTY_JSC != 1
2929
#import <ReactCommon/RCTJscInstance.h>
30-
#endif
30+
#endif // USE_HERMES
3131
#import <react/nativemodule/defaults/DefaultTurboModules.h>
3232

3333
using namespace facebook::react;

packages/react-native/Libraries/AppDelegate/RCTAppSetupUtils.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,12 @@
1919
#elif __has_include(<reacthermes/HermesExecutorFactory.h>)
2020
#import <reacthermes/HermesExecutorFactory.h>
2121
#endif
22-
#else // USE_HERMES
22+
#elif USE_THIRD_PARTY_JSC != 1
2323
#import <React/JSCExecutorFactory.h>
2424
#endif // USE_HERMES
2525

2626
#import <ReactCommon/RCTTurboModuleManager.h>
27+
#import <jsireact/JSIExecutor.h>
2728

2829
@protocol RCTDependencyProvider;
2930

packages/react-native/Libraries/AppDelegate/RCTAppSetupUtils.mm

Lines changed: 29 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -130,38 +130,47 @@ void RCTAppSetupPrepareApp(UIApplication *application, BOOL turboModuleEnabled)
130130
[turboModuleManager moduleForName:"RCTDevMenu"];
131131
#endif // end RCT_DEV
132132

133+
auto runtimeInstallerLambda = [turboModuleManager, bridge, runtimeScheduler](facebook::jsi::Runtime &runtime) {
134+
if (!bridge || !turboModuleManager) {
135+
return;
136+
}
137+
if (runtimeScheduler) {
138+
facebook::react::RuntimeSchedulerBinding::createAndInstallIfNeeded(runtime, runtimeScheduler);
139+
}
140+
[turboModuleManager installJSBindings:runtime];
141+
};
133142
#if USE_HERMES
134143
return std::make_unique<facebook::react::HermesExecutorFactory>(
135-
#else
144+
facebook::react::RCTJSIExecutorRuntimeInstaller(runtimeInstallerLambda));
145+
#elif USE_THIRD_PARTY_JSC != 1
136146
return std::make_unique<facebook::react::JSCExecutorFactory>(
147+
facebook::react::RCTJSIExecutorRuntimeInstaller(runtimeInstallerLambda));
148+
#else
149+
throw std::runtime_error("No JSExecutorFactory specified.");
150+
return nullptr;
137151
#endif // USE_HERMES
138-
facebook::react::RCTJSIExecutorRuntimeInstaller(
139-
[turboModuleManager, bridge, runtimeScheduler](facebook::jsi::Runtime &runtime) {
140-
if (!bridge || !turboModuleManager) {
141-
return;
142-
}
143-
if (runtimeScheduler) {
144-
facebook::react::RuntimeSchedulerBinding::createAndInstallIfNeeded(runtime, runtimeScheduler);
145-
}
146-
[turboModuleManager installJSBindings:runtime];
147-
}));
148152
}
149153

150154
std::unique_ptr<facebook::react::JSExecutorFactory> RCTAppSetupJsExecutorFactoryForOldArch(
151155
RCTBridge *bridge,
152156
const std::shared_ptr<facebook::react::RuntimeScheduler> &runtimeScheduler)
153157
{
158+
auto runtimeInstallerLambda = [bridge, runtimeScheduler](facebook::jsi::Runtime &runtime) {
159+
if (!bridge) {
160+
return;
161+
}
162+
if (runtimeScheduler) {
163+
facebook::react::RuntimeSchedulerBinding::createAndInstallIfNeeded(runtime, runtimeScheduler);
164+
}
165+
};
154166
#if USE_HERMES
155167
return std::make_unique<facebook::react::HermesExecutorFactory>(
156-
#else
168+
facebook::react::RCTJSIExecutorRuntimeInstaller(runtimeInstallerLambda));
169+
#elif USE_THIRD_PARTY_JSC != 1
157170
return std::make_unique<facebook::react::JSCExecutorFactory>(
171+
facebook::react::RCTJSIExecutorRuntimeInstaller(runtimeInstallerLambda));
172+
#else
173+
throw std::runtime_error("No JSExecutorFactory specified.");
174+
return nullptr;
158175
#endif // USE_HERMES
159-
facebook::react::RCTJSIExecutorRuntimeInstaller([bridge, runtimeScheduler](facebook::jsi::Runtime &runtime) {
160-
if (!bridge) {
161-
return;
162-
}
163-
if (runtimeScheduler) {
164-
facebook::react::RuntimeSchedulerBinding::createAndInstallIfNeeded(runtime, runtimeScheduler);
165-
}
166-
}));
167176
}

packages/react-native/Libraries/AppDelegate/RCTReactNativeFactory.mm

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@
2727
#import <React/RCTComponentViewProtocol.h>
2828
#if USE_HERMES
2929
#import <ReactCommon/RCTHermesInstance.h>
30-
#else
30+
#elif USE_THIRD_PARTY_JSC != 1
3131
#import <ReactCommon/RCTJscInstance.h>
32-
#endif
32+
#endif // USE_HERMES
3333
#import <react/nativemodule/defaults/DefaultTurboModules.h>
3434

3535
#import "RCTDependencyProvider.h"

packages/react-native/Libraries/AppDelegate/RCTRootViewFactory.mm

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,10 @@
2828
#import <React/RCTSurfacePresenter.h>
2929
#if USE_HERMES
3030
#import <ReactCommon/RCTHermesInstance.h>
31-
#else
31+
#elif USE_THIRD_PARTY_JSC != 1
3232
#import <ReactCommon/RCTJscInstance.h>
33-
#endif
33+
#else
34+
#endif // USE_HERMES
3435
#import <ReactCommon/RCTHost+Internal.h>
3536
#import <ReactCommon/RCTHost.h>
3637
#import <ReactCommon/RCTTurboModuleManager.h>
@@ -265,8 +266,10 @@ - (RCTHost *)createReactHost:(NSDictionary *)launchOptions
265266
{
266267
#if USE_HERMES
267268
return std::make_shared<facebook::react::RCTHermesInstance>(nullptr, /* allocInOldGenBeforeTTI */ false);
268-
#else
269+
#elif USE_THIRD_PARTY_JSC != 1
269270
return std::make_shared<facebook::react::RCTJscInstance>();
271+
#else
272+
throw std::runtime_error("No JSRuntimeFactory specified.");
270273
#endif
271274
}
272275

packages/react-native/Libraries/AppDelegate/React-RCTAppDelegate.podspec

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ use_hermes = ENV['USE_HERMES'] == nil || ENV['USE_HERMES'] == '1'
2525

2626
new_arch_enabled_flag = (is_new_arch_enabled ? " -DRCT_NEW_ARCH_ENABLED=1" : "")
2727
hermes_flag = (use_hermes ? " -DUSE_HERMES=1" : "")
28-
other_cflags = "$(inherited) " + folly_compiler_flags + new_arch_enabled_flag + hermes_flag
28+
use_third_party_jsc_flag = ENV['USE_THIRD_PARTY_JSC'] == '1' ? " -DUSE_THIRD_PARTY_JSC=1" : ""
29+
other_cflags = "$(inherited) " + folly_compiler_flags + new_arch_enabled_flag + hermes_flag + use_third_party_jsc_flag
2930

3031
header_search_paths = [
3132
"$(PODS_TARGET_SRCROOT)/../../ReactCommon",

packages/react-native/React-Core.podspec

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ boost_compiler_flags = boost_config[:compiler_flags]
2828

2929
use_hermes = ENV['USE_HERMES'] == nil || ENV['USE_HERMES'] == '1'
3030
use_hermes_flag = use_hermes ? "-DUSE_HERMES=1" : ""
31+
use_third_party_jsc_flag = ENV['USE_THIRD_PARTY_JSC'] == '1' ? "-DUSE_THIRD_PARTY_JSC=1" : ""
3132

3233
header_subspecs = {
3334
'CoreModulesHeaders' => 'React/CoreModules/**/*.h',
@@ -70,7 +71,7 @@ Pod::Spec.new do |s|
7071
s.platforms = min_supported_versions
7172
s.source = source
7273
s.resource_bundle = { "RCTI18nStrings" => ["React/I18n/strings/*.lproj"]}
73-
s.compiler_flags = folly_compiler_flags + ' ' + boost_compiler_flags + ' ' + use_hermes_flag
74+
s.compiler_flags = folly_compiler_flags + ' ' + boost_compiler_flags + ' ' + use_hermes_flag + ' ' + use_third_party_jsc_flag
7475
s.header_dir = "React"
7576
s.weak_framework = "JavaScriptCore"
7677
s.pod_target_xcconfig = {
@@ -95,7 +96,7 @@ Pod::Spec.new do |s|
9596
]
9697
# If we are using Hermes (the default is use hermes, so USE_HERMES can be nil), we don't have jsc installed
9798
# So we have to exclude the JSCExecutorFactory
98-
if use_hermes
99+
if use_hermes || ENV['USE_THIRD_PARTY_JSC'] == '1'
99100
exclude_files = exclude_files.append("React/CxxBridge/JSCExecutorFactory.{h,mm}")
100101
end
101102
ss.exclude_files = exclude_files

packages/react-native/React/CxxBridge/RCTCxxBridge.mm

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747

4848
#if USE_HERMES
4949
#import <reacthermes/HermesExecutorFactory.h>
50-
#else
50+
#elif USE_THIRD_PARTY_JSC != 1
5151
#import "JSCExecutorFactory.h"
5252
#endif
5353
#import "RCTJSIExecutorRuntimeInstaller.h"
@@ -440,8 +440,10 @@ - (void)start
440440
auto installBindings = RCTJSIExecutorRuntimeInstaller(nullptr);
441441
#if USE_HERMES
442442
executorFactory = std::make_shared<HermesExecutorFactory>(installBindings);
443-
#else
443+
#elif USE_THIRD_PARTY_JSC != 1
444444
executorFactory = std::make_shared<JSCExecutorFactory>(installBindings);
445+
#else
446+
throw std::runtime_error("No JSExecutorFactory specified.");
445447
#endif
446448
}
447449
} else {
@@ -1107,9 +1109,7 @@ - (void)handleError:(NSError *)error
11071109
/**
11081110
* Prevent super from calling setUp (that'd create another batchedBridge)
11091111
*/
1110-
- (void)setUp
1111-
{
1112-
}
1112+
- (void)setUp {}
11131113

11141114
- (Class)executorClass
11151115
{

packages/react-native/ReactCommon/react/runtime/platform/ios/React-RuntimeApple.podspec

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@ Pod::Spec.new do |s|
7777
s.dependency "hermes-engine"
7878
s.dependency "React-RuntimeHermes"
7979
s.exclude_files = "ReactCommon/RCTJscInstance.{mm,h}"
80+
elsif ENV['USE_THIRD_PARTY_JSC'] == '1'
81+
s.exclude_files = ["ReactCommon/RCTHermesInstance.{mm,h}", "ReactCommon/RCTJscInstance.{mm,h}"]
8082
else
8183
s.dependency "React-jsc"
8284
s.exclude_files = "ReactCommon/RCTHermesInstance.{mm,h}"

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ def setup
2121

2222
def teardown
2323
ENV['HERMES_ENGINE_TARBALL_PATH'] = nil
24+
ENV['USE_THIRD_PARTY_JSC'] = nil
2425
Open3.reset()
2526
Pod::Config.reset()
2627
Pod::UI.reset()
@@ -59,6 +60,19 @@ def test_setupJsc_installsPods_installsFabricSubspecWhenFabricEnabled
5960
assert_equal($podInvocation["React-jsc/Fabric"][:path], "../../ReactCommon/jsc")
6061
end
6162

63+
def test_setupJsc_installsPodsWithThirdPartyJSC
64+
# Arrange
65+
ENV['USE_THIRD_PARTY_JSC'] = '1'
66+
fabric_enabled = false
67+
68+
# Act
69+
setup_jsc!(:react_native_path => @react_native_path, :fabric_enabled => fabric_enabled)
70+
71+
# Assert
72+
assert_equal($podInvocationCount, 1)
73+
assert_equal($podInvocation["React-jsi"][:path], "../../ReactCommon/jsi")
74+
end
75+
6276
# ================== #
6377
# TEST - setupHermes #
6478
# ================== #

0 commit comments

Comments
 (0)