forked from eycorsican/leaf
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild_apple_xcframework.sh
executable file
·79 lines (67 loc) · 2.58 KB
/
build_apple_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
75
76
77
78
79
#!/usr/bin/env sh
set -x
mode=release
release_flag=--release
package=leaf-ffi
name=leaf
lib=lib$name.a
# The script is assumed to run in the root of the workspace
base=$(dirname "$0")
# Debug or release build?
if [ "$1" = "debug" ]; then
mode=debug
release_flag=
fi
# Build for all desired targets
rustup target add x86_64-apple-darwin
rustup target add aarch64-apple-darwin
rustup target add aarch64-apple-ios
rustup target add x86_64-apple-ios
rustup target add aarch64-apple-ios-sim
cargo build -p $package $release_flag --no-default-features --features "default-openssl outbound-quic" --target x86_64-apple-darwin
cargo build -p $package $release_flag --no-default-features --features "default-openssl outbound-quic" --target aarch64-apple-darwin
cargo build -p $package $release_flag --no-default-features --features "default-openssl outbound-quic" --target aarch64-apple-ios
cargo build -p $package $release_flag --no-default-features --features "default-openssl outbound-quic" --target x86_64-apple-ios
cargo build -p $package $release_flag --no-default-features --features "default-ring outbound-quic" --target aarch64-apple-ios-sim
# Directories to put the libraries.
rm -rf target/apple/$mode
mkdir -p target/apple/$mode/include
mkdir -p target/apple/$mode/ios
mkdir -p target/apple/$mode/ios-sim
mkdir -p target/apple/$mode/macos
# Put built libraries to folders where we can find them easier later
cp target/aarch64-apple-ios/$mode/$lib target/apple/$mode/ios/
lipo -create \
-arch x86_64 target/x86_64-apple-ios/$mode/$lib \
-arch arm64 target/aarch64-apple-ios-sim/$mode/$lib \
-output target/apple/$mode/ios-sim/$lib
# Create a single library for multiple archs
lipo -create \
-arch x86_64 target/x86_64-apple-darwin/$mode/$lib \
-arch arm64 target/aarch64-apple-darwin/$mode/$lib \
-output target/apple/$mode/macos/$lib
# Generate the header file
cbindgen \
--config $package/cbindgen.toml \
$package/src/lib.rs > target/apple/$mode/include/$name.h
wd="$base/../target/apple/$mode"
# Remove existing artifact
rm -rf "$wd/$name.xcframework"
# A modulemap is required for the compiler to find the module when using Swift
cat << EOF > "$wd/include/module.modulemap"
module $name {
header "$name.h"
export *
}
EOF
# Create the XCFramework packaging both iOS and macOS static libraries, so we can
# use a single XCFramework for both platforms.
xcodebuild -create-xcframework \
-library "$wd/ios/$lib" \
-headers "$wd/include" \
-library "$wd/ios-sim/$lib" \
-headers "$wd/include" \
-library "$wd/macos/$lib" \
-headers "$wd/include" \
-output "$wd/$name.xcframework"
ls $wd/$name.xcframework