Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hermes: Build Hermes apple runtime artifacts #33876

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 42 additions & 25 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ references:
gems_cache_key: &gems_cache_key v1-gems-{{ checksum "Gemfile.lock" }}
gradle_cache_key: &gradle_cache_key v1-gradle-{{ checksum "gradle/wrapper/gradle-wrapper.properties" }}-{{ checksum "ReactAndroid/gradle.properties" }}
hermes_cache_key: &hermes_cache_key v1-hermes-{{ .Environment.CIRCLE_JOB }}-{{ checksum "/tmp/hermes/hermesversion" }}
hermes_sdk_cache_key: &hermes_sdk_cache_key v1-hermes-{{ .Environment.CIRCLE_JOB }}-{{ checksum "sdks/.hermesversion" }}
hermes_sdk_cache_key: &hermes_sdk_cache_key v1-hermes-{{ .Environment.CIRCLE_JOB }}-{{ checksum "sdks/.hermes-cache-key-file" }}
hermes_windows_cache_key: &hermes_windows_cache_key v1-hermes-{{ .Environment.CIRCLE_JOB }}-{{ checksum "tmp/hermes/hermesversion" }}
pods_cache_key: &pods_cache_key v6-pods-{{ .Environment.CIRCLE_JOB }}-{{ checksum "packages/rn-tester/Podfile.lock.bak" }}-{{ checksum "packages/rn-tester/Podfile" }}
windows_yarn_cache_key: &windows_yarn_cache_key v1-win-yarn-cache-{{ arch }}-{{ checksum "yarn.lock" }}
Expand Down Expand Up @@ -278,9 +278,9 @@ commands:
- run:
name: Setup Hermes cache
command: |
HERMES_VERSION_FILE="sdks/.hermesversion"
if [ ! -f "$HERMES_VERSION_FILE" ]; then
git ls-remote https://github.com/facebook/hermes main | cut -f 1 > $HERMES_VERSION_FILE
HERMES_CACHE_KEY_FILE="sdks/.hermes-cache-key-file"
if [ ! -f "$HERMES_CACHE_KEY_FILE" ]; then
git ls-remote https://github.com/facebook/hermes main | cut -f 1 > $HERMES_CACHE_KEY_FILE
fi
- restore_cache:
keys:
Expand Down Expand Up @@ -946,7 +946,7 @@ jobs:
paths:
- linux64-bin

