first commit

This commit is contained in:
2026-03-10 16:18:05 +00:00
commit 11f9c069b5
31635 changed files with 3187747 additions and 0 deletions

View File

@@ -0,0 +1,234 @@
#!/bin/bash
# Copyright (c) Meta Platforms, Inc. and affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
# Defines functions for building various Hermes frameworks.
# See build-ios-framework.sh and build-mac-framework.sh for usage examples.
CURR_SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd -P)"
IMPORT_HOST_COMPILERS_PATH=${HERMES_OVERRIDE_HERMESC_PATH:-$PWD/build_host_hermesc/ImportHostCompilers.cmake}
BUILD_TYPE=${BUILD_TYPE:-Debug}
HERMES_PATH="$CURR_SCRIPT_DIR/.."
REACT_NATIVE_PATH=${REACT_NATIVE_PATH:-$CURR_SCRIPT_DIR/../../..}
NUM_CORES=$(sysctl -n hw.ncpu)
PLATFORMS=("macosx" "iphoneos" "iphonesimulator" "catalyst" "xros" "xrsimulator" "appletvos" "appletvsimulator")
if [[ -z "$JSI_PATH" ]]; then
JSI_PATH="$REACT_NATIVE_PATH/ReactCommon/jsi"
fi
function use_env_var_or_ruby_prop {
if [[ -n "$1" ]]; then
echo "$1"
else
ruby -rcocoapods-core -rjson -e "puts Pod::Specification.from_file('hermes-engine.podspec').$2"
fi
}
function use_env_var {
if [[ -n "$1" ]]; then
echo "$1"
else
echo "error: Missing $2 environment variable"
exit 1
fi
}
function get_release_version {
use_env_var_or_ruby_prop "${RELEASE_VERSION}" "version"
}
function get_ios_deployment_target {
use_env_var "${IOS_DEPLOYMENT_TARGET}" "IOS_DEPLOYMENT_TARGET"
}
function get_visionos_deployment_target {
use_env_var "${XROS_DEPLOYMENT_TARGET}" "XROS_DEPLOYMENT_TARGET"
}
function get_mac_deployment_target {
use_env_var "${MAC_DEPLOYMENT_TARGET}" "MAC_DEPLOYMENT_TARGET"
}
# Build host hermes compiler for internal bytecode
function build_host_hermesc {
echo "Building hermesc"
pushd "$HERMES_PATH" > /dev/null || exit 1
cmake -S . -B build_host_hermesc -DJSI_DIR="$JSI_PATH"
cmake --build ./build_host_hermesc --target hermesc -j "${NUM_CORES}"
popd > /dev/null || exit 1
}
# Utility function to configure an Apple framework
function configure_apple_framework {
local enable_debugger cmake_build_type xcode_15_flags xcode_major_version
if [[ $BUILD_TYPE == "Debug" ]]; then
enable_debugger="true"
else
enable_debugger="false"
fi
if [[ $BUILD_TYPE == "Debug" ]]; then
# JS developers aren't VM developers.
# Therefore we're passing as build type Release, to provide a faster build.
cmake_build_type="Release"
else
cmake_build_type="MinSizeRel"
fi
xcode_15_flags=""
xcode_major_version=$(xcodebuild -version | grep -oE '[0-9]*' | head -n 1)
if [[ $xcode_major_version -ge 15 ]]; then
xcode_15_flags="LINKER:-ld_classic"
fi
boost_context_flag=""
if [[ $1 == "catalyst" ]]; then
boost_context_flag="-DHERMES_ALLOW_BOOST_CONTEXT=0"
fi
pushd "$HERMES_PATH" > /dev/null || exit 1
cmake -S . -B "build_$1" \
-DHERMES_EXTRA_LINKER_FLAGS="$xcode_15_flags" \
-DHERMES_APPLE_TARGET_PLATFORM:STRING="$1" \
-DCMAKE_OSX_ARCHITECTURES:STRING="$2" \
-DCMAKE_OSX_DEPLOYMENT_TARGET:STRING="$3" \
-DHERMES_ENABLE_DEBUGGER:BOOLEAN="$enable_debugger" \
-DHERMES_ENABLE_INTL:BOOLEAN=true \
-DHERMES_ENABLE_LIBFUZZER:BOOLEAN=false \
-DHERMES_ENABLE_FUZZILLI:BOOLEAN=false \
-DHERMES_ENABLE_TEST_SUITE:BOOLEAN=false \
-DHERMES_ENABLE_BITCODE:BOOLEAN=false \
-DHERMES_BUILD_APPLE_FRAMEWORK:BOOLEAN=true \
-DHERMES_BUILD_SHARED_JSI:BOOLEAN=false \
-DCMAKE_CXX_FLAGS:STRING="-gdwarf" \
-DCMAKE_C_FLAGS:STRING="-gdwarf" \
-DIMPORT_HOST_COMPILERS:PATH="$IMPORT_HOST_COMPILERS_PATH" \
-DJSI_DIR="$JSI_PATH" \
-DHERMES_RELEASE_VERSION="for RN $(get_release_version)" \
-DCMAKE_BUILD_TYPE="$cmake_build_type" \
$boost_context_flag
popd > /dev/null || exit 1
}
function build_host_hermesc_if_needed {
if [[ ! -f "$IMPORT_HOST_COMPILERS_PATH" ]]; then
build_host_hermesc
else
echo "[HermesC] Skipping! Found an existent hermesc already at: $IMPORT_HOST_COMPILERS_PATH"
fi
}
# Utility function to build an Apple framework
function build_apple_framework {
# Only build host HermesC if no file found at $IMPORT_HOST_COMPILERS_PATH
build_host_hermesc_if_needed
# Confirm ImportHostCompilers.cmake is now available.
[ ! -f "$IMPORT_HOST_COMPILERS_PATH" ] &&
echo "Host hermesc is required to build apple frameworks!"
# $1: platform, $2: architectures, $3: deployment target
echo "Building $BUILD_TYPE framework for $1 with architectures: $2"
configure_apple_framework "$1" "$2" "$3"
pushd "$HERMES_PATH" > /dev/null || exit 1
mkdir -p "destroot/Library/Frameworks/$1"
cmake --build "./build_$1" --target hermesvm -j "${NUM_CORES}"
# Produce the dSYM.
xcrun dsymutil "./build_$1/lib/hermesvm.framework/hermesvm" -o "./build_$1/lib/hermesvm.framework.dSYM"
cp -R "./build_$1"/lib/hermesvm.framework* "destroot/Library/Frameworks/$1"
# In a MacOS build, also produce the hermes and hermesc CLI tools.
if [[ $1 == macosx ]]; then
cmake --build "./build_$1" --target hermesc hermes -j "${NUM_CORES}"
mkdir -p destroot/bin
cp "./build_$1/bin"/* "destroot/bin"
fi
# Copy over Hermes and JSI API headers.
mkdir -p destroot/include/hermes/Public
cp public/hermes/Public/*.h destroot/include/hermes/Public
mkdir -p destroot/include/hermes
cp API/hermes/*.h destroot/include/hermes
mkdir -p destroot/include/hermes/cdp
cp API/hermes/cdp/*.h destroot/include/hermes/cdp
mkdir -p destroot/include/hermes/inspector
cp API/hermes/inspector/*.h destroot/include/hermes/inspector
mkdir -p destroot/include/hermes/inspector/chrome
cp API/hermes/inspector/chrome/*.h destroot/include/hermes/inspector/chrome
mkdir -p destroot/include/jsi
cp "$JSI_PATH"/jsi/*.h destroot/include/jsi
popd > /dev/null || exit 1
}
function prepare_dest_root_for_ci {
mkdir -p "destroot/bin"
for platform in "${PLATFORMS[@]}"; do
mkdir -p "destroot/Library/Frameworks/$platform"
cp -R "./build_$platform/lib/hermesvm.framework"* "destroot/Library/Frameworks/$platform"
done
cp "./build_macosx/bin/"* "destroot/bin"
# Copy over Hermes and JSI API headers.
mkdir -p destroot/include/hermes/Public
cp public/hermes/Public/*.h destroot/include/hermes/Public
mkdir -p destroot/include/hermes
cp API/hermes/*.h destroot/include/hermes
mkdir -p destroot/include/hermes/cdp
cp API/hermes/cdp/*.h destroot/include/hermes/cdp
mkdir -p destroot/include/hermes/inspector
cp API/hermes/inspector/*.h destroot/include/hermes/inspector
mkdir -p destroot/include/hermes/inspector/chrome
cp API/hermes/inspector/chrome/*.h destroot/include/hermes/inspector/chrome
mkdir -p destroot/include/jsi
cp "$JSI_PATH"/jsi/*.h destroot/include/jsi
}
# Accepts an array of frameworks and will place all of
# the architectures into an universal folder and then remove
# the merged frameworks from destroot
function create_universal_framework {
pushd "$HERMES_PATH/destroot/Library/Frameworks" > /dev/null || exit 1
local platforms=("$@")
local args=""
echo "Creating universal framework for platforms: ${platforms[*]}"
for i in "${!platforms[@]}"; do
local platform="${platforms[$i]}"
local hermes_framework_path="${platform}/hermesvm.framework"
args+="-framework $hermes_framework_path "
done
mkdir -p universal
# shellcheck disable=SC2086
if xcodebuild -create-xcframework $args -output "universal/hermesvm.xcframework"
then
# # Remove the thin iOS hermesvm.frameworks that are now part of the universal
# XCFramework
for platform in "${platforms[@]}"; do
rm -r "$platform"
done
fi
popd > /dev/null || exit 1
}

View File

@@ -0,0 +1,108 @@
#!/bin/bash
# Copyright (c) Meta Platforms, Inc. and affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
set -x -e
release_version="$1"; shift
hermesc_path="$1"; shift
jsi_path="$1"; shift
# Based on platform name returns the framework copy destination. Used later by `vendored_frameworks` in Podspec.
# Fallbacks to "ios" if platform is not recognized.
function get_platform_copy_destination {
if [[ $1 == "macosx" ]]; then
echo "macosx"
return
elif [[ $1 == "xros" || $1 == "xrsimulator" ]]; then
echo "xros"
return
fi
echo "ios"
}
function get_deployment_target {
if [[ $1 == "macosx" ]]; then
echo "${MACOSX_DEPLOYMENT_TARGET}"
return
elif [[ $1 == "xrsimulator" || $1 == "xros" ]]; then
echo "${XROS_DEPLOYMENT_TARGET}"
return
fi
echo "${IPHONEOS_DEPLOYMENT_TARGET}"
}
enable_debugger="false"
if [[ "$CONFIGURATION" = *Debug* ]]; then
enable_debugger="true"
fi
cmake_build_type=""
if [[ "$CONFIGURATION" = *Debug* ]]; then
# JS developers aren't VM developers.
# Therefore we're passing as build type Release, to provide a faster build.
cmake_build_type="Release"
else
cmake_build_type="MinSizeRel"
fi
deployment_target=$(get_deployment_target $PLATFORM_NAME)
xcode_15_flags=""
xcode_major_version=$(xcodebuild -version | grep -oE '[0-9]*' | head -n 1)
if [[ $xcode_major_version -ge 15 ]]; then
echo "########### Using LINKER:-ld_classic ###########"
xcode_15_flags="LINKER:-ld_classic"
fi
boost_context_flag=""
if [[ $PLATFORM_NAME == "catalyst" ]]; then
boost_context_flag="-DHERMES_ALLOW_BOOST_CONTEXT=0"
fi
architectures=$( echo "$ARCHS" | tr " " ";" )
echo "Configure Apple framework"
"$CMAKE_BINARY" \
-S "${PODS_ROOT}/hermes-engine" \
-B "${PODS_ROOT}/hermes-engine/build/${PLATFORM_NAME}" \
-DHERMES_EXTRA_LINKER_FLAGS="$xcode_15_flags" \
-DHERMES_APPLE_TARGET_PLATFORM:STRING="$PLATFORM_NAME" \
-DCMAKE_OSX_ARCHITECTURES:STRING="$architectures" \
-DCMAKE_OSX_DEPLOYMENT_TARGET:STRING="$deployment_target" \
-DHERMES_ENABLE_DEBUGGER:BOOLEAN="$enable_debugger" \
-DHERMES_ENABLE_INTL:BOOLEAN=true \
-DHERMES_ENABLE_LIBFUZZER:BOOLEAN=false \
-DHERMES_ENABLE_FUZZILLI:BOOLEAN=false \
-DHERMES_ENABLE_TEST_SUITE:BOOLEAN=false \
-DHERMES_ENABLE_BITCODE:BOOLEAN=false \
-DHERMES_BUILD_APPLE_FRAMEWORK:BOOLEAN=true \
-DHERMES_BUILD_SHARED_JSI:BOOLEAN=false \
-DCMAKE_CXX_FLAGS:STRING="-gdwarf" \
-DCMAKE_C_FLAGS:STRING="-gdwarf" \
-DIMPORT_HOST_COMPILERS:PATH="${hermesc_path}" \
-DJSI_DIR="$jsi_path" \
-DHERMES_RELEASE_VERSION="for RN $release_version" \
-DCMAKE_BUILD_TYPE="$cmake_build_type" \
$boost_context_flag
echo "Build Apple framework"
"$CMAKE_BINARY" \
--build "${PODS_ROOT}/hermes-engine/build/${PLATFORM_NAME}" \
--target hermesvm \
-j "$(sysctl -n hw.ncpu)"
echo "Copy Apple framework to destroot/Library/Frameworks"
platform_copy_destination=$(get_platform_copy_destination $PLATFORM_NAME)
mkdir -p "${PODS_ROOT}/hermes-engine/destroot/Library/Frameworks/${platform_copy_destination}"
cp -pfR \
"${PODS_ROOT}/hermes-engine/build/${PLATFORM_NAME}/lib/hermesvm.framework" \
"${PODS_ROOT}/hermes-engine/destroot/Library/Frameworks/${platform_copy_destination}"

View File

@@ -0,0 +1,26 @@
#!/bin/bash
# Copyright (c) Meta Platforms, Inc. and affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
set -x -e
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 (iphone, iphonesimulator, macosx).
# We want to make sure that hermesc is built for mac.
# So we clean the environment with env -i, and explicitly set SDKROOT to macosx
SDKROOT=$(xcode-select -p)/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk
env -i \
PATH="$PATH" \
SDKROOT="$SDKROOT" \
"$CMAKE_BINARY" -S "${PODS_ROOT}/hermes-engine" -B "$hermesc_dir_path" -DJSI_DIR="$jsi_path" -DCMAKE_BUILD_TYPE=Release
env -i \
PATH="$PATH" \
SDKROOT="$SDKROOT" \
"$CMAKE_BINARY" --build "$hermesc_dir_path" --target hermesc -j "$(sysctl -n hw.ncpu)"

View File

@@ -0,0 +1,90 @@
#!/bin/bash
# Copyright (c) Meta Platforms, Inc. and affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
if [ "$CI" ]; then
set -x
fi
set -e
# Given a specific target, retrieve the right architecture for it
# $1 the target you want to build. Allowed values: iphoneos, iphonesimulator, catalyst, xros, xrsimulator
function get_architecture {
if [[ $1 == "iphoneos" || $1 == "xros" ]]; then
echo "arm64"
elif [[ $1 == "iphonesimulator" || $1 == "xrsimulator" ]]; then
echo "x86_64;arm64"
elif [[ $1 == "appletvos" ]]; then
echo "arm64"
elif [[ $1 == "appletvsimulator" ]]; then
echo "x86_64;arm64"
elif [[ $1 == "catalyst" ]]; then
echo "x86_64;arm64"
else
echo "Error: unknown architecture passed $1"
exit 1
fi
}
function get_deployment_target {
if [[ $1 == "xros" || $1 == "xrsimulator" ]]; then
echo "$(get_visionos_deployment_target)"
else # tvOS and iOS use the same deployment target
echo "$(get_ios_deployment_target)"
fi
}
# build a single framework
# $1 is the target to build
function build_framework {
if [ ! -d destroot/Library/Frameworks/universal/hermesvm.xcframework ]; then
deployment_target=$(get_deployment_target "$1")
architecture=$(get_architecture "$1")
build_apple_framework "$1" "$architecture" "$deployment_target"
else
echo "Skipping; Clean \"destroot\" to rebuild".
fi
}
# group the frameworks together to create a universal framework
function build_universal_framework {
if [ ! -d destroot/Library/Frameworks/universal/hermesvm.xcframework ]; then
create_universal_framework "iphoneos" "iphonesimulator" "catalyst" "xros" "xrsimulator" "appletvos" "appletvsimulator"
else
echo "Skipping; Clean \"destroot\" to rebuild".
fi
}
# single function that builds sequentially iphoneos, iphonesimulator and catalyst
# this is used to preserve backward compatibility
function create_framework {
if [ ! -d destroot/Library/Frameworks/universal/hermesvm.xcframework ]; then
build_framework "iphoneos"
build_framework "iphonesimulator"
build_framework "appletvos"
build_framework "appletvsimulator"
build_framework "catalyst"
build_framework "xros"
build_framework "xrsimulator"
build_universal_framework
else
echo "Skipping; Clean \"destroot\" to rebuild".
fi
}
CURR_SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd -P)"
# shellcheck source=xplat/js/react-native-github/sdks/hermes-engine/utils/build-apple-framework.sh
. "${CURR_SCRIPT_DIR}/build-apple-framework.sh"
if [[ -z $1 ]]; then
create_framework
elif [[ $1 == "build_framework" ]]; then
build_universal_framework
else
build_framework "$1"
fi

View File

@@ -0,0 +1,22 @@
#!/bin/bash
# Copyright (c) Meta Platforms, Inc. and affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
if [ "$CI" ]; then
set -x
fi
set -e
# shellcheck source=xplat/js/react-native-github/sdks/hermes-engine/utils/build-apple-framework.sh
CURR_SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd -P)"
. "${CURR_SCRIPT_DIR}/build-apple-framework.sh"
if [ ! -d destroot/Library/Frameworks/macosx/hermesvm.framework ]; then
mac_deployment_target=$(get_mac_deployment_target)
build_apple_framework "macosx" "x86_64;arm64" "$mac_deployment_target"
else
echo "Skipping; Clean \"destroot\" to rebuild".
fi

View File

@@ -0,0 +1,7 @@
#!/bin/bash
# Copyright (c) Meta Platforms, Inc. and affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
echo "This file is no-op now. Remove \"[RN] Copy Hermes Framework\" script phase from your main target if you don't want to see this message."

View File

@@ -0,0 +1,32 @@
#!/bin/bash
# Copyright (c) Meta Platforms, Inc. and affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
set -x
# CocoaPods requires vendored frameworks to exist before `pod install` is run,
# and to be proper Moch-O binaries in order to auto-link them to the user's Xcode project.
# This script creates dummy hermesvm.framework for macosx and ios.
# They are then get rewritten by `build-hermes-xcode.sh` during Xcode build.
rm -rf destroot
mkdir -p destroot/Library/Frameworks
pushd destroot/Library/Frameworks > /dev/null || exit 1
echo '' > dummy.c
platforms=( "macosx" "ios" "xros" ) # Add other platforms here if needed
for platform in "${platforms[@]}"
do
mkdir -p "${platform}/hermesvm.framework"
clang dummy.c -dynamiclib -o "${platform}/hermesvm.framework/hermesvm"
done
rm dummy.c
popd > /dev/null || exit 1

View File

@@ -0,0 +1,109 @@
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow strict-local
* @format
*/
'use strict';
const {spawnSync} = require('child_process');
const fs = require('fs');
const yargs = require('yargs');
const LAST_BUILD_FILENAME = '.last_build_configuration';
function validateBuildConfiguration(configuration) {
if (!['Debug', 'Release'].includes(configuration)) {
throw new Error(`Invalid configuration ${configuration}`);
}
}
function validateVersion(version) {
if (version == null || version === '') {
throw new Error('Version cannot be empty');
}
}
function shouldReplaceHermesConfiguration(configuration) {
const fileExists = fs.existsSync(LAST_BUILD_FILENAME);
if (fileExists) {
console.log(`Found ${LAST_BUILD_FILENAME} file`);
const oldConfiguration = fs.readFileSync(LAST_BUILD_FILENAME).toString();
if (oldConfiguration === configuration) {
console.log(
'Same config of the previous build. No need to replace Hermes engine',
);
return false;
}
}
// Assumption: if there is no stored last build, we assume that it was build for debug.
if (!fileExists && configuration === 'Debug') {
console.log(
'No previous build detected, but Debug Configuration. No need to replace Hermes engine',
);
return false;
}
return true;
}
function replaceHermesConfiguration(configuration, version, podsRoot) {
const tarballURLPath = `${podsRoot}/hermes-engine-artifacts/hermes-ios-${version.toLowerCase()}-${configuration.toLowerCase()}.tar.gz`;
const finalLocation = 'hermes-engine';
console.log('Preparing the final location');
fs.rmSync(finalLocation, {force: true, recursive: true});
fs.mkdirSync(finalLocation, {recursive: true});
console.log('Extracting the tarball');
spawnSync('tar', ['-xf', tarballURLPath, '-C', finalLocation], {
stdio: 'inherit',
});
}
function updateLastBuildConfiguration(configuration) {
fs.writeFileSync(LAST_BUILD_FILENAME, configuration);
}
function main(configuration, version, podsRoot) {
validateBuildConfiguration(configuration);
validateVersion(version);
if (!shouldReplaceHermesConfiguration(configuration)) {
return;
}
replaceHermesConfiguration(configuration, version, podsRoot);
updateLastBuildConfiguration(configuration);
console.log('Done replacing hermes-engine');
}
// This script is executed in the Pods folder, which is usually not synched to Github, so it should be ok
const argv = yargs
.option('c', {
alias: 'configuration',
description:
'Configuration to use to download the right Hermes version. Allowed values are "Debug" and "Release".',
})
.option('r', {
alias: 'reactNativeVersion',
description:
'The Version of React Native associated with the Hermes tarball.',
})
.option('p', {
alias: 'podsRoot',
description: 'The path to the Pods root folder',
})
.usage('Usage: $0 -c Debug -r <version> -p <path/to/react-native>').argv;
const configuration = argv.configuration;
const version = argv.reactNativeVersion;
const podsRoot = argv.podsRoot;
main(configuration, version, podsRoot);