Skip to content

Commit

Permalink
Make Hermes the default engine on iOS (#34085)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: #34085

Hermes is now the default engine on iOS.

Apps can choose to continue using JSC by setting `hermes_enabled` to `false` in their Podfile.

The RNTester app now uses Hermes, as well. Use JSC in RNTester by setting `USE_HERMES=0` when running `pod install`.

Changelog:

[iOS][Changed] Hermes is now the default engine on iOS. This setting is controlled via `flags[:hermes_enabled]` in the Podfile.

Reviewed By: cortinico, cipolleschi

Differential Revision: D37361468

fbshipit-source-id: e6dda6a23eea4a824ad157d1a26f17e181db33cd
  • Loading branch information
hramos authored and facebook-github-bot committed Jun 28, 2022
1 parent 7d42106 commit 1115bc7
Show file tree
Hide file tree
Showing 9 changed files with 46 additions and 29 deletions.
4 changes: 3 additions & 1 deletion packages/rn-tester/Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ def pods(options = {}, use_flipper: false)
project 'RNTesterPods.xcodeproj'

fabric_enabled = true
hermes_enabled = ENV['USE_HERMES'] == '1'
# 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'
puts "Building RNTester with Fabric #{fabric_enabled ? "enabled" : "disabled"}.#{hermes_enabled ? " Using Hermes engine." : ""}"

if ENV['RCT_NEW_ARCH_ENABLED'] == '1'
Expand Down
2 changes: 1 addition & 1 deletion packages/rn-tester/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ If you are still having a problem after doing the clean up (which can happen if
Both macOS and Xcode are required.
1. `cd packages/rn-tester`
1. Install [Bundler](https://bundler.io/): `gem install bundler`. We use bundler to install the right version of [CocoaPods](https://cocoapods.org/) locally.
1. Install Bundler and CocoaPods dependencies: `bundle install && bundle exec pod install` or `yarn setup-ios-jsc`. In order to use Hermes engine instead of JSC, run: `USE_HERMES=1 bundle exec pod install` or `yarn setup-ios-hermes` instead.
1. Install Bundler and CocoaPods dependencies: `bundle install && bundle exec pod install` or `yarn setup-ios-hermes`. In order to use JSC instead of Hermes engine, run: `USE_HERMES=0 bundle exec pod install` or `yarn setup-ios-jsc` instead.
1. Open the generated `RNTesterPods.xcworkspace`. This is not checked in, as it is generated by CocoaPods. Do not open `RNTesterPods.xcodeproj` directly.

#### Note for M1 users
Expand Down
2 changes: 1 addition & 1 deletion packages/rn-tester/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"install-android-jsc": "../../gradlew :packages:rn-tester:android:app:installJscDebug",
"install-android-hermes": "../../gradlew :packages:rn-tester:android:app:installHermesDebug",
"clean-android": "rm -rf android/app/build",
"setup-ios-jsc": "bundle install && bundle exec pod install",
"setup-ios-jsc": "bundle install && USE_HERMES=0 bundle exec pod install",
"setup-ios-hermes": "bundle install && USE_HERMES=1 bundle exec pod install",
"clean-ios": "rm -rf build/generated/ios && rm -rf Pods && rm Podfile.lock"
},
Expand Down
28 changes: 22 additions & 6 deletions scripts/cocoapods/__tests__/utils-test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def teardown
SysctlChecker.reset()
Environment.reset()
ENV['RCT_NEW_ARCH_ENABLED'] = '0'
ENV['USE_HERMES'] = '0'
ENV['USE_HERMES'] = '1'
end

# ======================= #
Expand Down Expand Up @@ -75,30 +75,30 @@ def test_warnIfNotOnArm64_whenSysctlReturns1AndRubyNotIncludeArm64_warns
def test_getDefaultFlag_whenOldArchitecture()
# Arrange
ENV['RCT_NEW_ARCH_ENABLED'] = '0'
ENV['USE_HERMES'] = '0'

# Act
flags = ReactNativePodsUtils.get_default_flags()

# Assert
assert_equal(flags, {
:fabric_enabled => false,
:hermes_enabled => false,
:hermes_enabled => true,
:flipper_configuration => FlipperConfiguration.disabled
})
end

def test_getDefaultFlag_whenOldArchitectureButHermesEnabled()
def test_getDefaultFlag_whenOldArchitectureButHermesDisabled()
# Arrange
ENV['RCT_NEW_ARCH_ENABLED'] = '0'
ENV['USE_HERMES'] = '1'
ENV['USE_HERMES'] = '0'

# Act
flags = ReactNativePodsUtils.get_default_flags()

# Assert
assert_equal(flags, {
:fabric_enabled => false,
:hermes_enabled => true,
:hermes_enabled => false,
:flipper_configuration => FlipperConfiguration.disabled
})
end
Expand All @@ -118,6 +118,22 @@ def test_getDefaultFlag_whenNewArchitecture()
})
end

