Skip to content

Commit 644fe43

Browse files
hramosfacebook-github-bot
authored andcommitted
iOS: Use pre-built hermesc if available (#33827)
Summary: Use pre-built hermesc if available by generating a ImportHermesc.cmake file that points to the hermesc binary. Recent `react-native` releases should have hermesc available in sdks/hermesc. Hermes build scripts have been updated to support a `HERMES_OVERRIDE_HERMESC_PATH` envvar which can point to this generated ImportHermesc.cmake file. Pull Request resolved: #33827 Changelog: [iOS] [Changed] - Use pre-built HermesC if available in current React Native release Reviewed By: cortinico Differential Revision: D36024615 fbshipit-source-id: 476569f73309f9bd142f28cb02d1f7d57b6cbc6a
1 parent bd2d0b2 commit 644fe43

File tree

5 files changed

+48
-3
lines changed

5 files changed

+48
-3
lines changed

.gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,9 @@ package-lock.json
115115
/packages/rn-tester/NativeModuleExample/ScreenshotManagerSpec*
116116

117117
# Additional SDKs
118-
/sdks/hermes
119118
/sdks/download
119+
/sdks/hermes
120+
/sdks/hermesc
120121

121122
# Visual studio
122123
.vscode

scripts/hermes/hermes-utils.js

+26
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,12 @@ const HERMES_DIR = path.join(SDKS_DIR, 'hermes');
1818
const HERMES_TAG_FILE_PATH = path.join(SDKS_DIR, '.hermesversion');
1919
const HERMES_TARBALL_BASE_URL = 'https://github.com/facebook/hermes/tarball/';
2020
const HERMES_TARBALL_DOWNLOAD_DIR = path.join(SDKS_DIR, 'download');
21+
const MACOS_BIN_DIR = path.join(SDKS_DIR, 'hermesc', 'osx-bin');
22+
const MACOS_HERMESC_PATH = path.join(MACOS_BIN_DIR, 'hermesc');
23+
const MACOS_IMPORT_HERMESC_PATH = path.join(
24+
MACOS_BIN_DIR,
25+
'ImportHermesc.cmake',
26+
);
2127

2228
function prepareFileSystem() {
2329
if (!fs.existsSync(SDKS_DIR)) {
@@ -143,11 +149,31 @@ function copyBuildScripts() {
143149
);
144150
}
145151

152+
function shouldUsePrebuiltHermesC(os) {
153+
if (os === 'macos') {
154+
return fs.existsSync(MACOS_HERMESC_PATH);
155+
}
156+
157+
return false;
158+
}
159+
160+
function configureMakeForPrebuiltHermesC() {
161+
const IMPORT_HERMESC_TEMPLATE = `add_executable(native-hermesc IMPORTED)
162+
set_target_properties(native-hermesc PROPERTIES
163+
IMPORTED_LOCATION "${MACOS_HERMESC_PATH}"
164+
)`;
165+
166+
fs.mkdirSync(MACOS_BIN_DIR, {recursive: true});
167+
fs.writeFileSync(MACOS_IMPORT_HERMESC_PATH, IMPORT_HERMESC_TEMPLATE);
168+
}
169+
146170
module.exports = {
171+
configureMakeForPrebuiltHermesC,
147172
copyBuildScripts,
148173
downloadHermesTarball,
149174
expandHermesTarball,
150175
getHermesTagSHA,
151176
readHermesTag,
152177
setHermesTag,
178+
shouldUsePrebuiltHermesC,
153179
};

scripts/hermes/prepare-hermes-for-build.js

+7
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,18 @@
1414
* iOS build pipeline on macOS.
1515
*/
1616
const {
17+
configureMakeForPrebuiltHermesC,
1718
copyBuildScripts,
1819
downloadHermesTarball,
1920
expandHermesTarball,
21+
shouldUsePrebuiltHermesC,
2022
} = require('./hermes-utils');
2123

2224
downloadHermesTarball();
2325
expandHermesTarball();
2426
copyBuildScripts();
27+
28+
if (shouldUsePrebuiltHermesC('macos')) {
29+
console.log('[Hermes] Using pre-built HermesC');
30+
configureMakeForPrebuiltHermesC();
31+
}

sdks/hermes-engine/hermes-engine.podspec

+6
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ end
1818

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

21+
import_hermesc_path=File.join(__dir__, "../hermesc/osx-bin/ImportHermesc.cmake")
22+
2123
Pod::Spec.new do |spec|
2224
spec.name = "hermes-engine"
2325
spec.version = "1000.0.0-#{hermes_tag_sha.slice(0,6)}"
@@ -43,6 +45,10 @@ Pod::Spec.new do |spec|
4345
# See `build-apple-framework.sh` for details
4446
DEBUG=#{HermesHelper::BUILD_TYPE == :debug}
4547
48+
# Set HERMES_OVERRIDE_HERMESC_PATH if pre-built HermesC is available
49+
#{File.exist?(import_hermesc_path) ? "export HERMES_OVERRIDE_HERMESC_PATH=#{import_hermesc_path}" : ""}
50+
#{File.exist?(import_hermesc_path) ? "echo \"Overriding HermesC path...\"" : ""}
51+
4652
# Build iOS framework
4753
./utils/build-ios-framework.sh
4854

sdks/hermes-engine/utils/build-apple-framework.sh

+7-2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ else
1111
fi
1212

1313
NUM_CORES=$(sysctl -n hw.ncpu)
14+
IMPORT_HERMESC_PATH=${HERMES_OVERRIDE_HERMESC_PATH:-$PWD/build_host_hermesc/ImportHermesc.cmake}
1415

1516
function get_release_version {
1617
ruby -rcocoapods-core -rjson -e "puts Pod::Specification.from_file('hermes-engine.podspec').version"
@@ -57,7 +58,7 @@ function configure_apple_framework {
5758
-DHERMES_BUILD_APPLE_FRAMEWORK:BOOLEAN=true \
5859
-DHERMES_BUILD_APPLE_DSYM:BOOLEAN=true \
5960
-DHERMES_ENABLE_TOOLS:BOOLEAN="$build_cli_tools" \
60-
-DIMPORT_HERMESC:PATH="$PWD/build_host_hermesc/ImportHermesc.cmake" \
61+
-DIMPORT_HERMESC:PATH="$IMPORT_HERMESC_PATH" \
6162
-DCMAKE_INSTALL_PREFIX:PATH=../destroot \
6263
-DCMAKE_BUILD_TYPE="$BUILD_TYPE"
6364
}
@@ -66,8 +67,12 @@ function configure_apple_framework {
6667
function build_apple_framework {
6768
echo "Building framework for $1 with architectures: $2"
6869

70+
# Only build host HermesC if no file found at $IMPORT_HERMESC_PATH
71+
[ ! -f "$IMPORT_HERMESC_PATH" ] &&
6972
build_host_hermesc
70-
[ ! -f "$PWD/build_host_hermesc/ImportHermesc.cmake" ] &&
73+
74+
# Confirm ImportHermesc.cmake is now available.
75+
[ ! -f "$IMPORT_HERMESC_PATH" ] &&
7176
echo "Host hermesc is required to build apple frameworks!"
7277

7378
configure_apple_framework "$1" "$2" "$3"

0 commit comments

Comments
 (0)