Skip to content

Commit ae28880

Browse files
hramosfacebook-github-bot
authored andcommitted
Hermes: Copy build scripts to RN
Summary: Copy Hermes build scripts to React Native repository for greater control over the build pipeline when used in RN. Changelog: [Internal] Reviewed By: neildhar Differential Revision: D36295406 fbshipit-source-id: 54bf4173b6c75db35de828378e6f5782a248ed2e
1 parent c171a6e commit ae28880

File tree

7 files changed

+157
-4
lines changed

7 files changed

+157
-4
lines changed

.circleci/config.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -987,13 +987,15 @@ jobs:
987987
environment:
988988
- HERMES_WS_DIR: *hermes_workspace_root
989989
steps:
990+
- checkout
990991
- *attach_hermes_workspace
991992
- restore_cache:
992993
key: v1-hermes-{{ .Environment.CIRCLE_JOB }}-{{ checksum "/tmp/hermes/hermesversion" }}
993994
- run:
994995
name: Set up workspace
995996
command: |
996997
mkdir -p /tmp/hermes/osx-bin
998+
cp ~/react-native/sdks/hermes-engine/utils/* "$HERMES_WS_DIR/hermes/utils/."
997999
- run:
9981000
name: Install dependencies
9991001
command: |

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@
5555
"scripts/react_native_pods.rb",
5656
"scripts/cocoapods/flipper.rb",
5757
"scripts/react-native-xcode.sh",
58+
"sdks/hermes-engine",
5859
"sdks/hermesc",
59-
"sdks/hermes-engine.podspec",
6060
"template.config.js",
6161
"template",
6262
"!template/node_modules",

scripts/react_native_pods.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -630,8 +630,9 @@ def downloadAndConfigureHermesSource(react_native_path)
630630
Pod::UI.puts "[Hermes] Extracting Hermes tarball (#{hermes_tag_sha.slice(0,6)})"
631631
system("tar -zxf #{hermes_tarball_path} --strip-components=1 --directory #{hermes_dir}")
632632

633-
# TODO: Integrate this temporary hermes-engine.podspec into the actual one located in facebook/hermes
634-
system("cp #{sdks_dir}/hermes-engine.podspec #{hermes_dir}/hermes-engine.podspec")
633+
# Use React Native's own scripts to build Hermes
634+
system("cp #{sdks_dir}/hermes-engine/hermes-engine.podspec #{hermes_dir}/hermes-engine.podspec")
635+
system("cp #{sdks_dir}/hermes-engine/utils/* #{hermes_dir}/utils/.")
635636

636637
hermes_dir
637638
end

sdks/hermes-engine.podspec renamed to sdks/hermes-engine/hermes-engine.podspec

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ Pod::Spec.new do |spec|
3838

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

41-
# TODO: Consider moving Hermes build scripts to react_native_pods.rb for greater control over when they're executed
4241
spec.prepare_command = <<-EOS
4342
# When true, debug build will be used.
4443
# See `build-apple-framework.sh` for details
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
#!/bin/bash
2+
# Copyright (c) Meta Platforms, Inc. and affiliates.
3+
#
4+
# This source code is licensed under the MIT license found in the
5+
# LICENSE file in the root directory of this source tree.
6+
7+
if [ "$DEBUG" = true ]; then
8+
BUILD_TYPE="Debug"
9+
else
10+
BUILD_TYPE="Release"
11+
fi
12+
13+
function command_exists {
14+
command -v "${1}" > /dev/null 2>&1
15+
}
16+
17+
if command_exists "cmake"; then
18+
if command_exists "ninja"; then
19+
BUILD_SYSTEM="Ninja"
20+
else
21+
BUILD_SYSTEM="Unix Makefiles"
22+
fi
23+
else
24+
echo >&2 'CMake is required to install Hermes, install it with: brew install cmake'
25+
exit 1
26+
fi
27+
28+
function get_release_version {
29+
ruby -rcocoapods-core -rjson -e "puts Pod::Specification.from_file('hermes-engine.podspec').version"
30+
}
31+
32+
function get_ios_deployment_target {
33+
ruby -rcocoapods-core -rjson -e "puts Pod::Specification.from_file('hermes-engine.podspec').deployment_target('ios')"
34+
}
35+
36+
function get_mac_deployment_target {
37+
ruby -rcocoapods-core -rjson -e "puts Pod::Specification.from_file('hermes-engine.podspec').deployment_target('osx')"
38+
}
39+
40+
# Build host hermes compiler for internal bytecode
41+
function build_host_hermesc {
42+
cmake -S . -B build_host_hermesc
43+
cmake --build ./build_host_hermesc --target hermesc
44+
}
45+
46+
# Utility function to configure an Apple framework
47+
function configure_apple_framework {
48+
local build_cli_tools enable_bitcode
49+
50+
if [[ $1 == iphoneos || $1 == catalyst ]]; then
51+
enable_bitcode="true"
52+
else
53+
enable_bitcode="false"
54+
fi
55+
if [[ $1 == macosx ]]; then
56+
build_cli_tools="true"
57+
else
58+
build_cli_tools="false"
59+
fi
60+
61+
cmake -S . -B "build_$1" -G "$BUILD_SYSTEM" \
62+
-DHERMES_APPLE_TARGET_PLATFORM:STRING="$1" \
63+
-DCMAKE_OSX_ARCHITECTURES:STRING="$2" \
64+
-DCMAKE_OSX_DEPLOYMENT_TARGET:STRING="$3" \
65+
-DHERMES_ENABLE_DEBUGGER:BOOLEAN=true \
66+
-DHERMES_ENABLE_LIBFUZZER:BOOLEAN=false \
67+
-DHERMES_ENABLE_FUZZILLI:BOOLEAN=false \
68+
-DHERMES_ENABLE_TEST_SUITE:BOOLEAN=false \
69+
-DHERMES_ENABLE_BITCODE:BOOLEAN="$enable_bitcode" \
70+
-DHERMES_BUILD_APPLE_FRAMEWORK:BOOLEAN=true \
71+
-DHERMES_BUILD_APPLE_DSYM:BOOLEAN=true \
72+
-DHERMES_ENABLE_TOOLS:BOOLEAN="$build_cli_tools" \
73+
-DIMPORT_HERMESC:PATH="$PWD/build_host_hermesc/ImportHermesc.cmake" \
74+
-DCMAKE_INSTALL_PREFIX:PATH=../destroot \
75+
-DCMAKE_BUILD_TYPE="$BUILD_TYPE"
76+
}
77+
78+
# Utility function to build an Apple framework
79+
function build_apple_framework {
80+
echo "Building framework for $1 with architectures: $2"
81+
82+
build_host_hermesc
83+
[ ! -f "$PWD/build_host_hermesc/ImportHermesc.cmake" ] &&
84+
echo "Host hermesc is required to build apple frameworks!"
85+
86+
configure_apple_framework "$1" "$2" "$3"
87+
88+
if [[ "$BUILD_SYSTEM" == "Ninja" ]]; then
89+
(cd "./build_$1" && ninja install/strip)
90+
else
91+
(cd "./build_$1" && make install/strip)
92+
fi
93+
}
94+
95+
# Accepts an array of frameworks and will place all of
96+
# the architectures into an universal folder and then remove
97+
# the merged frameworks from destroot
98+
function create_universal_framework {
99+
cd ./destroot/Library/Frameworks || exit 1
100+
101+
local platforms=("$@")
102+
local args=""
103+
104+
echo "Creating universal framework for platforms: ${platforms[*]}"
105+
106+
for i in "${!platforms[@]}"; do
107+
args+="-framework ${platforms[$i]}/hermes.framework "
108+
done
109+
110+
mkdir universal
111+
xcodebuild -create-xcframework $args -output "universal/hermes.xcframework"
112+
113+
for platform in $@; do
114+
rm -r "$platform"
115+
done
116+
117+
cd - || exit 1
118+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/bin/bash
2+
# Copyright (c) Meta Platforms, Inc. and affiliates.
3+
#
4+
# This source code is licensed under the MIT license found in the
5+
# LICENSE file in the root directory of this source tree.
6+
7+
. ./utils/build-apple-framework.sh
8+
9+
if [ ! -d destroot/Library/Frameworks/universal/hermes.xcframework ]; then
10+
ios_deployment_target=$(get_ios_deployment_target)
11+
12+
build_apple_framework "iphoneos" "arm64" "$ios_deployment_target"
13+
build_apple_framework "iphonesimulator" "x86_64;arm64" "$ios_deployment_target"
14+
build_apple_framework "catalyst" "x86_64;arm64" "$ios_deployment_target"
15+
16+
create_universal_framework "iphoneos" "iphonesimulator" "catalyst"
17+
else
18+
echo "Skipping; Clean \"destroot\" to rebuild".
19+
fi
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/bin/bash
2+
# Copyright (c) Meta Platforms, Inc. and affiliates.
3+
#
4+
# This source code is licensed under the MIT license found in the
5+
# LICENSE file in the root directory of this source tree.
6+
7+
. ./utils/build-apple-framework.sh
8+
if [ ! -d destroot/Library/Frameworks/macosx/hermes.framework ]; then
9+
mac_deployment_target=$(get_mac_deployment_target)
10+
11+
build_apple_framework "macosx" "x86_64;arm64" "$mac_deployment_target"
12+
else
13+
echo "Skipping; Clean \"destroot\" to rebuild".
14+
fi

0 commit comments

Comments
 (0)