2022-11-22 20:37:17 -08:00
|
|
|
#!/bin/bash
|
|
|
|
# This script builds local swift-bdk Swift language bindings and corresponding bdkFFI.xcframework.
|
|
|
|
# The results of this script can be used for locally testing your SPM package adding a local package
|
|
|
|
# to your application pointing at the bdk-swift directory.
|
2023-10-17 12:33:35 -04:00
|
|
|
|
2024-06-11 21:03:00 -05:00
|
|
|
HEADERPATH="Sources/BitcoinDevKit/BitcoinDevKitFFI.h"
|
|
|
|
MODMAPPATH="Sources/BitcoinDevKit/BitcoinDevKitFFI.modulemap"
|
|
|
|
TARGETDIR="../bdk-ffi/target"
|
|
|
|
OUTDIR="."
|
|
|
|
RELDIR="release-smaller"
|
|
|
|
NAME="bdkffi"
|
|
|
|
STATIC_LIB_NAME="lib${NAME}.a"
|
|
|
|
NEW_HEADER_DIR="../bdk-ffi/target/include"
|
|
|
|
|
|
|
|
# set required rust version and install component and targets
|
2024-04-19 14:47:26 -04:00
|
|
|
rustup default 1.77.1
|
2023-11-10 13:26:45 -06:00
|
|
|
rustup component add rust-src
|
2024-03-26 10:13:21 -04:00
|
|
|
rustup target add aarch64-apple-ios # iOS arm64
|
2023-11-21 14:48:49 -05:00
|
|
|
rustup target add x86_64-apple-ios # iOS x86_64
|
|
|
|
rustup target add aarch64-apple-ios-sim # simulator mac M1
|
|
|
|
rustup target add aarch64-apple-darwin # mac M1
|
|
|
|
rustup target add x86_64-apple-darwin # mac x86_64
|
2022-11-21 13:43:47 -06:00
|
|
|
|
2024-03-26 10:13:21 -04:00
|
|
|
cd ../bdk-ffi/ || exit
|
2022-11-21 13:43:47 -06:00
|
|
|
|
2024-06-11 21:03:00 -05:00
|
|
|
# build bdk-ffi rust lib for apple targets
|
2023-03-23 12:39:22 -04:00
|
|
|
cargo build --package bdk-ffi --profile release-smaller --target x86_64-apple-darwin
|
|
|
|
cargo build --package bdk-ffi --profile release-smaller --target aarch64-apple-darwin
|
|
|
|
cargo build --package bdk-ffi --profile release-smaller --target x86_64-apple-ios
|
|
|
|
cargo build --package bdk-ffi --profile release-smaller --target aarch64-apple-ios
|
2023-11-10 13:26:45 -06:00
|
|
|
cargo build --package bdk-ffi --profile release-smaller --target aarch64-apple-ios-sim
|
2022-11-21 13:43:47 -06:00
|
|
|
|
2024-06-11 21:03:00 -05:00
|
|
|
# build bdk-ffi Swift bindings and put in bdk-swift Sources
|
2024-04-30 15:54:50 -04:00
|
|
|
cargo run --bin uniffi-bindgen generate --library ./target/aarch64-apple-ios/release-smaller/libbdkffi.dylib --language swift --out-dir ../bdk-swift/Sources/BitcoinDevKit --no-format
|
|
|
|
|
2024-06-11 21:03:00 -05:00
|
|
|
# combine bdk-ffi static libs for aarch64 and x86_64 targets via lipo tool
|
2022-11-21 13:43:47 -06:00
|
|
|
mkdir -p target/lipo-ios-sim/release-smaller
|
2023-05-01 11:13:26 -05:00
|
|
|
lipo target/aarch64-apple-ios-sim/release-smaller/libbdkffi.a target/x86_64-apple-ios/release-smaller/libbdkffi.a -create -output target/lipo-ios-sim/release-smaller/libbdkffi.a
|
2022-11-21 13:43:47 -06:00
|
|
|
mkdir -p target/lipo-macos/release-smaller
|
|
|
|
lipo target/aarch64-apple-darwin/release-smaller/libbdkffi.a target/x86_64-apple-darwin/release-smaller/libbdkffi.a -create -output target/lipo-macos/release-smaller/libbdkffi.a
|
|
|
|
|
2024-03-26 10:13:21 -04:00
|
|
|
cd ../bdk-swift/ || exit
|
2024-06-11 21:03:00 -05:00
|
|
|
|
|
|
|
# move bdk-ffi static lib header files to temporary directory
|
|
|
|
mkdir -p "${NEW_HEADER_DIR}"
|
|
|
|
mv "${HEADERPATH}" "${NEW_HEADER_DIR}"
|
|
|
|
mv "${MODMAPPATH}" "${NEW_HEADER_DIR}/module.modulemap"
|
|
|
|
|
|
|
|
# remove old xcframework directory
|
|
|
|
rm -rf "${OUTDIR}/${NAME}.xcframework"
|
|
|
|
|
|
|
|
# create new xcframework directory from bdk-ffi static libs and headers
|
|
|
|
xcodebuild -create-xcframework \
|
|
|
|
-library "${TARGETDIR}/lipo-macos/${RELDIR}/${STATIC_LIB_NAME}" \
|
|
|
|
-headers "${NEW_HEADER_DIR}" \
|
|
|
|
-library "${TARGETDIR}/aarch64-apple-ios/${RELDIR}/${STATIC_LIB_NAME}" \
|
|
|
|
-headers "${NEW_HEADER_DIR}" \
|
|
|
|
-library "${TARGETDIR}/lipo-ios-sim/${RELDIR}/${STATIC_LIB_NAME}" \
|
|
|
|
-headers "${NEW_HEADER_DIR}" \
|
|
|
|
-output "${OUTDIR}/${NAME}.xcframework"
|