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

iOS: Use pre-built hermesc if available #33827

Closed
wants to merge 1 commit 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
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,9 @@ package-lock.json
/packages/rn-tester/NativeModuleExample/ScreenshotManagerSpec*

# Additional SDKs
/sdks/hermes
/sdks/download
/sdks/hermes
/sdks/hermesc

# Visual studio
.vscode
Expand Down
26 changes: 26 additions & 0 deletions scripts/hermes/hermes-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ const HERMES_DIR = path.join(SDKS_DIR, 'hermes');
const HERMES_TAG_FILE_PATH = path.join(SDKS_DIR, '.hermesversion');
const HERMES_TARBALL_BASE_URL = 'https://github.com/facebook/hermes/tarball/';
const HERMES_TARBALL_DOWNLOAD_DIR = path.join(SDKS_DIR, 'download');
const MACOS_BIN_DIR = path.join(SDKS_DIR, 'hermesc', 'osx-bin');
const MACOS_HERMESC_PATH = path.join(MACOS_BIN_DIR, 'hermesc');
const MACOS_IMPORT_HERMESC_PATH = path.join(
MACOS_BIN_DIR,
'ImportHermesc.cmake',
);

function prepareFileSystem() {
if (!fs.existsSync(SDKS_DIR)) {
Expand Down Expand Up @@ -135,11 +141,31 @@ function copyBuildScripts() {
);
}

function shouldUsePrebuiltHermesC(os) {
if (os === 'macos') {
return fs.existsSync(MACOS_HERMESC_PATH);
}

return false;
}

function configureMakeForPrebuiltHermesC() {
const IMPORT_HERMESC_TEMPLATE = `add_executable(native-hermesc IMPORTED)
set_target_properties(native-hermesc PROPERTIES
IMPORTED_LOCATION "${MACOS_HERMESC_PATH}"
)`;

fs.mkdirSync(MACOS_BIN_DIR, {recursive: true});
fs.writeFileSync(MACOS_IMPORT_HERMESC_PATH, IMPORT_HERMESC_TEMPLATE);
}

module.exports = {
configureMakeForPrebuiltHermesC,
copyBuildScripts,
downloadHermesTarball,
expandHermesTarball,
getHermesTagSHA,
readHermesTag,
setHermesTag,
shouldUsePrebuiltHermesC,
};
7 changes: 7 additions & 0 deletions scripts/hermes/prepare-hermes-for-build.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,18 @@
* iOS build pipeline on macOS.
*/
const {
configureMakeForPrebuiltHermesC,
copyBuildScripts,
downloadHermesTarball,
expandHermesTarball,
shouldUsePrebuiltHermesC,
} = require('./hermes-utils');

downloadHermesTarball();
expandHermesTarball();
copyBuildScripts();

if (shouldUsePrebuiltHermesC('macos')) {
console.log('[Hermes] Using pre-built HermesC');
configureMakeForPrebuiltHermesC();
}
6 changes: 6 additions & 0 deletions sdks/hermes-engine/hermes-engine.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ 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")

Pod::Spec.new do |spec|
spec.name = "hermes-engine"
spec.version = "1000.0.0-#{hermes_tag_sha.slice(0,6)}"
Expand All @@ -43,6 +45,10 @@ Pod::Spec.new do |spec|
# 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...\"" : ""}

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

Expand Down
9 changes: 7 additions & 2 deletions sdks/hermes-engine/utils/build-apple-framework.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ else
fi

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

function get_release_version {
ruby -rcocoapods-core -rjson -e "puts Pod::Specification.from_file('hermes-engine.podspec').version"
Expand Down Expand Up @@ -57,7 +58,7 @@ function configure_apple_framework {
-DHERMES_BUILD_APPLE_FRAMEWORK:BOOLEAN=true \
-DHERMES_BUILD_APPLE_DSYM:BOOLEAN=true \
-DHERMES_ENABLE_TOOLS:BOOLEAN="$build_cli_tools" \
-DIMPORT_HERMESC:PATH="$PWD/build_host_hermesc/ImportHermesc.cmake" \
-DIMPORT_HERMESC:PATH="$IMPORT_HERMESC_PATH" \
-DCMAKE_INSTALL_PREFIX:PATH=../destroot \
-DCMAKE_BUILD_TYPE="$BUILD_TYPE"
}
Expand All @@ -66,8 +67,12 @@ function configure_apple_framework {
function build_apple_framework {
echo "Building framework for $1 with architectures: $2"

# Only build host HermesC if no file found at $IMPORT_HERMESC_PATH
[ ! -f "$IMPORT_HERMESC_PATH" ] &&
build_host_hermesc
[ ! -f "$PWD/build_host_hermesc/ImportHermesc.cmake" ] &&

# Confirm ImportHermesc.cmake is now available.
[ ! -f "$IMPORT_HERMESC_PATH" ] &&
echo "Host hermesc is required to build apple frameworks!"

configure_apple_framework "$1" "$2" "$3"
Expand Down