Skip to content

Commit e8bbe48

Browse files
tido64matthargett
andauthored
fix(react-native-host): fix community JSC support (#3854)
Fix compile error in `ReactNativeHost.mm` when Hermes is not being used. `fatal error: 'ReactCommon/RCTHermesInstance.h' file not found` The `USE_HERMES` preprocessor definition was only being set in `GCC_PREPROCESSOR_DEFINITIONS` (for C and Objective-C files), but NOT in `CPP_PREPROCESSOR_DEFINITIONS` (for [Objective] C++) files. This caused `ReactNativeHost.mm` to NOT receive the `USE_HERMES=0` flag, making it incorrectly import Hermes symbols that aren't resolved at link time. Co-authored-by: Matt Hargett <plaztiksyke@gmail.com>
1 parent 960b594 commit e8bbe48

File tree

4 files changed

+28
-5
lines changed

4 files changed

+28
-5
lines changed

.changeset/cold-colts-add.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
---
2+
"@rnx-kit/react-native-host": patch
3+
---
4+
5+
Fixed community JSC support.
6+
7+
Fix compile error in `ReactNativeHost.mm` when Hermes is not being used.
8+
`fatal error: 'ReactCommon/RCTHermesInstance.h' file not found`
9+
10+
The `USE_HERMES` preprocessor definition was only being set in
11+
`GCC_PREPROCESSOR_DEFINITIONS` (for C and Objective-C files), but NOT in
12+
`CPP_PREPROCESSOR_DEFINITIONS` (for [Objective] C++) files. This caused
13+
`ReactNativeHost.mm` to NOT receive the `USE_HERMES=0` flag, making it
14+
incorrectly import Hermes symbols that aren't resolved at link time.

packages/react-native-host/ReactNativeHost.podspec

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,10 @@ repo_dir = repository['directory']
1010

1111
new_arch_enabled = ENV['RCT_NEW_ARCH_ENABLED'] == '1'
1212
preprocessor_definitions = [
13-
'$(inherit)',
13+
'$(inherited)',
1414
"USE_HERMES=#{ENV['USE_HERMES'] || '0'}",
15+
"USE_THIRD_PARTY_JSC=#{ENV['USE_THIRD_PARTY_JSC'] || '0'}",
16+
"USE_V8=#{ENV['USE_V8'] || '0'}",
1517
]
1618
if new_arch_enabled
1719
preprocessor_definitions << 'RCT_NEW_ARCH_ENABLED=1'
@@ -49,6 +51,7 @@ Pod::Spec.new do |s|
4951
'CLANG_CXX_LANGUAGE_STANDARD' => 'c++20',
5052
'DEFINES_MODULE' => 'YES',
5153
'GCC_PREPROCESSOR_DEFINITIONS' => preprocessor_definitions,
54+
'CPP_PREPROCESSOR_DEFINITIONS' => preprocessor_definitions,
5255
'HEADER_SEARCH_PATHS' => [
5356
'$(PODS_ROOT)/Headers/Private/React-Core',
5457
'$(PODS_CONFIGURATION_BUILD_DIR)/React-RuntimeApple/React_RuntimeApple.framework/Headers',

packages/react-native-host/cocoa/RNXBridgelessHeaders.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,13 @@
88

99
#if USE_HERMES
1010
#import <ReactCommon/RCTHermesInstance.h>
11+
#elif USE_V8
12+
#import <v8runtime/V8ExecutorFactory.h>
13+
#elif __has_include(<React-jsc/RCTJscInstance.h>)
14+
#import <React-jsc/RCTJscInstance.h>
1115
#else
12-
#import <ReactCommon/RCTJscInstance.h>
13-
#endif // USE_HERMES
16+
#import <ReactCommon/RCTJscInstance.h> // RN pre 0.80
17+
#endif // USE_HERMES
1418

1519
#ifdef USE_REACT_NATIVE_CONFIG
1620
#import <react/config/ReactNativeConfig.h>

packages/react-native-host/cocoa/ReactNativeHost.mm

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -296,9 +296,11 @@ - (void)initializeReactHost
296296
#else
297297
return std::make_shared<facebook::react::RCTHermesInstance>(nullptr, false);
298298
#endif // USE_REACT_NATIVE_CONFIG
299-
#else // USE_HERMES
299+
#elif USE_V8
300+
return std::make_shared<facebook::react::V8ExecutorFactory>();
301+
#else
300302
return std::make_shared<facebook::react::RCTJscInstance>();
301-
#endif // USE_HERMES
303+
#endif
302304
};
303305

304306
__weak __typeof(self) weakSelf = self;

0 commit comments

Comments
 (0)