-
Notifications
You must be signed in to change notification settings - Fork 0
/
xcframework.sh
74 lines (55 loc) · 2.26 KB
/
xcframework.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
#!/bin/zsh
set -euxo pipefail
rm -rf oneTBB-2021.13.0
rm -rf v2021.13.0.tar.gz
rm -rf tbb.xcframework
rm -rf tbb.xcframework.zip
wget https://github.com/oneapi-src/oneTBB/archive/refs/tags/v2021.13.0.tar.gz
tar zxf v2021.13.0.tar.gz
cd oneTBB-2021.13.0
# See https://github.com/Homebrew/homebrew-core/blob/master/Formula/t/tbb.rb
# Apply patch to header so the headers play nice with frameworks (ugh)
patch include/oneapi/tbb/tbb_allocator.h ../tbb.patch
# [Apple says](https://developer.apple.com/documentation/xcode/creating-a-multi-platform-binary-framework-bundle):
# Avoid using dynamic library files (.dylib files) for dynamic linking.
# An XCFramework can include dynamic library files, but only macOS supports these libraries for dynamic linking.
# Dynamic linking on iOS, watchOS, and tvOS requires the XCFramework to contain .framework bundles.```
# Also: error: an xcframework cannot contain both frameworks and libraries.
# So we have to build frameworks for each target.
# macOS build
mkdir build && cd build
cmake .. -DCMAKE_BUILD_TYPE=Release \
-DBUILD_SHARED_LIBS=OFF
make -j 12
ctest
cd ..
# ios build
mkdir build_ios && cd build_ios
cmake .. -DCMAKE_SYSTEM_NAME=iOS \
-DCMAKE_OSX_DEPLOYMENT_TARGET=11.0 \
-DCMAKE_BUILD_TYPE=Release \
-DBUILD_SHARED_LIBS=OFF \
-DTBB_TEST=OFF
make -j 12 target=ios
cd ..
# ios simulator build
mkdir build_ios_sim && cd build_ios_sim
cmake .. -DCMAKE_TOOLCHAIN_FILE=../../ios.toolchain.cmake \
-DPLATFORM=SIMULATORARM64 \
-DBUILD_SHARED_LIBS=OFF \
-DTBB_TEST=OFF
make -j 12 tareget=ios
cd ..
NAME=appleclang_16.0_cxx11_64_release
SIMNAME=appleclang_16.0_cxx11_64_relwithdebinfo
libtool -static -o tbb_macos.a build/$NAME/libtbb.a build/$NAME/libtbbmalloc.a
libtool -static -o tbb_ios.a build_ios/$NAME/libtbb.a build_ios/$NAME/libtbbmalloc.a
libtool -static -o tbb_ios_sim.a build_ios_sim/$SIMNAME/libtbb.a build_ios_sim/$SIMNAME/libtbbmalloc.a
xcodebuild -create-xcframework \
-library tbb_macos.a -headers include \
-library tbb_ios.a -headers include \
-library tbb_ios_sim.a -headers include \
-output ../tbb.xcframework
cd ..
zip -r tbb.xcframework.zip tbb.xcframework
swift package compute-checksum tbb.xcframework.zip