|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +# This script builds local cktap Swift language bindings and corresponding cktapFFI.xcframework. |
| 4 | + |
| 5 | +TARGETDIR="../target" |
| 6 | +OUTDIR="." |
| 7 | +RELDIR="release-smaller" |
| 8 | +NAME="cktapFFI" |
| 9 | +STATIC_LIB_NAME="lib${NAME}.a" |
| 10 | +NEW_HEADER_DIR="../target/include" |
| 11 | + |
| 12 | +# set required rust version and install component and targets |
| 13 | +rustup default 1.77.1 |
| 14 | +rustup component add rust-src |
| 15 | +rustup target add aarch64-apple-ios # iOS arm64 |
| 16 | +rustup target add x86_64-apple-ios # iOS x86_64 |
| 17 | +rustup target add aarch64-apple-ios-sim # simulator mac M1 |
| 18 | +rustup target add aarch64-apple-darwin # mac M1 |
| 19 | +rustup target add x86_64-apple-darwin # mac x86_64 |
| 20 | + |
| 21 | +# Create all required directories first |
| 22 | +mkdir -p Sources/CKTap |
| 23 | +mkdir -p ../target/include |
| 24 | +mkdir -p ../target/lipo-macos/release-smaller |
| 25 | +mkdir -p ../target/lipo-ios-sim/release-smaller |
| 26 | + |
| 27 | +cd ../ || exit |
| 28 | + |
| 29 | +# build cktap-ffi rust lib for apple targets |
| 30 | +cargo build --package rust-cktap --profile release-smaller --target x86_64-apple-darwin |
| 31 | +cargo build --package rust-cktap --profile release-smaller --target aarch64-apple-darwin |
| 32 | +cargo build --package rust-cktap --profile release-smaller --target x86_64-apple-ios |
| 33 | +cargo build --package rust-cktap --profile release-smaller --target aarch64-apple-ios |
| 34 | +cargo build --package rust-cktap --profile release-smaller --target aarch64-apple-ios-sim |
| 35 | + |
| 36 | +# Then run uniffi-bindgen |
| 37 | +cargo run --bin uniffi-bindgen generate \ |
| 38 | + --library target/aarch64-apple-ios/release-smaller/librust_cktap.dylib \ |
| 39 | + --language swift \ |
| 40 | + --out-dir cktap-swift/Sources/CKTap \ |
| 41 | + --no-format |
| 42 | + |
| 43 | +# combine cktap-ffi static libs for aarch64 and x86_64 targets via lipo tool |
| 44 | +lipo target/aarch64-apple-ios-sim/release-smaller/librust_cktap.a target/x86_64-apple-ios/release-smaller/librust_cktap.a -create -output target/lipo-ios-sim/release-smaller/libcktapFFI.a |
| 45 | + |
| 46 | +lipo target/aarch64-apple-darwin/release-smaller/librust_cktap.a target/x86_64-apple-darwin/release-smaller/librust_cktap.a -create -output target/lipo-macos/release-smaller/libcktapFFI.a |
| 47 | + |
| 48 | +cd cktap-swift || exit |
| 49 | + |
| 50 | +# move cktap-ffi static lib header files to temporary directory |
| 51 | +mv "Sources/CKTap/rust_cktapFFI.h" "${NEW_HEADER_DIR}" |
| 52 | +mv "Sources/CKTap/rust_cktapFFI.modulemap" "${NEW_HEADER_DIR}/module.modulemap" |
| 53 | + |
| 54 | +# remove old xcframework directory |
| 55 | +rm -rf "${OUTDIR}/${NAME}.xcframework" |
| 56 | + |
| 57 | +# create new xcframework directory from cktap-ffi static libs and headers |
| 58 | +xcodebuild -create-xcframework \ |
| 59 | + -library "${TARGETDIR}/lipo-macos/${RELDIR}/librust_cktap.a" \ |
| 60 | + -headers "${NEW_HEADER_DIR}" \ |
| 61 | + -library "${TARGETDIR}/aarch64-apple-ios/${RELDIR}/librust_cktap.a" \ |
| 62 | + -headers "${NEW_HEADER_DIR}" \ |
| 63 | + -library "${TARGETDIR}/lipo-ios-sim/${RELDIR}/librust_cktap.a" \ |
| 64 | + -headers "${NEW_HEADER_DIR}" \ |
| 65 | + -output "${OUTDIR}/${NAME}.xcframework" |
0 commit comments