-
Notifications
You must be signed in to change notification settings - Fork 632
/
build-apple-framework.sh
executable file
·128 lines (105 loc) · 3.75 KB
/
build-apple-framework.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
#!/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 [ "$DEBUG" = true ]; then
BUILD_TYPE="Debug"
else
BUILD_TYPE="Release"
fi
function command_exists {
command -v "${1}" > /dev/null 2>&1
}
if command_exists "cmake"; then
if command_exists "ninja"; then
BUILD_SYSTEM="Ninja"
else
BUILD_SYSTEM="Unix Makefiles"
fi
else
echo >&2 'CMake is required to install Hermes, install it with: brew install cmake'
exit 1
fi
function get_release_version {
ruby -rcocoapods-core -rjson -e "puts Pod::Specification.from_file('hermes-engine.podspec').version"
}
function get_ios_deployment_target {
ruby -rcocoapods-core -rjson -e "puts Pod::Specification.from_file('hermes-engine.podspec').deployment_target('ios')"
}
function get_visionos_deployment_target {
ruby -rcocoapods-core -rjson -e "puts Pod::Specification.from_file('hermes-engine.podspec').deployment_target('visionos')"
}
function get_tvos_deployment_target {
ruby -rcocoapods-core -rjson -e "puts Pod::Specification.from_file('hermes-engine.podspec').deployment_target('tvos')"
}
function get_mac_deployment_target {
ruby -rcocoapods-core -rjson -e "puts Pod::Specification.from_file('hermes-engine.podspec').deployment_target('osx')"
}
# Build host hermes compiler for internal bytecode
function build_host_hermesc {
cmake -S . -B build_host_hermesc
cmake --build ./build_host_hermesc --target hermesc
}
# Utility function to configure an Apple framework
function configure_apple_framework {
local build_cli_tools enable_bitcode
if [[ $1 == appletvos || $1 == iphoneos || $1 == catalyst || $1 == visionos ]]; then
enable_bitcode="true"
else
enable_bitcode="false"
fi
if [[ $1 == macosx ]]; then
build_cli_tools="true"
else
build_cli_tools="false"
fi
cmake -S . -B "build_$1" -G "$BUILD_SYSTEM" \
-DHERMES_APPLE_TARGET_PLATFORM:STRING="$1" \
-DCMAKE_OSX_ARCHITECTURES:STRING="$2" \
-DCMAKE_OSX_DEPLOYMENT_TARGET:STRING="$3" \
-DHERMES_ENABLE_DEBUGGER:BOOLEAN=true \
-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="$enable_bitcode" \
-DHERMES_BUILD_APPLE_FRAMEWORK:BOOLEAN=true \
-DHERMES_BUILD_SHARED_JSI:BOOLEAN=false \
-DHERMES_BUILD_APPLE_DSYM:BOOLEAN=true \
-DHERMES_ENABLE_TOOLS:BOOLEAN="$build_cli_tools" \
-DIMPORT_HERMESC:PATH="$PWD/build_host_hermesc/ImportHermesc.cmake" \
-DCMAKE_INSTALL_PREFIX:PATH=../destroot \
-DCMAKE_BUILD_TYPE="$BUILD_TYPE"
}
# Utility function to build an Apple framework
function build_apple_framework {
echo "Building framework for $1 with architectures: $2"
build_host_hermesc
[ ! -f "$PWD/build_host_hermesc/ImportHermesc.cmake" ] &&
echo "Host hermesc is required to build apple frameworks!"
configure_apple_framework "$1" "$2" "$3"
if [[ "$BUILD_SYSTEM" == "Ninja" ]]; then
(cd "./build_$1" && ninja install/strip)
else
(cd "./build_$1" && make install/strip)
fi
}
# 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 {
cd ./destroot/Library/Frameworks || exit 1
local platforms=("$@")
local args=""
echo "Creating universal framework for platforms: ${platforms[*]}"
for i in "${!platforms[@]}"; do
args+="-framework ${platforms[$i]}/hermes.framework "
done
mkdir universal
xcodebuild -create-xcframework $args -output "universal/hermes.xcframework"
for platform in $@; do
rm -r "$platform"
done
cd - || exit 1
}