Skip to content

Commit

Permalink
build: update scripts to build xcframework
Browse files Browse the repository at this point in the history
  • Loading branch information
notmandatory committed Nov 9, 2024
1 parent f680f5b commit 6c4d3a7
Show file tree
Hide file tree
Showing 16 changed files with 85 additions and 189 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ bdkFFI.h
BitcoinDevKit.swift
bdk.swift
.build
bdkffi.xcframework
*.modulemap

# Python related
__pycache__
9 changes: 6 additions & 3 deletions bdk-swift/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,14 @@ let package = Package(
.binaryTarget(name: "bdkFFI", path: "./bdkFFI.xcframework"),
.target(
name: "BitcoinDevKit",
dependencies: ["bdkFFI"],
swiftSettings: [.unsafeFlags(["-suppress-warnings"])]
dependencies: ["bdkFFI"]
),
.testTarget(
name: "BitcoinDevKitTests",
dependencies: ["BitcoinDevKit"]),
dependencies: ["BitcoinDevKit"],
resources: [
.copy("Resources/pre_existing_wallet_persistence_test.sqlite")
]
),
]
)
4 changes: 2 additions & 2 deletions bdk-swift/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import BitcoinDevKit

Swift Package Manager releases for `bdk-swift` are published to a separate repository (https://github.com/bitcoindevkit/bdk-swift), and that is where the releases are created for it.

The `bdk-swift/build-local-swift.sh` script can be used instead to create a version of the project for local testing.
The `bdk-swift/build-xcframework.sh` script can be used instead to create a version of the project for local testing.

### How to test

Expand All @@ -35,7 +35,7 @@ swift test

### Example Projects

* [BdkSwiftSample](https://github.com/futurepaul/BdkSwiftSample), iOS
* [BDKSwiftExampleWallet](https://github.com/bitcoindevkit/BDKSwiftExampleWallet), iOS

## How to Build and Publish

Expand Down
59 changes: 0 additions & 59 deletions bdk-swift/bdkFFI.xcframework/Info.plist

This file was deleted.

This file was deleted.

18 changes: 0 additions & 18 deletions bdk-swift/bdkFFI.xcframework/ios-arm64/bdkFFI.framework/Info.plist

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

41 changes: 0 additions & 41 deletions bdk-swift/build-local-swift.sh

This file was deleted.

61 changes: 61 additions & 0 deletions bdk-swift/build-xcframework.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#!/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.

HEADERPATH="Sources/BitcoinDevKit/bdkFFI.h"
MODMAPPATH="Sources/BitcoinDevKit/bdkFFI.modulemap"
TARGETDIR="../target"
OUTDIR="."
RELDIR="release-smaller"
NAME="bdkffi"
STATIC_LIB_NAME="lib${NAME}.a"
NEW_HEADER_DIR="../target/include"

# set required rust version and install component and targets
rustup default 1.77.1
rustup component add rust-src
rustup target add aarch64-apple-ios # iOS arm64
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

cd ../bdk-ffi/ || exit

# build bdk-ffi rust lib for apple targets
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
cargo build --package bdk-ffi --profile release-smaller --target aarch64-apple-ios-sim

# build bdk-ffi Swift bindings and put in bdk-swift Sources
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

# combine bdk-ffi static libs for aarch64 and x86_64 targets via lipo tool
mkdir -p ../target/lipo-ios-sim/release-smaller
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
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

cd ../bdk-swift/ || exit

# 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"
echo -e "\n" >> "${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"
14 changes: 14 additions & 0 deletions bdk-swift/justfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
default:
just --list

build:
bash ./build-xcframework.sh

clean:
rm -rf ../target bdkffi.xcframework Sources/BitcoinDevKit/*

test:
swift test

test-offline:
swift test --skip LiveElectrumClientTests --skip LiveMemoryWalletTests --skip LiveTransactionTests --skip LiveTxBuilderTests --skip LiveWalletTests

0 comments on commit 6c4d3a7

Please sign in to comment.