-
Notifications
You must be signed in to change notification settings - Fork 9
/
build-re2.sh
executable file
·146 lines (130 loc) · 5.13 KB
/
build-re2.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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
#!/bin/bash
# exit when any command fails
set -e
# The -f option force the rebuild of IREE runtime frameworks.
while getopts hf flag; do
case "${flag}" in
f) FORCE_REBUILD="YES" ;;
*)
echo "$0 -h|-f"
echo " -h : display this message"
echo " -f : force rebuild runtime frameworks"
exit 0
;;
esac
done
SCRIPT_DIR=$(dirname "$(readlink -f "${BASH_SOURCE[0]}")")
SRC_DIR=$SCRIPT_DIR/re2
BUILD_DIR=$SCRIPT_DIR/build/re2
XCFRAMEWORK="$BUILD_DIR"/re2.xcframework
if [[ $FORCE_REBUILD == "YES" ]]; then
echo "┌------------------------------------------------------------------------------┐"
echo " Deleting existig RE2 frameworks ..."
echo "└------------------------------------------------------------------------------┘"
rm -rf "$BUILD_DIR"
fi
function build_for_ios() {
case $1 in
sim) sdk=iphonesimulator ;;
dev) sdk=iphoneos ;;
*)
echo "Unknown target $1 when calling build_for_ios"
exit 5
;;
esac
arch=$2
label=ios-$1-"$arch"
build_dir="$BUILD_DIR"/"$label"
test_file="$build_dir"/re2.framework/re2
if test -f "$test_file" && lipo -info "$test_file"; then
echo "Skip building iree.framework for $label."
else
echo "┌------------------------------------------------------------------------------┐"
echo " Building for $label ..."
echo " src: $SRC_DIR "
echo " build: $build_dir "
echo " build log: $build_dir/build.log"
echo "└------------------------------------------------------------------------------┘"
mkdir -p "$build_dir" # So to create the build.log file.
cmake -S . \
-B "$build_dir" \
-DCMAKE_SYSTEM_NAME=iOS \
-DCMAKE_OSX_SYSROOT="$(xcodebuild -version -sdk $sdk Path)" \
-DCMAKE_OSX_ARCHITECTURES="$arch" \
-DCMAKE_SYSTEM_PROCESSOR="$arch" \
-DCMAKE_OSX_DEPLOYMENT_TARGET=11.0 \
-DCMAKE_IOS_INSTALL_COMBINED=YES \
-DCMAKE_INSTALL_PREFIX="$build_dir"/install \
-DRE2_BUILD_TESTING=OFF \
>"$build_dir"/build.log 2>&1
cmake --build "$build_dir" >>"$build_dir"/build.log 2>&1
fi
}
function build_for_macos() {
arch=$1
label=macos-"$arch"
build_dir="$BUILD_DIR"/"$label"
test_file="$build_dir"/re2.framework/re2
if test -f "$test_file" && lipo -info "$test_file"; then
echo "Skip building iree.framework for $label."
else
echo "┌------------------------------------------------------------------------------┐"
echo " Building for $label ..."
echo " src: $SRC_DIR "
echo " build: $build_dir "
echo " build log: $build_dir/build.log"
echo "└------------------------------------------------------------------------------┘"
mkdir -p "$build_dir" # So to create the build.log file.
cmake -S . \
-B "$build_dir" \
-DRE2_BUILD_TESTING=OFF \
-DCMAKE_OSX_ARCHITECTURES="$arch" >"$build_dir"/build.log 2>&1
cmake --build "$build_dir" >"$build_dir"/build.log 2>&1
fi
}
function merge_fat_static_library() {
src_label=$2
dst_label=$1
src="$BUILD_DIR"/$src_label/re2/re2.framework/re2
dst="$BUILD_DIR"/$dst_label/re2/re2.framework/re2
if lipo -info "$dst" | grep 'Non-fat' >/dev/null; then
echo "┌------------------------------------------------------------------------------┐"
echo " Building FAT static library ..."
echo " merge: $src"
echo " into: $dst"
echo "└------------------------------------------------------------------------------┘"
merged=/tmp/libmerged-"$src_label"-"$dst_label".a
lipo "$src" "$dst" -create -output "$merged"
mv "$merged" "$dst"
fi
}
# Step 1. Build the following frameworks
#
# Note: We cannot build for dev-x86_64 because Apple does not offer
# SDK for it. If we do so, CMake will prompt us about missing required
# architecture x86_64 in file
# /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS16.2.sdk/usr/lib/libc++.tbd
# build_for_ios dev x86_64
#
# This step also merge dependent static libraries into the target library.
build_for_ios sim arm64
build_for_ios sim x86_64
build_for_ios dev arm64
build_for_macos x86_64
build_for_macos arm64
# Step 2. Merge the frameworks of the same OS platform
# ios-simulator-arm64+x86_64
# macos-arm64+x86_64
merge_fat_static_library ios-sim-arm64 ios-sim-x86_64
merge_fat_static_library macos-arm64 macos-x86_64
# Step 3. Merge the above frameworks into an XCFramework
echo "┌------------------------------------------------------------------------------┐"
echo " Aggregating frameworks into an xcframework ..."
echo "└------------------------------------------------------------------------------┘"
rm -rf "$XCFRAMEWORK"
xcodebuild -create-xcframework \
-framework "$BUILD_DIR"/macos-arm64/re2/re2.framework \
-framework "$BUILD_DIR"/ios-sim-arm64/re2/re2.framework \
-framework "$BUILD_DIR"/ios-dev-arm64/re2/re2.framework \
-output "$XCFRAMEWORK"
tree -L 1 -d "$XCFRAMEWORK"