Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/react-native/Libraries/AppDelegate/RCTAppDelegate.mm
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@
#import <React/RCTComponentViewProtocol.h>
#if USE_HERMES
#import <ReactCommon/RCTHermesInstance.h>
#else
#elif USE_THIRD_PARTY_JSC != 1
#import <ReactCommon/RCTJscInstance.h>
#endif
#endif // USE_HERMES
#import <react/nativemodule/defaults/DefaultTurboModules.h>

using namespace facebook::react;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,11 @@
#elif __has_include(<reacthermes/HermesExecutorFactory.h>)
#import <reacthermes/HermesExecutorFactory.h>
#endif
#else // USE_HERMES
#elif USE_THIRD_PARTY_JSC != 1
#import <React/JSCExecutorFactory.h>
#endif // USE_HERMES

#import <jsireact/JSIExecutor.h>
#import <ReactCommon/RCTTurboModuleManager.h>

@protocol RCTDependencyProvider;
Expand Down
49 changes: 29 additions & 20 deletions packages/react-native/Libraries/AppDelegate/RCTAppSetupUtils.mm
Original file line number Diff line number Diff line change
Expand Up @@ -130,38 +130,47 @@ void RCTAppSetupPrepareApp(UIApplication *application, BOOL turboModuleEnabled)
[turboModuleManager moduleForName:"RCTDevMenu"];
#endif // end RCT_DEV

auto runtimeInstallerLambda = [turboModuleManager, bridge, runtimeScheduler](facebook::jsi::Runtime &runtime) {
if (!bridge || !turboModuleManager) {
return;
}
if (runtimeScheduler) {
facebook::react::RuntimeSchedulerBinding::createAndInstallIfNeeded(runtime, runtimeScheduler);
}
[turboModuleManager installJSBindings:runtime];
};
#if USE_HERMES
return std::make_unique<facebook::react::HermesExecutorFactory>(
Comment thread
Kudo marked this conversation as resolved.
#else
facebook::react::RCTJSIExecutorRuntimeInstaller(runtimeInstallerLambda));
#elif USE_THIRD_PARTY_JSC != 1
return std::make_unique<facebook::react::JSCExecutorFactory>(
facebook::react::RCTJSIExecutorRuntimeInstaller(runtimeInstallerLambda));
#else
throw std::runtime_error("No JSExecutorFactory specified.");
return nullptr;
#endif // USE_HERMES
facebook::react::RCTJSIExecutorRuntimeInstaller(
[turboModuleManager, bridge, runtimeScheduler](facebook::jsi::Runtime &runtime) {
if (!bridge || !turboModuleManager) {
return;
}
if (runtimeScheduler) {
facebook::react::RuntimeSchedulerBinding::createAndInstallIfNeeded(runtime, runtimeScheduler);
}
[turboModuleManager installJSBindings:runtime];
}));
}

std::unique_ptr<facebook::react::JSExecutorFactory> RCTAppSetupJsExecutorFactoryForOldArch(
RCTBridge *bridge,
const std::shared_ptr<facebook::react::RuntimeScheduler> &runtimeScheduler)
{
auto runtimeInstallerLambda = [bridge, runtimeScheduler](facebook::jsi::Runtime &runtime) {
if (!bridge) {
return;
}
if (runtimeScheduler) {
facebook::react::RuntimeSchedulerBinding::createAndInstallIfNeeded(runtime, runtimeScheduler);
}
};
#if USE_HERMES
return std::make_unique<facebook::react::HermesExecutorFactory>(
#else
facebook::react::RCTJSIExecutorRuntimeInstaller(runtimeInstallerLambda));
#elif USE_THIRD_PARTY_JSC != 1
return std::make_unique<facebook::react::JSCExecutorFactory>(
facebook::react::RCTJSIExecutorRuntimeInstaller(runtimeInstallerLambda));
#else
throw std::runtime_error("No JSExecutorFactory specified.");
return nullptr;
#endif // USE_HERMES
facebook::react::RCTJSIExecutorRuntimeInstaller([bridge, runtimeScheduler](facebook::jsi::Runtime &runtime) {
if (!bridge) {
return;
}
if (runtimeScheduler) {
facebook::react::RuntimeSchedulerBinding::createAndInstallIfNeeded(runtime, runtimeScheduler);
}
}));
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@
#import <React/RCTComponentViewProtocol.h>
#if USE_HERMES
#import <ReactCommon/RCTHermesInstance.h>
#else
#elif USE_THIRD_PARTY_JSC != 1
#import <ReactCommon/RCTJscInstance.h>
#endif
#endif // USE_HERMES
#import <react/nativemodule/defaults/DefaultTurboModules.h>