build_hermesc_macos:
build_hermes_macos:
executor: reactnativeios
environment:
- HERMES_WS_DIR: *hermes_workspace_root
Expand All @@ -959,28 +959,46 @@ jobs:
name: Set up workspace
command: |
mkdir -p /tmp/hermes/osx-bin
cp ~/react-native/sdks/hermes-engine/utils/* "$HERMES_WS_DIR/hermes/utils/."
mkdir -p ~/react-native/sdks/hermes
cp -r $HERMES_WS_DIR/hermes/* ~/react-native/sdks/hermes/.
- run:
name: Install dependencies
command: |
brew install cmake
- run:
name: Build HermesC for macOS
name: Build the Hermes iOS frameworks
command: |
if [ -f /tmp/hermes/osx-bin/hermesc ]; then
echo 'Skipping; Clean "/tmp/hermes/osx-bin" to rebuild.'
else
cd "$HERMES_WS_DIR/hermes"
./utils/build-mac-framework.sh
cp build_macosx/bin/hermesc /tmp/hermes/osx-bin/.
fi
cd ~/react-native/sdks/hermes
./utils/build-ios-framework.sh
- run:
name: Build the Hermes Mac frameworks
command: |
cd ~/react-native/sdks/hermes
./utils/build-mac-framework.sh
cp build_macosx/bin/hermesc /tmp/hermes/osx-bin/.
- run:
name: Package the Hermes Apple frameworks
command: |
cd ~/react-native/sdks/hermes
. ./utils/build-apple-framework.sh

mkdir -p /tmp/cocoapods-package-root/destroot
mkdir -p /tmp/hermes/output
cp -R ./destroot /tmp/cocoapods-package-root
cp hermes-engine.podspec LICENSE /tmp/cocoapods-package-root

tar -C /tmp/cocoapods-package-root/ -czvf /tmp/hermes/output/hermes-runtime-darwin-v$(get_release_version).tar.gz .
- save_cache:
key: *hermes_cache_key
paths:
- /tmp/hermes/osx-bin/
- /tmp/hermes/hermes/destroot/
- /tmp/hermes/hermes/build_host_hermesc/
- /tmp/hermes/hermes/build_macosx/
- ~/react-native/hermes/build_host_hermesc
- ~/react-native/hermes/build_iphoneos
- ~/react-native/hermes/build_catalyst
- ~/react-native/hermes/build_iphonesimulator
- ~/react-native/hermes/build_macosx
- ~/react-native/hermes/destroot
- store_artifacts:
path: /tmp/hermes/output/
- store_artifacts:
path: /tmp/hermes/osx-bin/
- persist_to_workspace:
Expand Down Expand Up @@ -1232,7 +1250,7 @@ workflows:
- build_hermesc_linux:
requires:
- prepare_hermes_workspace
- build_hermesc_macos:
- build_hermes_macos:
requires:
- prepare_hermes_workspace
- build_hermesc_windows:
Expand All @@ -1243,7 +1261,7 @@ workflows:
publish_npm_args: --dry-run
requires:
- build_hermesc_linux
- build_hermesc_macos
- build_hermes_macos
- build_hermesc_windows
- test_js:
run_disabled_tests: false
Expand Down Expand Up @@ -1290,7 +1308,7 @@ workflows:
filters: *only_release_tags
requires:
- prepare_hermes_workspace
- build_hermesc_macos:
- build_hermes_macos:
filters: *only_release_tags
requires:
- prepare_hermes_workspace
Expand All @@ -1306,7 +1324,7 @@ workflows:
filters: *only_release_tags
requires:
- build_hermesc_linux
- build_hermesc_macos
- build_hermes_macos
- build_hermesc_windows

analysis:
Expand Down Expand Up @@ -1340,16 +1358,15 @@ workflows:
- build_hermesc_linux:
requires:
- prepare_hermes_workspace
- build_hermesc_macos:
- build_hermes_macos:
requires:
- prepare_hermes_workspace
- build_hermesc_windows:
requires:
- prepare_hermes_workspace

- build_npm_package:
publish_npm_args: --nightly
requires:
- build_hermesc_linux
- build_hermesc_macos
- build_hermes_macos
- build_hermesc_windows
26 changes: 24 additions & 2 deletions scripts/react_native_pods.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.

require 'json'
require 'pathname'
require_relative './react_native_pods_utils/script_phases.rb'
require_relative './cocoapods/flipper.rb'
Expand All @@ -17,6 +18,8 @@
DEFAULT_OTHER_CPLUSPLUSFLAGS = '$(inherited)'
NEW_ARCH_OTHER_CPLUSPLUSFLAGS = '$(inherited) -DRCT_NEW_ARCH_ENABLED=1 -DFOLLY_NO_CONFIG -DFOLLY_MOBILE=1 -DFOLLY_USE_LIBCPP=1'

$START_TIME = Time.now.to_i

def use_react_native! (options={})
# The prefix to react-native
prefix = options[:path] ||= "../node_modules/react-native"
Expand Down Expand Up @@ -102,10 +105,27 @@ def use_react_native! (options={})
end

if hermes_enabled
system("(cd #{prefix} && node scripts/hermes/prepare-hermes-for-build)")
pod 'React-hermes', :path => "#{prefix}/ReactCommon/hermes"
pod 'hermes-engine', :path => "#{prefix}/sdks/hermes/hermes-engine.podspec"
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)
Expand Down Expand Up @@ -224,6 +244,8 @@ def react_native_post_install(installer, react_native_path = "../node_modules/re
modify_flags_for_new_architecture(installer, cpp_flags)

set_node_modules_user_settings(installer, react_native_path)

puts "Pod install took #{Time.now.to_i - $START_TIME} [s] to run"
end

def modify_flags_for_new_architecture(installer, cpp_flags)
Expand Down
68 changes: 46 additions & 22 deletions sdks/hermes-engine/hermes-engine.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,48 @@
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.

hermes_tag = 'main'
hermes_tag_file = File.join(__dir__, ".hermesversion")
if (File.exist?(hermes_tag_file))
hermes_tag = File.read(hermes_tag_file)
require "json"

# sdks/.hermesversion
hermes_tag_file = File.join(__dir__, "..", ".hermesversion")

# sdks/hermesc/osx-bin/ImportHermesc.cmake
import_hermesc_file=File.join(__dir__, "..", "hermesc", "osx-bin", "ImportHermesc.cmake")

# package.json
package_file = File.join(__dir__, "..", "..", "package.json")
package = JSON.parse(File.read(package_file))
version = package['version']

source = {}
git = "https://github.com/facebook/hermes.git"
building_from_source = false

if ENV['hermes-artifact-url'] then
source[:http] = ENV['hermes-artifact-url']
elsif File.exist?(hermes_tag_file) then
building_from_source = true
source[:git] = git
source[:tag] = File.read(hermes_tag_file)
else
building_from_source = true
source[:git] = git
hermes_commit_sha = `git ls-remote https://github.com/facebook/hermes main | cut -f 1`.strip
source[:commit] = hermes_commit_sha
end
hermes_tag_sha = `git ls-remote https://github.com/facebook/hermes #{hermes_tag} | cut -f 1`.strip
source = { :git => 'https://github.com/facebook/hermes.git', :commit => hermes_tag_sha }

module HermesHelper
# BUILD_TYPE = :debug
BUILD_TYPE = :release
end

Pod::UI.puts '[Hermes] Hermes needs to be compiled, installing hermes-engine may take a while...'.yellow if Object.const_defined?("Pod::UI")

import_hermesc_path=File.join(__dir__, "../hermesc/osx-bin/ImportHermesc.cmake")
if building_from_source
Pod::UI.puts '[Hermes] Hermes needs to be compiled, installing hermes-engine may take a while...'.yellow if Object.const_defined?("Pod::UI")
end

Pod::Spec.new do |spec|
spec.name = "hermes-engine"
spec.version = "1000.0.0-#{hermes_tag_sha.slice(0,6)}"
spec.version = version
spec.summary = "Hermes is a small and lightweight JavaScript engine optimized for running React Native."
spec.description = "Hermes is a JavaScript engine optimized for fast start-up of React Native apps. It features ahead-of-time static optimization and compact bytecode."
spec.homepage = "https://hermesengine.dev"
Expand All @@ -40,19 +62,21 @@ Pod::Spec.new do |spec|

spec.xcconfig = { "CLANG_CXX_LANGUAGE_STANDARD" => "c++17", "CLANG_CXX_LIBRARY" => "compiler-default", "GCC_PREPROCESSOR_DEFINITIONS" => "HERMES_ENABLE_DEBUGGER=1" }

spec.prepare_command = <<-EOS
# When true, debug build will be used.
# See `build-apple-framework.sh` for details
DEBUG=#{HermesHelper::BUILD_TYPE == :debug}
unless ENV['hermes-artifact-url']
spec.prepare_command = <<-EOS
# When true, debug build will be used.
# See `build-apple-framework.sh` for details
DEBUG=#{HermesHelper::BUILD_TYPE == :debug}

# Set HERMES_OVERRIDE_HERMESC_PATH if pre-built HermesC is available
#{File.exist?(import_hermesc_path) ? "export HERMES_OVERRIDE_HERMESC_PATH=#{import_hermesc_path}" : ""}
#{File.exist?(import_hermesc_path) ? "echo \"Overriding HermesC path...\"" : ""}
# Set HERMES_OVERRIDE_HERMESC_PATH if pre-built HermesC is available
#{File.exist?(import_hermesc_file) ? "export HERMES_OVERRIDE_HERMESC_PATH=#{import_hermesc_file}" : ""}
#{File.exist?(import_hermesc_file) ? "echo \"Overriding HermesC path...\"" : ""}

# Build iOS framework
./utils/build-ios-framework.sh
# Build iOS framework
./utils/build-ios-framework.sh

# Build Mac framework
./utils/build-mac-framework.sh
EOS
# Build Mac framework
./utils/build-mac-framework.sh
EOS
end
end