diff --git a/packages/rn-tester/Podfile b/packages/rn-tester/Podfile index 24130f1874ce5c..4a3cd57f37f5c4 100644 --- a/packages/rn-tester/Podfile +++ b/packages/rn-tester/Podfile @@ -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' diff --git a/packages/rn-tester/README.md b/packages/rn-tester/README.md index 553dc70f45a6b8..688b061cbe8f9f 100644 --- a/packages/rn-tester/README.md +++ b/packages/rn-tester/README.md @@ -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 diff --git a/packages/rn-tester/package.json b/packages/rn-tester/package.json index aa37800cc1bd0a..c201f167c2eb7d 100644 --- a/packages/rn-tester/package.json +++ b/packages/rn-tester/package.json @@ -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" }, diff --git a/scripts/cocoapods/__tests__/utils-test.rb b/scripts/cocoapods/__tests__/utils-test.rb index 410af249835e00..51bd853f8a2540 100644 --- a/scripts/cocoapods/__tests__/utils-test.rb +++ b/scripts/cocoapods/__tests__/utils-test.rb @@ -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 # ======================= # @@ -75,22 +75,22 @@ 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() @@ -98,7 +98,7 @@ def test_getDefaultFlag_whenOldArchitectureButHermesEnabled() # Assert assert_equal(flags, { :fabric_enabled => false, - :hermes_enabled => true, + :hermes_enabled => false, :flipper_configuration => FlipperConfiguration.disabled }) end @@ -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 # # ============== # diff --git a/scripts/cocoapods/utils.rb b/scripts/cocoapods/utils.rb index 6ea8db0c3847a5..4e76a9cbb5fa55 100644 --- a/scripts/cocoapods/utils.rb +++ b/scripts/cocoapods/utils.rb @@ -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 } @@ -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 diff --git a/scripts/react-native-xcode.sh b/scripts/react-native-xcode.sh index 1eca138eaf2fcb..2dc4f667bafcbe 100755 --- a/scripts/react-native-xcode.sh +++ b/scripts/react-native-xcode.sh @@ -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 @@ -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 \ No newline at end of file +fi diff --git a/scripts/react_native_pods.rb b/scripts/react_native_pods.rb index 6f9a54b96247fc..2c1dc6187a4980 100644 --- a/scripts/react_native_pods.rb +++ b/scripts/react_native_pods.rb @@ -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 diff --git a/scripts/test-manual-e2e.sh b/scripts/test-manual-e2e.sh index 24a01fb3232fae..a98f74b662ac4e 100755 --- a/scripts/test-manual-e2e.sh +++ b/scripts/test-manual-e2e.sh @@ -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 "" @@ -232,4 +232,3 @@ init(){ } init - diff --git a/template/ios/Podfile b/template/ios/Podfile index 938146d23e839b..38d48aef179f42 100644 --- a/template/ios/Podfile +++ b/template/ios/Podfile @@ -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. #