#import "RCTDependencyProvider.h"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,10 @@
#import <React/RCTSurfacePresenter.h>
#if USE_HERMES
#import <ReactCommon/RCTHermesInstance.h>
#else
#elif USE_THIRD_PARTY_JSC != 1
#import <ReactCommon/RCTJscInstance.h>
#endif
#else
#endif // USE_HERMES
#import <ReactCommon/RCTHost+Internal.h>
#import <ReactCommon/RCTHost.h>
#import <ReactCommon/RCTTurboModuleManager.h>
Expand Down Expand Up @@ -265,8 +266,10 @@ - (RCTHost *)createReactHost:(NSDictionary *)launchOptions
{
#if USE_HERMES
return std::make_shared<facebook::react::RCTHermesInstance>(nullptr, /* allocInOldGenBeforeTTI */ false);
#else
#elif USE_THIRD_PARTY_JSC != 1
return std::make_shared<facebook::react::RCTJscInstance>();
#else
throw std::runtime_error("No JSRuntimeFactory specified.");
#endif
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ use_hermes = ENV['USE_HERMES'] == nil || ENV['USE_HERMES'] == '1'

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

header_search_paths = [
"$(PODS_TARGET_SRCROOT)/../../ReactCommon",
Expand Down
5 changes: 3 additions & 2 deletions packages/react-native/React-Core.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ boost_compiler_flags = boost_config[:compiler_flags]

use_hermes = ENV['USE_HERMES'] == nil || ENV['USE_HERMES'] == '1'
use_hermes_flag = use_hermes ? "-DUSE_HERMES=1" : ""
use_third_party_jsc_flag = ENV['USE_THIRD_PARTY_JSC'] == '1' ? "-DUSE_THIRD_PARTY_JSC=1" : ""

header_subspecs = {
'CoreModulesHeaders' => 'React/CoreModules/**/*.h',
Expand Down Expand Up @@ -70,7 +71,7 @@ Pod::Spec.new do |s|
s.platforms = min_supported_versions
s.source = source
s.resource_bundle = { "RCTI18nStrings" => ["React/I18n/strings/*.lproj"]}
s.compiler_flags = folly_compiler_flags + ' ' + boost_compiler_flags + ' ' + use_hermes_flag
s.compiler_flags = folly_compiler_flags + ' ' + boost_compiler_flags + ' ' + use_hermes_flag + ' ' + use_third_party_jsc_flag
s.header_dir = "React"
s.weak_framework = "JavaScriptCore"
s.pod_target_xcconfig = {
Expand All @@ -95,7 +96,7 @@ Pod::Spec.new do |s|
]
# If we are using Hermes (the default is use hermes, so USE_HERMES can be nil), we don't have jsc installed
# So we have to exclude the JSCExecutorFactory
if use_hermes
if use_hermes || ENV['USE_THIRD_PARTY_JSC'] == '1'
exclude_files = exclude_files.append("React/CxxBridge/JSCExecutorFactory.{h,mm}")
end
ss.exclude_files = exclude_files
Expand Down
6 changes: 4 additions & 2 deletions packages/react-native/React/CxxBridge/RCTCxxBridge.mm
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@

#if USE_HERMES
#import <reacthermes/HermesExecutorFactory.h>
#else
#elif USE_THIRD_PARTY_JSC != 1
#import "JSCExecutorFactory.h"
#endif
#import "RCTJSIExecutorRuntimeInstaller.h"
Expand Down Expand Up @@ -440,8 +440,10 @@ - (void)start
auto installBindings = RCTJSIExecutorRuntimeInstaller(nullptr);
#if USE_HERMES
executorFactory = std::make_shared<HermesExecutorFactory>(installBindings);
#else
#elif USE_THIRD_PARTY_JSC != 1
executorFactory = std::make_shared<JSCExecutorFactory>(installBindings);
#else
throw std::runtime_error("No JSExecutorFactory specified.");
#endif
}
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ Pod::Spec.new do |s|
s.dependency "hermes-engine"
s.dependency "React-RuntimeHermes"
s.exclude_files = "ReactCommon/RCTJscInstance.{mm,h}"
elsif ENV['USE_THIRD_PARTY_JSC'] == '1'
s.exclude_files = ["ReactCommon/RCTHermesInstance.{mm,h}", "ReactCommon/RCTJscInstance.{mm,h}"]
else
s.dependency "React-jsc"
s.exclude_files = "ReactCommon/RCTHermesInstance.{mm,h}"
Expand Down
14 changes: 14 additions & 0 deletions packages/react-native/scripts/cocoapods/__tests__/jsengine-test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ def setup

def teardown
ENV['HERMES_ENGINE_TARBALL_PATH'] = nil
ENV['USE_THIRD_PARTY_JSC'] = nil
Open3.reset()
Pod::Config.reset()
Pod::UI.reset()
Expand Down Expand Up @@ -59,6 +60,19 @@ def test_setupJsc_installsPods_installsFabricSubspecWhenFabricEnabled
assert_equal($podInvocation["React-jsc/Fabric"][:path], "../../ReactCommon/jsc")
end

def test_setupJsc_installsPodsWithThirdPartyJSC
# Arrange
ENV['USE_THIRD_PARTY_JSC'] = '1'
fabric_enabled = false

# Act
setup_jsc!(:react_native_path => @react_native_path, :fabric_enabled => fabric_enabled)

# Assert
assert_equal($podInvocationCount, 1)
assert_equal($podInvocation["React-jsi"][:path], "../../ReactCommon/jsi")
end

# ================== #
# TEST - setupHermes #
# ================== #
Expand Down
10 changes: 6 additions & 4 deletions packages/react-native/scripts/cocoapods/jsengine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@
# @parameter react_native_path: relative path to react-native
# @parameter fabric_enabled: whether Fabirc is enabled
def setup_jsc!(react_native_path: "../node_modules/react-native", fabric_enabled: false)
pod 'React-jsc', :path => "#{react_native_path}/ReactCommon/jsc"
if fabric_enabled
pod 'React-jsc/Fabric', :path => "#{react_native_path}/ReactCommon/jsc"
if ENV['USE_THIRD_PARTY_JSC'] != '1'
pod 'React-jsc', :path => "#{react_native_path}/ReactCommon/jsc"
if fabric_enabled
pod 'React-jsc/Fabric', :path => "#{react_native_path}/ReactCommon/jsc"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not even sure that this subspec is actually needed...

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe not but that feels out of scope toward this pr. maybe we can update that in a separate pr?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can create a separate one with removal

end
end
end

Expand All @@ -35,7 +37,7 @@ def depend_on_js_engine(s)
if ENV["USE_HERMES"] == nil || ENV["USE_HERMES"] == "1"
s.dependency 'hermes-engine'
s.dependency 'React-hermes'
else
elsif ENV['USE_THIRD_PARTY_JSC'] != '1'
s.dependency 'React-jsc'
Comment thread
Kudo marked this conversation as resolved.
end
end
8 changes: 6 additions & 2 deletions packages/react-native/scripts/cocoapods/utils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -600,7 +600,7 @@ def self.set_imagemanager_search_path(target_installation_result)
end

def self.react_native_pods
return [
pods = [
"DoubleConversion",
"FBLazyVector",
"RCT-Folly",
Expand Down Expand Up @@ -629,7 +629,6 @@ def self.react_native_pods
"React-callinvoker",
"React-cxxreact",
"React-graphics",
"React-jsc",
"React-jsi",
"React-jsiexecutor",
"React-jsinspector",
Expand All @@ -647,6 +646,11 @@ def self.react_native_pods
"hermes-engine",
"React-hermes",
]
if ENV['USE_THIRD_PARTY_JSC'] != '1'
pods << "React-jsc"
end

return pods
end

def self.add_search_path_to_result(result, base_path, additional_paths, include_base_path)
Expand Down