def test_getDefaultFlag_whenNewArchitectureButHermesDisabled()
# Arrange
ENV['RCT_NEW_ARCH_ENABLED'] = '1'
ENV['USE_HERMES'] = '0'

# Act
flags = ReactNativePodsUtils.get_default_flags()

# Assert
assert_equal(flags, {
:fabric_enabled => true,
:hermes_enabled => false,
:flipper_configuration => FlipperConfiguration.disabled
})
end

# ============== #
# TEST - has_pod #
# ============== #
Expand Down
6 changes: 3 additions & 3 deletions scripts/cocoapods/utils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def self.warn_if_not_on_arm64
def self.get_default_flags
flags = {
:fabric_enabled => false,
:hermes_enabled => false,
:hermes_enabled => true,
:flipper_configuration => FlipperConfiguration.disabled
}

Expand All @@ -28,8 +28,8 @@ def self.get_default_flags
flags[:hermes_enabled] = true
end

if ENV['USE_HERMES'] == '1'
flags[:hermes_enabled] = true
if ENV['USE_HERMES'] == '0'
flags[:hermes_enabled] = false
end

return flags
Expand Down
21 changes: 10 additions & 11 deletions scripts/react-native-xcode.sh
Original file line number Diff line number Diff line change
Expand Up @@ -78,16 +78,15 @@ fi
# shellcheck source=/dev/null
source "$REACT_NATIVE_DIR/scripts/node-binary.sh"

[ -z "$HERMES_CLI_PATH" ] && HERMES_CLI_PATH="$PODS_ROOT/hermes-engine/destroot/bin/hermesc"

if [[ -z "$USE_HERMES" && -f "$HERMES_CLI_PATH" ]]; then
echo "Enabling Hermes byte-code compilation. Disable with USE_HERMES=false if needed."
USE_HERMES=true
fi

if [[ $USE_HERMES == true && ! -f "$HERMES_CLI_PATH" ]]; then
echo "error: USE_HERMES is set to true but the hermesc binary could not be " \
"found at ${HERMES_CLI_PATH}. Perhaps you need to run 'bundle exec pod install' or otherwise " \
HERMES_ENGINE_PATH="$PODS_ROOT/hermes-engine"
[ -z "$HERMES_CLI_PATH" ] && HERMES_CLI_PATH="$HERMES_ENGINE_PATH/destroot/bin/hermesc"

# Hermes is enabled in new projects by default, so we cannot assume that USE_HERMES=1 is set as an envvar.
# If hermes-engine is found in Pods, we can assume Hermes has not been disabled.
# If hermesc is not available and USE_HERMES is either unset or true, show error.
if [[ -f "$HERMES_ENGINE_PATH" && ! -f "$HERMES_CLI_PATH" ]]; then
echo "error: Hermes is enabled but the hermesc binary could not be found at ${HERMES_CLI_PATH}." \
"Perhaps you need to run 'bundle exec pod install' or otherwise " \
"point the HERMES_CLI_PATH variable to your custom location." >&2
exit 2
fi
Expand Down Expand Up @@ -179,4 +178,4 @@ if [[ $DEV != true && ! -f "$BUNDLE_FILE" ]]; then
echo "error: File $BUNDLE_FILE does not exist. This must be a bug with" >&2
echo "React Native, please report it here: https://github.com/facebook/react-native/issues"
exit 2
fi
fi
2 changes: 1 addition & 1 deletion scripts/react_native_pods.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def use_react_native! (options={})
production = options[:production] ||= false

# Include Hermes dependencies
hermes_enabled = options[:hermes_enabled] ||= false
hermes_enabled = options[:hermes_enabled] ||= true

flipper_configuration = options[:flipper_configuration] ||= FlipperConfiguration.disabled

Expand Down
3 changes: 1 addition & 2 deletions scripts/test-manual-e2e.sh
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ test_ios_jsc(){
success "About to test iOS JSC... "
success "Installing CocoaPods dependencies..."
rm -rf packages/rn-tester/Pods
(cd packages/rn-tester && bundle exec pod install)
(cd packages/rn-tester && USE_HERMES=0 bundle exec pod install)

info "Press any key to open the workspace in Xcode, then build and test manually."
info ""
Expand Down Expand Up @@ -232,4 +232,3 @@ init(){
}

init

7 changes: 4 additions & 3 deletions template/ios/Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@ target 'HelloWorld' do

use_react_native!(
:path => config[:reactNativePath],
# By default, Hermes is disabled on Old Architecture, and enabled on New Architecture.
# You can enabled/disable it manually by replacing `flags[:hermes_enabled]` with `true` or `false`.
:hermes_enabled => flags[:hermes_enabled],
# Hermes is now enabled by default. Disable by setting this flag to false.
# Upcoming versions of React Native may rely on get_default_flags(), but
# we make it explicit here to aid in the React Native upgrade process.
:hermes_enabled => true,
:fabric_enabled => flags[:fabric_enabled],
# Enables Flipper.
#
Expand Down

0 comments on commit 1115bc7

Please sign in to comment.