-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathgenerate.sh
executable file
·90 lines (60 loc) · 2.91 KB
/
generate.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
#!/bin/sh
# based on https://rhonabwy.com/2023/02/10/creating-an-xcframework
XCFRAMEWORK_FOLDER="./output/DevolutionsCrypto.xcframework"
LIBNAME="devolutions_crypto_uniffi"
LIBNAMEBUILD="devolutions-crypto-uniffi"
rm -rf ./bindings
rm -rf ./output
cargo build -p "$LIBNAMEBUILD"
cargo run -p uniffi-bindgen generate --library "../../target/debug/lib$LIBNAME.dylib" --language swift -o bindings --no-format
mkdir ./bindings/mac
mkdir ./bindings/ios-simulator
rustup target add x86_64-apple-ios # iOS Simulator on Intel based mac
rustup target add aarch64-apple-ios-sim # iOS Simulator on Arm based mac
rustup target add aarch64-apple-ios # iOS & iPad
rustup target add aarch64-apple-darwin # Arm based mac
rustup target add x86_64-apple-darwin # Intel based mac
cargo build --release --target=x86_64-apple-ios -p "$LIBNAMEBUILD"
cargo build --release --target=aarch64-apple-ios-sim -p "$LIBNAMEBUILD"
cargo build --release --target=aarch64-apple-ios -p "$LIBNAMEBUILD"
cargo build --release --target=aarch64-apple-darwin -p "$LIBNAMEBUILD"
cargo build --release --target=x86_64-apple-darwin -p "$LIBNAMEBUILD"
mv "./bindings/devolutions_cryptoFFI.modulemap" ./bindings/module.modulemap
# combine the platforms
# ios simulator
lipo "../../target/x86_64-apple-ios/release/lib$LIBNAME.dylib" \
"../../target/aarch64-apple-ios-sim/release/lib$LIBNAME.dylib" \
-create -output "./bindings/ios-simulator/lib$LIBNAME.dylib"
# mac
lipo ../../target/x86_64-apple-darwin/release/lib$LIBNAME.dylib \
../../target/aarch64-apple-darwin/release/lib$LIBNAME.dylib \
-create -output ./bindings/mac/lib$LIBNAME.dylib
# no need to combine ios
# Move headers
mkdir headers
cp ./bindings/devolutions_crypto.swift ./headers
cp ./bindings/devolutions_cryptoFFI.h ./headers
cp ./bindings/module.modulemap ./headers
# create the XCFramework
xcodebuild -create-xcframework \
-library "./bindings/ios-simulator/lib$LIBNAME.dylib" -headers ./headers \
-library "./bindings/mac/lib$LIBNAME.dylib" -headers ./headers \
-library "../../target/aarch64-apple-ios/release/lib$LIBNAME.dylib" -headers ./headers \
-output "$XCFRAMEWORK_FOLDER"
# Compress XCFramework
ditto -c -k --sequesterRsrc --keepParent "$XCFRAMEWORK_FOLDER" "$XCFRAMEWORK_FOLDER.zip"
# Compute checksum
swift package compute-checksum "$XCFRAMEWORK_FOLDER.zip"
# Move swift file to package
cp "./bindings/devolutions_crypto.swift" ./DevolutionsCryptoSwift/Sources/DevolutionsCryptoSwift/DevolutionsCryptoSwift.swift
# Tests
cd ./DevolutionsCryptoSwift
swift test
cd ../
mkdir package
cp -R ./output/DevolutionsCrypto.xcframework ./package
cp -R ./DevolutionsCryptoSwift/Sources ./package
cp -R ./DevolutionsCryptoSwift/Tests ./package
cp ./DevolutionsCryptoSwift/Package.swift ./package
cp ./DevolutionsCryptoSwift.podspec ./package
sed -i '' 's|\.\./output/DevolutionsCrypto\.xcframework|./DevolutionsCrypto\.xcframework|g' ./package/Package.swift