Skip to content

Commit

Permalink
Hermes: Use shared JSI from React Native on iOS (facebook#33885)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: facebook#33885

When building Hermes for React Native, point to the React Native JSI location to ensure both React Native and Hermes use the exact same version of JSI.

Changelog:
[iOS] [Changed] - When Hermes is enabled, it will use the same copy of JSI as React Native

Differential Revision: D36567471

fbshipit-source-id: 5d1fda8a2576f1069795f650460480511717283b
  • Loading branch information
hramos authored and facebook-github-bot committed May 22, 2022
1 parent fcebeac commit 4c18d8e
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 24 deletions.
48 changes: 24 additions & 24 deletions scripts/react_native_pods.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,30 @@ def use_react_native! (options={})

pod 'React-bridging', :path => "#{prefix}/ReactCommon/react/bridging"
pod 'React-cxxreact', :path => "#{prefix}/ReactCommon/cxxreact"

if hermes_enabled
pod 'React-hermes', :path => "#{prefix}/ReactCommon/hermes"
pod 'libevent', '~> 2.1.12'

sdks_dir = Pod::Config.instance.installation_root.join(prefix, "sdks")
hermes_tag_file = sdks_dir.join(".hermesversion")

if (File.exist?(hermes_tag_file))
# Use published pod with pre-builts.
Pod::UI.puts "[Hermes] Tag file exists at path: #{hermes_tag_file}"
package = JSON.parse(File.read(File.join(__dir__, "..", "package.json")))
hermes_version = package['version']
Pod::UI.puts "[Hermes] Loading version: #{hermes_version}"
pod 'hermes-engine', hermes_version
else
# Use local podspec and build from source.
path_to_hermes = "#{prefix}/sdks/hermes/hermes-engine.podspec"
Pod::UI.puts "[Hermes] Use local version from #{path_to_hermes}"
system("(cd #{prefix} && node scripts/hermes/prepare-hermes-for-build)")
pod 'hermes-engine', :path => path_to_hermes
end
end

pod 'React-jsi', :path => "#{prefix}/ReactCommon/jsi"
pod 'React-jsiexecutor', :path => "#{prefix}/ReactCommon/jsiexecutor"
pod 'React-jsinspector', :path => "#{prefix}/ReactCommon/jsinspector"
Expand Down Expand Up @@ -104,30 +128,6 @@ def use_react_native! (options={})
setup_fabric!(prefix)
end

if hermes_enabled
pod 'React-hermes', :path => "#{prefix}/ReactCommon/hermes"
pod 'libevent', '~> 2.1.12'

sdks_dir = Pod::Config.instance.installation_root.join(prefix, "sdks")
hermes_tag_file = sdks_dir.join(".hermesversion")

if (File.exist?(hermes_tag_file))
# Use published pod with pre-builts.
Pod::UI.puts "[Hermes] Tag file exists at path: #{hermes_tag_file}"
package = JSON.parse(File.read(File.join(__dir__, "..", "package.json")))
hermes_version = package['version']
Pod::UI.puts "[Hermes] Loading version: #{hermes_version}"
pod 'hermes-engine', hermes_version
else
# Use local podspec and build from source.
path_to_hermes = "#{prefix}/sdks/hermes/hermes-engine.podspec"
Pod::UI.puts "[Hermes] Use local version from #{path_to_hermes}"
system("(cd #{prefix} && node scripts/hermes/prepare-hermes-for-build)")
pod 'hermes-engine', :path => path_to_hermes
end

end

pods_to_update = LocalPodspecPatch.pods_to_update(options)
if !pods_to_update.empty?
if Pod::Lockfile.public_instance_methods.include?(:detect_changes_with_podfile)
Expand Down
4 changes: 4 additions & 0 deletions sdks/hermes-engine/utils/build-apple-framework.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ fi

NUM_CORES=$(sysctl -n hw.ncpu)
IMPORT_HERMESC_PATH=${HERMES_OVERRIDE_HERMESC_PATH:-$PWD/build_host_hermesc/ImportHermesc.cmake}
JSI_PATH="$PWD/../../ReactCommon/jsi"

function get_release_version {
ruby -rcocoapods-core -rjson -e "puts Pod::Specification.from_file('hermes-engine.podspec').version"
Expand Down Expand Up @@ -59,6 +60,9 @@ function configure_apple_framework {
-DHERMES_BUILD_APPLE_DSYM:BOOLEAN=true \
-DHERMES_ENABLE_TOOLS:BOOLEAN="$build_cli_tools" \
-DIMPORT_HERMESC:PATH="$IMPORT_HERMESC_PATH" \
-DJSI_DIR="$JSI_PATH" \
-DHERMES_BUILD_SHARED_JSI=true \
-DHERMES_RELEASE_VERSION="for RN $(get_release_version)" \
-DCMAKE_INSTALL_PREFIX:PATH=../destroot \
-DCMAKE_BUILD_TYPE="$BUILD_TYPE"
}
Expand Down

0 comments on commit 4c18d8e

Please sign in to comment.