Skip to content

Commit

Permalink
Consume Hermes from local source directory (#38967)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: #38967

Changelog: [IOS][Added] - Now it is possible to build Hermes form local source directory. Just set REACT_NATIVE_OVERRIDE_HERMES_DIR to the path to that directory.

Known shortcoming: changes made to the Hermes source will not be reflected in the RN project. You should manually delete `Pods/hermes-engine` and rerun `pod install`.

Reviewed By: cipolleschi

Differential Revision: D48121314

fbshipit-source-id: 0389662396921bdf120d390de36a586c52eb47f1
  • Loading branch information
dmytrorykun authored and facebook-github-bot committed Aug 24, 2023
1 parent 4b664fc commit 45f7e11
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 5 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ package-lock.json
/packages/react-native/sdks/download
/packages/react-native/sdks/hermes
/packages/react-native/sdks/hermesc
/packages/react-native/sdks/hermes-engine/hermes-engine-from-local-source-dir.tar.gz

# Visual studio
.vscode
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ Pod::Spec.new do |spec|
:script => <<-EOS
. "${REACT_NATIVE_PATH}/scripts/xcode/with-environment.sh"
export CMAKE_BINARY=${CMAKE_BINARY:-#{CMAKE_BINARY}}
. ${REACT_NATIVE_PATH}/sdks/hermes-engine/utils/build-hermesc-xcode.sh #{hermesc_path}
. ${REACT_NATIVE_PATH}/sdks/hermes-engine/utils/build-hermesc-xcode.sh #{hermesc_path} ${REACT_NATIVE_PATH}/ReactCommon/jsi
EOS
},
{
Expand All @@ -118,7 +118,7 @@ Pod::Spec.new do |spec|
:script => <<-EOS
. "${REACT_NATIVE_PATH}/scripts/xcode/with-environment.sh"
export CMAKE_BINARY=${CMAKE_BINARY:-#{CMAKE_BINARY}}
. ${REACT_NATIVE_PATH}/sdks/hermes-engine/utils/build-hermes-xcode.sh #{version} #{hermesc_path}/ImportHermesc.cmake
. ${REACT_NATIVE_PATH}/sdks/hermes-engine/utils/build-hermes-xcode.sh #{version} #{hermesc_path}/ImportHermesc.cmake ${REACT_NATIVE_PATH}/ReactCommon/jsi
EOS
}
]
Expand Down
39 changes: 38 additions & 1 deletion packages/react-native/sdks/hermes-engine/hermes-utils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,14 @@ module HermesEngineSourceType
BUILD_FROM_GITHUB_COMMIT = :build_from_github_commit
BUILD_FROM_GITHUB_TAG = :build_from_github_tag
BUILD_FROM_GITHUB_MAIN = :build_from_github_main
BUILD_FROM_LOCAL_SOURCE_DIR = :build_from_local_source_dir

def HermesEngineSourceType.isPrebuilt(source_type)
return source_type == LOCAL_PREBUILT_TARBALL || source_type == DOWNLOAD_PREBUILD_RELEASE_TARBALL || source_type == DOWNLOAD_PREBUILT_NIGHTLY_TARBALL
end

def HermesEngineSourceType.isFromSource(source_type)
return source_type == BUILD_FROM_GITHUB_COMMIT || source_type == BUILD_FROM_GITHUB_TAG || source_type == BUILD_FROM_GITHUB_MAIN
return source_type == BUILD_FROM_GITHUB_COMMIT || source_type == BUILD_FROM_GITHUB_TAG || source_type == BUILD_FROM_GITHUB_MAIN || source_type == BUILD_FROM_LOCAL_SOURCE_DIR
end
end

Expand All @@ -40,6 +41,10 @@ def HermesEngineSourceType.isFromSource(source_type)

# Returns: hermes-engine source type
def hermes_source_type(version, react_native_path)
if override_hermes_dir_envvar_defined()
return HermesEngineSourceType::BUILD_FROM_LOCAL_SOURCE_DIR
end

if hermes_engine_tarball_envvar_defined()
return HermesEngineSourceType::LOCAL_PREBUILT_TARBALL
end
Expand Down Expand Up @@ -67,6 +72,10 @@ def hermes_source_type(version, react_native_path)
return HermesEngineSourceType::BUILD_FROM_GITHUB_MAIN
end

def override_hermes_dir_envvar_defined()
return ENV.has_key?('REACT_NATIVE_OVERRIDE_HERMES_DIR')
end

def hermes_engine_tarball_envvar_defined()
return ENV.has_key?('HERMES_ENGINE_TARBALL_PATH')
end
Expand All @@ -93,6 +102,8 @@ def nightly_artifact_exists(version)

def podspec_source(source_type, version, react_native_path)
case source_type
when HermesEngineSourceType::BUILD_FROM_LOCAL_SOURCE_DIR
return podspec_source_build_from_local_source_dir(react_native_path)
when HermesEngineSourceType::LOCAL_PREBUILT_TARBALL
return podspec_source_local_prebuilt_tarball()
when HermesEngineSourceType::BUILD_FROM_GITHUB_COMMIT
Expand All @@ -110,6 +121,32 @@ def podspec_source(source_type, version, react_native_path)
end
end

def podspec_source_build_from_local_source_dir(react_native_path)
source_dir_path = ENV['REACT_NATIVE_OVERRIDE_HERMES_DIR']
if Dir.exist?(source_dir_path)
hermes_log("Using source code from local path: #{source_dir_path}")
tarball_path = File.join(react_native_path, "sdks", "hermes-engine", "hermes-engine-from-local-source-dir.tar.gz")
exclude_paths = [
"__tests__",
"./external/flowtest",
"./external/esprima/test_fixtures"
]
.map {|path| "--exclude=#{path}"}
.join(' ')
tar_command = "tar #{exclude_paths} -czvf #{tarball_path} -C #{source_dir_path} . 2> /dev/null"
success = system(tar_command)
if !success
abort "Failed to create a tarball with the contents of \"#{source_dir_path}\""
end
return {:http => "file://#{tarball_path}"}
else
abort <<-EOS
[Hermes] REACT_NATIVE_OVERRIDE_HERMES_DIR is set, but points to a non-existing directory: \"#{source_dir_path}\"
If you don't want to use local source, run `unset REACT_NATIVE_OVERRIDE_HERMES_DIR`
EOS
end
end

def podspec_source_local_prebuilt_tarball()
tarball_path = ENV['HERMES_ENGINE_TARBALL_PATH']
if File.exist?(tarball_path)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ set -x

release_version="$1"; shift
hermesc_path="$1"; shift
jsi_path="$1"; shift

enable_debugger="false"
if [[ "$CONFIGURATION" == "Debug" ]]; then
Expand Down Expand Up @@ -47,6 +48,7 @@ echo "Configure Apple framework"
-DHERMES_BUILD_APPLE_FRAMEWORK:BOOLEAN=true \
-DHERMES_BUILD_APPLE_DSYM:BOOLEAN=true \
-DIMPORT_HERMESC:PATH="${hermesc_path}" \
-DJSI_DIR="$jsi_path" \
-DHERMES_RELEASE_VERSION="for RN $release_version" \
-DCMAKE_BUILD_TYPE="$cmake_build_type"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@

set -x

hermesc_dir_path="$1"
hermesc_dir_path="$1"; shift
jsi_path="$1"

# This script is supposed to be executed from Xcode "run script" phase.
# Xcode sets up its build environment based on the build target.
Expand All @@ -17,7 +18,7 @@ export MACOSX_DEPLOYMENT_TARGET=$MACOSX_DEPLOYMENT_TARGET
SDKROOT=$(xcode-select -p)/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk
export SDKROOT=$SDKROOT

if ! "$CMAKE_BINARY" -S "${PODS_ROOT}/hermes-engine" -B "$hermesc_dir_path"
if ! "$CMAKE_BINARY" -S "${PODS_ROOT}/hermes-engine" -B "$hermesc_dir_path" -DJSI_DIR="$jsi_path"
then
echo "Failed to configure Hermesc cmake project."
exit 1
Expand Down

0 comments on commit 45f7e11

Please sign in to comment.