Skip to content

Commit 2bcaeb1

Browse files
shwantonShawn Dempsey
and
Shawn Dempsey
authored
[RN][macos] Enable Hermes for RNTester (#1308)
Summary: **Context** On Core RN, Hermes for iOS can be enabled by setting a flag in the Podfile https://reactnative.dev/docs/hermes#ios | Since React Native 0.64, Hermes also runs on iOS. To enable Hermes for iOS, edit your ios/Podfile file and make the change illustrated below: ``` use_react_native!( :path => config[:reactNativePath], # to enable hermes on iOS, change `false` to `true` and then install pods # By default, Hermes is disabled on Old Architecture, and enabled on New Architecture. # You can enable/disable it manually by replacing `flags[:hermes_enabled]` with `true` or `false`. :hermes_enabled => true ) ``` In the RNTester Podfile, Hermes is enabled using envvar: https://github.com/facebook/react-native/blob/main/packages/rn-tester/Podfile#L27 ``` # Hermes is now enabled by default. # The following line will only disable Hermes if the USE_HERMES envvar is SET to a value other than 1 (e.g. USE_HERMES=0). hermes_enabled = !ENV.has_key?('USE_HERMES') || ENV['USE_HERMES'] == '1' ``` Build command: `USE_HERMES=1 bundle exec pod install` This will install the Hermes runtime Pod (not build it from scratch) & thus enable the `RCT_USE_HERMES` macro. https://www.internalfb.com/code/fbsource/[9f57823a75a40d3f8559c8f1b7ae0add8e95d6dc]/xplat/js/react-native-github/packages/rn-tester/RNTester/AppDelegate.mm?lines=10-16 --- The documentation for enabling Hermes on RN Desktop macOS are outdated: https://microsoft.github.io/react-native-windows/docs/hermes#hermes-on-macos > Install the npm package yarn add 'hermes-engine-darwin@^0.4.3' * `hermes-engine-darwin` is no longer required > Add (or uncomment) the following pod dependencies to your macOS target in your Podfile: pod 'React-Core/Hermes', :path => '../node_modules/react-native-macos/' pod 'hermes', :path => '../node_modules/hermes-engine-darwin' pod 'libevent', :podspec => '../node_modules/react-native-macos/third-party-podspecs/libevent.podspec' * Setting `USE_HERMES=1` during `pod install= replaces all of this > Copy Run pod install Be sure to set your target's deployment target to at least 10.14 before running pod install * `USE_HERMES=1 bundle exec pod install --verbose` --- On RN Desktop, the Hermes flag was [set to false](#780) due to M1 build reasons which have since been resolved. - #952 - #781 Curiously, the `RNTester-macOS` target AppDelegate was never updated to import & use Hermes when `RCT_USE_HERMES` was `true`. Only the `RNTester` for mobile had the correct Hermes usage. **RNTester-macOS:** https://github.com/microsoft/react-native-macos/blob/main/packages/rn-tester/RNTester-macOS/AppDelegate.mm **RNTester:** https://github.com/microsoft/react-native-macos/blob/main/packages/rn-tester/RNTester/AppDelegate.mm **Change** * Remove `pods(:hermes_enabled => true)` in favor of passing `USE_HERMES=1` to `pod install` (This is how it's done on RNTester iOS) * Copy Hermes support to `RNTester-macOS` AppDelegate Test Plan: **Install from scratch** Differential Revision: https://phabricator.intern.facebook.com/D38277077 Co-authored-by: Shawn Dempsey <[email protected]>
1 parent 4a3b4bf commit 2bcaeb1

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

packages/rn-tester/Podfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ end
8686

8787
target 'RNTester-macOS' do
8888
platform :osx, '10.15'
89-
pods(:hermes_enabled => false)
89+
pods()
9090
end
9191

9292
target 'RNTester-macOSUnitTests' do

packages/rn-tester/RNTester-macOS/AppDelegate.mm

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,21 @@
88

99
#import "AppDelegate.h"
1010

11-
#import <React/CoreModulesPlugins.h>
11+
#ifndef RCT_USE_HERMES
12+
#if __has_include(<reacthermes/HermesExecutorFactory.h>)
13+
#define RCT_USE_HERMES 1
14+
#else
15+
#define RCT_USE_HERMES 0
16+
#endif
17+
#endif
18+
19+
#if RCT_USE_HERMES
20+
#import <reacthermes/HermesExecutorFactory.h>
21+
#else
1222
#import <React/JSCExecutorFactory.h>
23+
#endif
24+
25+
#import <React/CoreModulesPlugins.h>
1326
#import <React/RCTBridge.h>
1427
#import <React/RCTBundleURLProvider.h>
1528
#import <React/RCTCxxBridgeDelegate.h>
@@ -106,7 +119,11 @@ - (NSURL *)sourceURLForBridge:(__unused RCTBridge *)bridge
106119
#endif
107120

108121
__weak __typeof(self) weakSelf = self;
122+
#if RCT_USE_HERMES
123+
return std::make_unique<facebook::react::HermesExecutorFactory>(
124+
#else
109125
return std::make_unique<facebook::react::JSCExecutorFactory>(
126+
#endif
110127
facebook::react::RCTJSIExecutorRuntimeInstaller([weakSelf, bridge](facebook::jsi::Runtime &runtime) {
111128
if (!bridge) {
112129
return;

0 commit comments

Comments
 (0)