diff --git a/Cargo.toml b/Cargo.toml index 954e596..b8512b1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,16 +6,16 @@ edition = "2018" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [lib] -crate-type = ["cdylib"] +crate-type = ["staticlib", "cdylib"] [dependencies] bdk = { version = "^0.12.1-dev", features = ["all-keys", "use-esplora-ureq"] } -uniffi_macros = "0.14.0" -uniffi = "0.14.0" +uniffi_macros = "0.14.1" +uniffi = "0.14.1" thiserror = "1.0" [build-dependencies] -uniffi_build = "0.14.0" +uniffi_build = "0.14.1" [patch.crates-io] bdk = { git = "https://github.com/artfuldev/bdk.git", branch = "use-send-and-sync-on-memory-database" } diff --git a/build.sh b/build.sh index 13302c7..3a0d37c 100755 --- a/build.sh +++ b/build.sh @@ -44,9 +44,46 @@ copy_lib_kotlin() { ## bdk-bdk-kotlin jar build_kotlin() { + copy_lib_kotlin uniffi-bindgen generate src/bdk.udl --no-format --out-dir bindings/bdk-kotlin/jvm/src/main/kotlin --language kotlin } +## bdk swift +build_swift() { + uniffi-bindgen generate src/bdk.udl --no-format --out-dir bindings/bdk-swift/ --language swift + swiftc -module-name bdk -emit-library -o libuniffi_bdk.dylib -emit-module -emit-module-path ./bindings/bdk-swift/ -parse-as-library -L ./target/debug/ -luniffi_bdk -Xcc -fmodule-map-file=./bindings/bdk-swift/bdkFFI.modulemap ./bindings/bdk-swift/bdk.swift + TARGETDIR=target + RELDIR=debug + STATIC_LIB_NAME=libuniffi_bdk.a + + # We can't use cargo lipo because we can't link to universal libraries :( + # https://github.com/rust-lang/rust/issues/55235 + LIBS_ARCHS=("x86_64" "arm64") + IOS_TRIPLES=("x86_64-apple-ios" "aarch64-apple-ios") + for i in "${!LIBS_ARCHS[@]}"; do + cargo build --target "${IOS_TRIPLES[${i}]}" + done + + UNIVERSAL_BINARY=./${TARGETDIR}/ios/universal/${RELDIR}/${STATIC_LIB_NAME} + NEED_LIPO= + + # if the universal binary doesnt exist, or if it's older than the static libs, + # we need to run `lipo` again. + if [[ ! -f "${UNIVERSAL_BINARY}" ]]; then + NEED_LIPO=1 + elif [[ "$(stat -f "%m" "./${TARGETDIR}/x86_64-apple-ios/${RELDIR}/${STATIC_LIB_NAME}")" -gt "$(stat -f "%m" "${UNIVERSAL_BINARY}")" ]]; then + NEED_LIPO=1 + elif [[ "$(stat -f "%m" "./${TARGETDIR}/aarch64-apple-ios/${RELDIR}/${STATIC_LIB_NAME}")" -gt "$(stat -f "%m" "${UNIVERSAL_BINARY}")" ]]; then + NEED_LIPO=1 + fi + if [[ "${NEED_LIPO}" = "1" ]]; then + mkdir -p "${TARGETDIR}/ios/universal/${RELDIR}" + lipo -create -output "${UNIVERSAL_BINARY}" \ + "${TARGETDIR}/x86_64-apple-ios/${RELDIR}/${STATIC_LIB_NAME}" \ + "${TARGETDIR}/aarch64-apple-ios/${RELDIR}/${STATIC_LIB_NAME}" + fi +} + ## rust android build_android() { build_kotlin @@ -96,12 +133,12 @@ then help else build_rust - copy_lib_kotlin while [ -n "$1" ]; do # while loop starts case "$1" in -a) build_android ;; -k) build_kotlin ;; + -s) build_swift ;; -h) help ;; *) echo "Option $1 not recognized" ;; esac