-
Notifications
You must be signed in to change notification settings - Fork 163
/
build-ios.sh
executable file
·207 lines (180 loc) · 6.53 KB
/
build-ios.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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
#!/usr/bin/env bash
set -ex
dir=build-ios
mkdir -p $dir
cd $dir
if [ ! -f openmp-11.0.0.src.tar.xz ]; then
wget https://github.com/llvm/llvm-project/releases/download/llvmorg-11.0.0/openmp-11.0.0.src.tar.xz
fi
if [ ! -d openmp-11.0.0.src ]; then
tar -xf openmp-11.0.0.src.tar.xz
pushd openmp-11.0.0.src
sed -i'' -e '/.size __kmp_unnamed_critical_addr/d' runtime/src/z_Linux_asm.S
sed -i'' -e 's/__kmp_unnamed_critical_addr/___kmp_unnamed_critical_addr/g' runtime/src/z_Linux_asm.S
popd
fi
if [ ! -f openmp-11.0.0.src/build/os64/install/include/omp.h ]; then
pushd openmp-11.0.0.src
mkdir -p build
# iOS & simulator running on arm64 & x86_64
cmake -S . \
-DCMAKE_TOOLCHAIN_FILE=../../toolchains/ios.toolchain.cmake \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_INSTALL_PREFIX=install \
-DPLATFORM=OS64 \
-DENABLE_BITCODE=0 -DENABLE_ARC=0 -DENABLE_VISIBILITY=0 \
-DPERL_EXECUTABLE=$(which perl) \
-DLIBOMP_ENABLE_SHARED=OFF \
-DLIBOMP_OMPT_SUPPORT=OFF \
-DLIBOMP_USE_HWLOC=OFF \
-B build/os64
cmake -S . \
-DCMAKE_TOOLCHAIN_FILE=../../toolchains/ios.toolchain.cmake \
-DCMAKE_BUILD_TYPE=Release \
-DPLATFORM=SIMULATORARM64 \
-DENABLE_BITCODE=0 -DENABLE_ARC=0 -DENABLE_VISIBILITY=0 \
-DPERL_EXECUTABLE=$(which perl) \
-DLIBOMP_ENABLE_SHARED=OFF \
-DLIBOMP_OMPT_SUPPORT=OFF \
-DLIBOMP_USE_HWLOC=OFF \
-B build/simulator_arm64
cmake -S . \
-DCMAKE_TOOLCHAIN_FILE=../../toolchains/ios.toolchain.cmake \
-DCMAKE_BUILD_TYPE=Release \
-DPLATFORM=SIMULATOR64 \
-DENABLE_BITCODE=0 -DENABLE_ARC=0 -DENABLE_VISIBILITY=0 \
-DPERL_EXECUTABLE=$(which perl) \
-DLIBOMP_ENABLE_SHARED=OFF \
-DLIBOMP_OMPT_SUPPORT=OFF \
-DLIBOMP_USE_HWLOC=OFF \
-B build/simulator_x86_64
# It generates the following files in the directory install
# .
# ├── include
# │ └── omp.h
# └── lib
# ├── libgomp.a -> libomp.a
# ├── libiomp5.a -> libomp.a
# └── libomp.a
#
# 2 directories, 4 files
cmake --build ./build/os64 -j 4
# Generate header for sharper-ncnn.xcframework
cmake --build ./build/os64 --target install
cmake --build ./build/simulator_arm64 -j 4
cmake --build ./build/simulator_x86_64 -j 4
mkdir -p "./build/simulator/openmp"
lipo -create build/simulator_x86_64/runtime/src/libomp.a \
build/simulator_arm64/runtime/src/libomp.a \
-output build/simulator/openmp/libomp.a
# Return to parent directory to create xcframework
popd
rm -rf openmp.xcframework
xcodebuild -create-xcframework \
-library "openmp-11.0.0.src/build/os64/runtime/src/libomp.a" \
-library "openmp-11.0.0.src/build/simulator/openmp/libomp.a" \
-output openmp.xcframework
# Copy Headers
mkdir -p openmp.xcframework/Headers
cp -v openmp-11.0.0.src/install/include/omp.h openmp.xcframework/Headers
fi
export CPLUS_INCLUDE_PATH=$PWD/openmp.xcframework/Headers/:$CPLUS_INCLUDE_PATH
mkdir -p build
cmake -S .. \
-DCMAKE_TOOLCHAIN_FILE=./toolchains/ios.toolchain.cmake \
-DPLATFORM=OS64 \
-DENABLE_BITCODE=0 \
-DENABLE_ARC=0 \
-DENABLE_VISIBILITY=0 \
-DOpenMP_C_FLAGS="-Xclang -fopenmp" \
-DOpenMP_CXX_FLAGS="-Xclang -fopenmp" \
-DOpenMP_C_LIB_NAMES="libomp" \
-DOpenMP_CXX_LIB_NAMES="libomp" \
-DOpenMP_libomp_LIBRARY="$PWD/openmp.xcframework/ios-arm64/libomp.a" \
-DCMAKE_INSTALL_PREFIX=./install \
-DCMAKE_BUILD_TYPE=Release \
-DBUILD_SHARED_LIBS=OFF \
-DSHERPA_NCNN_ENABLE_PYTHON=OFF \
-DSHERPA_NCNN_ENABLE_PORTAUDIO=OFF \
-DSHERPA_NCNN_ENABLE_JNI=OFF \
-DSHERPA_NCNN_ENABLE_BINARY=OFF \
-DSHERPA_NCNN_ENABLE_TEST=OFF \
-DSHERPA_NCNN_ENABLE_C_API=ON \
-B build/os64
cmake -S .. \
-DCMAKE_TOOLCHAIN_FILE=./toolchains/ios.toolchain.cmake \
-DPLATFORM=SIMULATORARM64 \
-DENABLE_BITCODE=0 \
-DENABLE_ARC=0 \
-DENABLE_VISIBILITY=0 \
-DOpenMP_C_FLAGS="-Xclang -fopenmp" \
-DOpenMP_CXX_FLAGS="-Xclang -fopenmp" \
-DOpenMP_C_LIB_NAMES="libomp" \
-DOpenMP_CXX_LIB_NAMES="libomp" \
-DOpenMP_libomp_LIBRARY="$PWD/openmp.xcframework/ios-arm64_x86_64-simulator/libomp.a" \
-DCMAKE_BUILD_TYPE=Release \
-DBUILD_SHARED_LIBS=OFF \
-DSHERPA_NCNN_ENABLE_PYTHON=OFF \
-DSHERPA_NCNN_ENABLE_PORTAUDIO=OFF \
-DSHERPA_NCNN_ENABLE_JNI=OFF \
-DSHERPA_NCNN_ENABLE_BINARY=OFF \
-DSHERPA_NCNN_ENABLE_TEST=OFF \
-DSHERPA_NCNN_ENABLE_C_API=ON \
-B build/simulator_arm64
cmake -S .. \
-DCMAKE_TOOLCHAIN_FILE=./toolchains/ios.toolchain.cmake \
-DPLATFORM=SIMULATOR64 \
-DENABLE_BITCODE=0 \
-DENABLE_ARC=0 \
-DENABLE_VISIBILITY=0 \
-DOpenMP_C_FLAGS="-Xclang -fopenmp" \
-DOpenMP_CXX_FLAGS="-Xclang -fopenmp" \
-DOpenMP_C_LIB_NAMES="libomp" \
-DOpenMP_CXX_LIB_NAMES="libomp" \
-DOpenMP_libomp_LIBRARY="$PWD/openmp.xcframework/ios-arm64_x86_64-simulator/libomp.a" \
-DCMAKE_BUILD_TYPE=Release \
-DBUILD_SHARED_LIBS=OFF \
-DSHERPA_NCNN_ENABLE_PYTHON=OFF \
-DSHERPA_NCNN_ENABLE_PORTAUDIO=OFF \
-DSHERPA_NCNN_ENABLE_JNI=OFF \
-DSHERPA_NCNN_ENABLE_BINARY=OFF \
-DSHERPA_NCNN_ENABLE_TEST=OFF \
-DSHERPA_NCNN_ENABLE_C_API=ON \
-B build/simulator_x86_64
cmake --build build/os64 -j 4
# Generate headers for sherpa-ncnn.xcframework
cmake --build build/os64 --target install
# Clean files
rm -rf install/lib/cmake
rm -rf install/lib/pkgconfig
rm -rf install/include/ncnn
rm -rf install/include/kaldi-native-fbank
cmake --build build/simulator_arm64 -j 8
cmake --build build/simulator_x86_64 -j 8
# For sherpa-ncnn.xcframework
rm -rf sherpa-ncnn.xcframework
libtool -static -o build/os64/sherpa-ncnn.a \
build/os64/lib/libncnn.a \
build/os64/lib/libsherpa-ncnn-c-api.a \
build/os64/lib/libsherpa-ncnn-core.a \
build/os64/lib/libkaldi-native-fbank-core.a
mkdir -p "build/simulator/lib"
for f in libncnn.a libsherpa-ncnn-c-api.a libsherpa-ncnn-core.a libkaldi-native-fbank-core.a; do
lipo -create build/simulator_arm64/lib/${f} \
build/simulator_x86_64/lib/${f} \
-output build/simulator/lib/${f}
done
# Merge archive first, because the following xcodebuild create xcframework
# cannot accept multi archive with the same architecture.
libtool -static -o build/simulator/sherpa-ncnn.a \
build/simulator/lib/libncnn.a \
build/simulator/lib/libsherpa-ncnn-c-api.a \
build/simulator/lib/libsherpa-ncnn-core.a \
build/simulator/lib/libkaldi-native-fbank-core.a
xcodebuild -create-xcframework \
-library "build/os64/sherpa-ncnn.a" \
-library "build/simulator/sherpa-ncnn.a" \
-output sherpa-ncnn.xcframework
# Copy Headers
mkdir -p sherpa-ncnn.xcframework/Headers
cp -av install/include/* sherpa-ncnn.xcframework/Headers