|
| 1 | +#!/bin/bash -e |
| 2 | + |
| 3 | +echo "Verify and install required targets" |
| 4 | +targets=( |
| 5 | + "x86_64-apple-ios" |
| 6 | + "aarch64-apple-ios" |
| 7 | + "aarch64-apple-ios-sim" |
| 8 | + "aarch64-apple-darwin" |
| 9 | + "x86_64-apple-darwin" |
| 10 | +) |
| 11 | + |
| 12 | +for target in "${targets[@]}"; do |
| 13 | + if ! rustup target list | grep -q "$target (installed)"; then |
| 14 | + echo "Target $target is not installed. Installing..." |
| 15 | + rustup target add "$target" |
| 16 | + echo "Target $target installed." |
| 17 | + else |
| 18 | + echo "Target $target is already installed." |
| 19 | + fi |
| 20 | +done |
| 21 | + |
| 22 | +# Create output directories |
| 23 | +mkdir -p ./target/universal-ios-sim/release || true |
| 24 | +mkdir -p ./target/universal-darwin/release || true |
| 25 | + |
| 26 | +# Generate Uniffi bindings |
| 27 | +echo "Creating uniffi bindings" |
| 28 | +uniffi-bindgen generate src/anoncreds.udl --language swift -o ./wrappers/swift/anoncreds |
| 29 | + |
| 30 | +# Build targets |
| 31 | +echo "Build all targets" |
| 32 | +for target in "${targets[@]}"; do |
| 33 | + echo "Starting $target build" |
| 34 | + cargo build --release --target "$target" |
| 35 | + echo "Finished $target build" |
| 36 | +done |
| 37 | + |
| 38 | +# Remove existing files in the destination directories |
| 39 | +rm -f ./target/universal-ios-sim/release/libanoncreds_uniffi.a || true |
| 40 | +rm -f ./target/universal-darwin/release/libanoncreds_uniffi.a || true |
| 41 | +rm -dr ./target/universal/libanoncreds.xcframework || true |
| 42 | + |
| 43 | +# Create universal libraries |
| 44 | +echo "Creating lipo universal libraries" |
| 45 | +lipo -create ./target/aarch64-apple-ios-sim/release/libanoncreds_uniffi.a ./target/x86_64-apple-ios/release/libanoncreds_uniffi.a -output ./target/universal-ios-sim/release/libanoncreds_uniffi.a |
| 46 | + |
| 47 | +lipo -create ./target/aarch64-apple-darwin/release/libanoncreds_uniffi.a ./target/x86_64-apple-darwin/release/libanoncreds_uniffi.a -output ./target/universal-darwin/release/libanoncreds_uniffi.a |
| 48 | + |
| 49 | +# Create XCFramework |
| 50 | +echo "Creating xcframework" |
| 51 | +xcodebuild -create-xcframework \ |
| 52 | + -library ./target/aarch64-apple-ios/release/libanoncreds_uniffi.a \ |
| 53 | + -headers ./wrappers/swift/anoncreds/ \ |
| 54 | + -library ./target/universal-ios-sim/release/libanoncreds_uniffi.a \ |
| 55 | + -headers ./wrappers/swift/anoncreds/ \ |
| 56 | + -library ./target/universal-darwin/release/libanoncreds_uniffi.a \ |
| 57 | + -headers ./wrappers/swift/anoncreds/ \ |
| 58 | + -output ./target/universal/libanoncreds.xcframework |
| 59 | + |
| 60 | +echo "Removing .swift files from headers" |
| 61 | +dir="./target/universal/libanoncreds.xcframework" |
| 62 | + |
| 63 | +# Compress and copy XCFramework |
| 64 | +target_dir_name="libanoncreds.xcframework" |
| 65 | +source_dir="./target/universal/" |
| 66 | +dest_dir="./output-frameworks/anoncreds-swift" |
| 67 | +zip_name="libanoncreds.xcframework.zip" |
| 68 | + |
| 69 | +echo "Zip xcframework" |
| 70 | +rm -f "$dest_dir/$zip_name" || true |
| 71 | +zip -r "$dest_dir/$zip_name" "$source_dir/$target_dir_name" |
| 72 | + |
| 73 | +echo "Copy .swift binders" |
| 74 | +rm -f "./output-frameworks/anoncreds-swift/AnoncredsSwift/Sources/Swift/anoncreds.swift" || true |
| 75 | +mv "./wrappers/swift/anoncreds/anoncreds.swift" "./output-frameworks/anoncreds-swift/AnoncredsSwift/Sources/Swift/anoncreds.swift" |
| 76 | + |
| 77 | +rm -f "/wrappers/swift/anoncreds/anoncreds.swift" || true |
| 78 | + |
0 commit comments