Created
February 27, 2025 00:16
-
-
Save maxpowa/eda28e3dc506d28429beec9157e616f3 to your computer and use it in GitHub Desktop.
Script for building custom builds of hermes for react-native 0.76.7
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export HERMES_WS_DIR="/tmp/hermes" | |
export HERMES_TARBALL_ARTIFACTS_DIR="/tmp/hermes/hermes-runtime-darwin" | |
export HERMES_OSXBIN_ARTIFACTS_DIR="/tmp/hermes/osx-bin" | |
export IOS_DEPLOYMENT_TARGET="15.1" | |
export MAC_DEPLOYMENT_TARGET="14.0" | |
# supported platforms, see also https://github.com/facebook/react-native/blob/798f2e47aafa555a99d596cefa6bf6972e17d52e/.github/workflows/publish-release.yml#L67 | |
declare -a slices=("macosx" "iphoneos" "iphonesimulator") | |
set -ex | |
# restore-hermes-workspace | |
mkdir -p $HERMES_OSXBIN_ARTIFACTS_DIR ./packages/react-native/sdks/hermes | |
cp -r $HERMES_WS_DIR/hermes/* ./packages/react-native/sdks/hermes/. | |
cp -r ./packages/react-native/sdks/hermes-engine/utils ./packages/react-native/sdks/hermes/. | |
# build-hermesc-apple | |
cd ./packages/react-native/sdks/hermes || exit 1 | |
. ./utils/build-apple-framework.sh | |
build_host_hermesc_if_needed | |
# build-apple-slices-hermes | |
function build_apple_slice() | |
{ | |
echo "Current directory: $(pwd)" | |
SLICE=$1 | |
FLAVOR=$2 | |
FINAL_PATH=build_"$SLICE"_"$FLAVOR" | |
echo "Final path for this slice is: $FINAL_PATH" | |
if [[ -d "$FINAL_PATH" ]]; then | |
echo "[HERMES] Skipping! Found the requested slice at $FINAL_PATH". | |
exit 0 | |
fi | |
if [[ "$ARTIFACTS_EXIST" ]]; then | |
echo "[HERMES] Skipping! Artifacts exists already." | |
exit 0 | |
fi | |
export RELEASE_VERSION=0.76.7 | |
# HermesC is used to build hermes, so it has to be executable | |
chmod +x ./build_host_hermesc/bin/hermesc | |
if [[ "$SLICE" == "macosx" ]]; then | |
echo "[HERMES] Building Hermes for MacOS" | |
chmod +x ./utils/build-mac-framework.sh | |
export BUILD_TYPE="$FLAVOR" | |
./utils/build-mac-framework.sh | |
else | |
echo "[HERMES] Building Hermes for iOS: $SLICE" | |
chmod +x ./utils/build-ios-framework.sh | |
export BUILD_TYPE="$FLAVOR" | |
./utils/build-ios-framework.sh "$SLICE" | |
fi | |
echo "Moving from build_$SLICE to $FINAL_PATH" | |
mv build_"$SLICE" "$FINAL_PATH" | |
# check whether everything is there | |
if [[ -d "$FINAL_PATH/API/hermes/hermes.framework" ]]; then | |
echo "Successfully built hermes.framework for $SLICE in $FLAVOR" | |
else | |
echo "Failed to built hermes.framework for $SLICE in $FLAVOR" | |
exit 1 | |
fi | |
if [[ -d "$FINAL_PATH/API/hermes/hermes.framework.dSYM" ]]; then | |
echo "Successfully built hermes.framework.dSYM for $SLICE in $FLAVOR" | |
else | |
echo "Failed to built hermes.framework.dSYM for $SLICE in $FLAVOR" | |
echo "Please try again" | |
exit 1 | |
fi | |
rm -r destroot | |
} | |
# Go application only targets iphoneos and iphonesimulator | |
for slice in "${slices[@]}"; | |
do | |
build_apple_slice "$slice" "Debug" | |
build_apple_slice "$slice" "Release" | |
done | |
# build-hermes-macos (combines slices into single framework) | |
function build_combined_slices() | |
{ | |
export BUILD_TYPE=$1 | |
# Prepare destroot folder | |
chmod +x ./utils/build-apple-framework.sh | |
. ./utils/build-apple-framework.sh | |
mkdir -p "destroot/bin" | |
for slice in "${slices[@]}"; do | |
mkdir -p "destroot/Library/Frameworks/$platform" | |
cp -R "./build_${slice}_${BUILD_TYPE}/API/hermes/hermes.framework"* "destroot/Library/Frameworks/$platform" | |
done | |
cp "./build_macosx_${BUILD_TYPE}/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 | |
# Create fat framework for iOS | |
echo "[HERMES] Creating the universal framework" | |
chmod +x ./utils/build-ios-framework.sh | |
./utils/build-ios-framework.sh build_framework | |
chmod +x ./destroot/bin/hermesc | |
# Package the Hermes Apple frameworks | |
echo "Packaging Hermes Apple frameworks for $BUILD_TYPE build type" | |
TARBALL_OUTPUT_DIR=$(mktemp -d /tmp/hermes-tarball-output-XXXXXXXX) | |
TARBALL_FILENAME=$(node ./packages/react-native/scripts/hermes/get-tarball-name.js --buildType "$BUILD_TYPE") | |
echo "Packaging Hermes Apple frameworks for $BUILD_TYPE build type" | |
TARBALL_OUTPUT_PATH=$(node ./packages/react-native/scripts/hermes/create-tarball.js \ | |
--inputDir ./packages/react-native/sdks/hermes \ | |
--buildType "$BUILD_TYPE" \ | |
--outputDir $TARBALL_OUTPUT_DIR) | |
echo "Hermes tarball saved to $TARBALL_OUTPUT_PATH" | |
mkdir -p $HERMES_TARBALL_ARTIFACTS_DIR | |
cp $TARBALL_OUTPUT_PATH $HERMES_TARBALL_ARTIFACTS_DIR/. | |
# mkdir -p /tmp/hermes/osx-bin/$BUILD_TYPE | |
# cp ./packages/react-native/sdks/hermes/build_macosx/bin/* /tmp/hermes/osx-bin/$BUILD_TYPE | |
# ls -lR /tmp/hermes/osx-bin/ | |
# Create dSYM archive | |
export WORKING_DIR="/tmp/hermes_tmp/dSYM/$BUILD_TYPE" | |
export DSYM_FILE_PATH=API/hermes/hermes.framework.dSYM | |
for slice in "${slices[@]}"; | |
do | |
mkdir -p "$WORKING_DIR/$slice" | |
cp -r build_${slice}_${BUILD_TYPE}/$DSYM_FILE_PATH "$WORKING_DIR/$slice/" | |
done | |
export DEST_DIR="/tmp/hermes/dSYM/$BUILD_TYPE" | |
tar -C "$WORKING_DIR" -czvf "hermes.framework.dSYM" . | |
mkdir -p "$DEST_DIR" | |
mv "hermes.framework.dSYM" "$DEST_DIR" | |
} | |
build_combined_slices "Release" | |
build_combined_slices "Debug" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment