|
| 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 | +} |
0 commit comments