From 6f0ecf3570cadbf3025299509af0eecd39e945d8 Mon Sep 17 00:00:00 2001 From: Riccardo Cipolleschi Date: Fri, 24 Nov 2023 03:15:14 -0800 Subject: [PATCH] Unify usage of USE_HERMES flag (#41625) Summary: To tell React Native whether we are building with hermes or not on iOS, we were using 2 different build time flags: - USE_HERMES - RCT_USE_HERMES The first was widely used by the OSS use case, while the latter was set internally. Worse than that, their default values were the opposite and we were never setting the RCT_USE_HERMES explicitly with Cocoapods, while there was some piece of code that was trying to "smartly" detect whether Hermes was included or not. This change unifies the behavior, removing the "smartness" in favor od a declarative approach. ## Changelog: [Internal] - Unify the USE_HERMES flags Differential Revision: D51549284 --- packages/react-native/React-Core.podspec | 3 ++- packages/react-native/React/CxxBridge/RCTCxxBridge.mm | 10 +++++----- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/packages/react-native/React-Core.podspec b/packages/react-native/React-Core.podspec index 101b5e9cc10056..e2b1ed82b7622b 100644 --- a/packages/react-native/React-Core.podspec +++ b/packages/react-native/React-Core.podspec @@ -22,6 +22,7 @@ socket_rocket_version = '0.7.0' boost_compiler_flags = '-Wno-documentation' use_hermes = ENV['USE_HERMES'] == nil || ENV['USE_HERMES'] == '1' +use_hermes_flag = use_hermes ? "-DUSE_HERMES=1" : "" header_subspecs = { 'CoreModulesHeaders' => 'React/CoreModules/**/*.h', @@ -63,7 +64,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 + s.compiler_flags = folly_compiler_flags + ' ' + boost_compiler_flags + ' ' + use_hermes_flag s.header_dir = "React" s.framework = "JavaScriptCore" s.pod_target_xcconfig = { diff --git a/packages/react-native/React/CxxBridge/RCTCxxBridge.mm b/packages/react-native/React/CxxBridge/RCTCxxBridge.mm index af931fd45ca10f..c6807c194e5682 100644 --- a/packages/react-native/React/CxxBridge/RCTCxxBridge.mm +++ b/packages/react-native/React/CxxBridge/RCTCxxBridge.mm @@ -41,15 +41,15 @@ #import #import -#ifndef RCT_USE_HERMES +#ifndef USE_HERMES #if __has_include() -#define RCT_USE_HERMES 1 +#define USE_HERMES 1 #else -#define RCT_USE_HERMES 0 +#define USE_HERMES 0 #endif #endif -#if RCT_USE_HERMES +#if USE_HERMES #import #else #import "JSCExecutorFactory.h" @@ -423,7 +423,7 @@ - (void)start } if (!executorFactory) { auto installBindings = RCTJSIExecutorRuntimeInstaller(nullptr); -#if RCT_USE_HERMES +#if USE_HERMES executorFactory = std::make_shared(installBindings); #else executorFactory = std::make_shared(installBindings);