|
1 | 1 | Pod::UI.warn "!!! CONFIGURING HERMES WITH NODE-API SUPPORT !!!" |
2 | 2 |
|
3 | | -if ENV['REACT_NATIVE_OVERRIDE_HERMES_DIR'].nil? |
4 | | - def get_react_native_package |
5 | | - if caller.any? { |frame| frame.include?("node_modules/react-native-macos/") } |
6 | | - return "react-native-macos" |
7 | | - elsif caller.any? { |frame| frame.include?("node_modules/react-native/") } |
8 | | - return "react-native" |
9 | | - else |
10 | | - raise "Unable to determine React Native package from call stack." |
11 | | - end |
| 3 | +def node_api_react_native_package |
| 4 | + if caller.any? { |frame| frame.include?("node_modules/react-native-macos/") } |
| 5 | + return "react-native-macos" |
| 6 | + elsif caller.any? { |frame| frame.include?("node_modules/react-native/") } |
| 7 | + return "react-native" |
| 8 | + else |
| 9 | + raise "Unable to determine React Native package from call stack." |
12 | 10 | end |
| 11 | +end |
| 12 | + |
| 13 | +def node_api_run_cli(command, react_native_package) |
| 14 | + args = [ |
| 15 | + command, |
| 16 | + "--react-native-package", react_native_package, |
| 17 | + "--silent", Pod::Config.instance.installation_root.to_s |
| 18 | + ].map { |arg| "'#{arg}'" }.join(" ") |
| 19 | + result = `npx react-native-node-api #{args}`.strip |
| 20 | + raise "Hermes setup failed: 'react-native-node-api #{command}' exited with #{$?.exitstatus}" unless $?.success? |
| 21 | + result |
| 22 | +end |
13 | 23 |
|
14 | | - VENDORED_HERMES_DIR ||= `npx react-native-node-api vendor-hermes --react-native-package '#{get_react_native_package()}' --silent '#{Pod::Config.instance.installation_root}'`.strip |
15 | | - ENV['REACT_NATIVE_OVERRIDE_HERMES_DIR'] = VENDORED_HERMES_DIR |
| 24 | +if ENV['REACT_NATIVE_OVERRIDE_HERMES_DIR'].nil? && ENV['HERMES_ENGINE_TARBALL_PATH'].nil? |
| 25 | + react_native_package = node_api_react_native_package() |
| 26 | + # Building from source keeps Hermes inside the Xcode build, where it rebuilds |
| 27 | + # incrementally — the faster loop while iterating on Hermes itself. Otherwise |
| 28 | + # the pinned commit is resolved to an archive built once and reused. |
| 29 | + # |
| 30 | + # react-native-macos stays on the source path: the archive is only produced |
| 31 | + # and exercised for the iOS platforms today. |
| 32 | + if ENV['REACT_NATIVE_NODE_API_HERMES_FROM_SOURCE'].to_s == '1' || react_native_package == "react-native-macos" |
| 33 | + ENV['REACT_NATIVE_OVERRIDE_HERMES_DIR'] = node_api_run_cli("vendor-hermes", react_native_package) |
| 34 | + else |
| 35 | + ENV['HERMES_ENGINE_TARBALL_PATH'] = node_api_run_cli("prebuilt-hermes", react_native_package) |
| 36 | + end |
16 | 37 | end |
17 | 38 |
|
18 | 39 | if ENV['REACT_NATIVE_OVERRIDE_HERMES_DIR'] && !ENV['REACT_NATIVE_OVERRIDE_HERMES_DIR'].empty? |
19 | 40 | if Dir.exist?(ENV['REACT_NATIVE_OVERRIDE_HERMES_DIR']) |
20 | | - Pod::UI.info "[Node-API] Using overridden Hermes in #{ENV['REACT_NATIVE_OVERRIDE_HERMES_DIR'].inspect}" |
| 41 | + Pod::UI.info "[Node-API] Building Hermes from source in #{ENV['REACT_NATIVE_OVERRIDE_HERMES_DIR'].inspect}" |
21 | 42 | else |
22 | 43 | raise "Hermes setup failed: Expected override to exist in #{ENV['REACT_NATIVE_OVERRIDE_HERMES_DIR'].inspect}" |
23 | 44 | end |
| 45 | +elsif ENV['HERMES_ENGINE_TARBALL_PATH'] && !ENV['HERMES_ENGINE_TARBALL_PATH'].empty? |
| 46 | + if File.exist?(ENV['HERMES_ENGINE_TARBALL_PATH']) |
| 47 | + Pod::UI.info "[Node-API] Using prebuilt Hermes from #{ENV['HERMES_ENGINE_TARBALL_PATH'].inspect}" |
| 48 | + else |
| 49 | + raise "Hermes setup failed: Expected prebuilt archive to exist at #{ENV['HERMES_ENGINE_TARBALL_PATH'].inspect}" |
| 50 | + end |
24 | 51 | end |
0 commit comments