diff --git a/.github/workflows/publish-spm.yaml b/.github/workflows/publish-spm.yaml new file mode 100644 index 0000000..f135871 --- /dev/null +++ b/.github/workflows/publish-spm.yaml @@ -0,0 +1,117 @@ +name: Build, tag and create release +on: + workflow_dispatch: + inputs: + branch: + description: 'Release branch, eg. release/0.MINOR' + required: true + type: string + version: + description: 'New release version, eg. 0.MINOR.PATCH' + required: true + type: string + +jobs: + build-publish: + name: Build, tag and create release + runs-on: macos-12 + steps: + - name: Checkout release branch + uses: actions/checkout@v2 + with: + ref: ${{ inputs.branch }} + submodules: true + + - name: Cache + uses: actions/cache@v3 + with: + path: | + ~/.cargo/registry + ~/.cargo/git + ./bdk-ffi/target + key: ${{ runner.os }}-${{ hashFiles('**/Cargo.toml','**/Cargo.lock') }} + + - name: Install Rust targets + run: | + rustup install nightly-x86_64-apple-darwin + rustup component add rust-src --toolchain nightly-x86_64-apple-darwin + rustup target add aarch64-apple-ios x86_64-apple-ios + rustup target add aarch64-apple-ios-sim --toolchain nightly + rustup target add aarch64-apple-darwin x86_64-apple-darwin + + - name: Run bdk-ffi-bindgen + working-directory: bdk-ffi + run: | + cargo run --package bdk-ffi-bindgen -- --language swift --out-dir ../Sources/BitcoinDevKit + + - name: Build bdk-ffi for x86_64-apple-darwin + working-directory: bdk-ffi + run: | + cargo build --release --target x86_64-apple-darwin + + - name: Build bdk-ffi for aarch64-apple-darwin + working-directory: bdk-ffi + run: | + cargo build --release --target aarch64-apple-darwin + + - name: Build bdk-ffi for x86_64-apple-ios + working-directory: bdk-ffi + run: | + cargo build --release --target x86_64-apple-ios + + - name: Build bdk-ffi for aarch64-apple-ios + working-directory: bdk-ffi + run: | + cargo build --release --target aarch64-apple-ios + + - name: Build bdk-ffi for aarch64-apple-ios-sim + working-directory: bdk-ffi + run: | + cargo +nightly build --release -Z build-std --target aarch64-apple-ios-sim + + - name: Create lipo-ios-sim and lipo-macos + working-directory: bdk-ffi + run: | + mkdir -p target/lipo-ios-sim/release + lipo target/aarch64-apple-ios-sim/release/libbdkffi.a target/x86_64-apple-ios/release/libbdkffi.a -create -output target/lipo-ios-sim/release/libbdkffi.a + mkdir -p target/lipo-macos/release + lipo target/aarch64-apple-darwin/release/libbdkffi.a target/x86_64-apple-darwin/release/libbdkffi.a -create -output target/lipo-macos/release/libbdkffi.a + + - name: Create bdkFFI.xcframework + run: | + mv Sources/BitcoinDevKit/bdk.swift Sources/BitcoinDevKit/BitcoinDevKit.swift + cp Sources/BitcoinDevKit/bdkFFI.h bdkFFI.xcframework/ios-arm64/bdkFFI.framework/Headers + cp Sources/BitcoinDevKit/bdkFFI.h bdkFFI.xcframework/ios-arm64_x86_64-simulator/bdkFFI.framework/Headers + cp Sources/BitcoinDevKit/bdkFFI.h bdkFFI.xcframework/macos-arm64_x86_64/bdkFFI.framework/Headers + cp bdk-ffi/target/aarch64-apple-ios/release/libbdkffi.a bdkFFI.xcframework/ios-arm64/bdkFFI.framework/bdkFFI + cp bdk-ffi/target/lipo-ios-sim/release/libbdkffi.a bdkFFI.xcframework/ios-arm64_x86_64-simulator/bdkFFI.framework/bdkFFI + cp bdk-ffi/target/lipo-macos/release/libbdkffi.a bdkFFI.xcframework/macos-arm64_x86_64/bdkFFI.framework/bdkFFI + rm Sources/BitcoinDevKit/bdkFFI.h + rm Sources/BitcoinDevkit/bdkFFI.modulemap + rm bdkFFI.xcframework.zip || true + zip -9 -r bdkFFI.xcframework.zip bdkFFI.xcframework + echo "BDKFFICHECKSUM=`swift package compute-checksum bdkFFI.xcframework.zip`" >> $GITHUB_ENV + echo "BDKFFIURL=https\:\/\/github\.com\/${{ github.repository_owner }}\/bdk\-swift\/releases\/download\/${{ inputs.version }}\/bdkFFI\.xcframework\.zip" >> $GITHUB_ENV + + - name: Update, commit, and push new Package.swift + run: | + echo checksum = ${{ env.BDKFFICHECKSUM }} + echo url = ${{ env.BDKFFIURL }} + sed "s/BDKFFICHECKSUM/${BDKFFICHECKSUM}/;s/BDKFFIURL/${BDKFFIURL}/" Package.swift.txt > Package.swift + git add Package.swift + git commit -m "Update Package.swift for release ${{ inputs.version }}" + git push + + - name: Tag new release + run: | + git tag ${{ inputs.version }} -m "Release ${{ inputs.version }}" + git push --tags + + - name: Publish release + uses: ncipollo/release-action@v1 + with: + artifacts: "bdkFFI.xcframework.zip" + tag: ${{ inputs.version }} + token: ${{ secrets.GITHUB_TOKEN }} + name: Release ${{ inputs.version }} + prerelease: true diff --git a/Package.swift.txt b/Package.swift.txt new file mode 100644 index 0000000..ec401f2 --- /dev/null +++ b/Package.swift.txt @@ -0,0 +1,36 @@ +// swift-tools-version:5.5 +// The swift-tools-version declares the minimum version of Swift required to build this package. + +import PackageDescription + +let package = Package( + name: "bdk-swift", + platforms: [ + .macOS(.v12), + .iOS(.v15) + ], + products: [ + // Products define the executables and libraries a package produces, and make them visible to other packages. + .library( + name: "BitcoinDevKit", + targets: ["bdkFFI", "BitcoinDevKit"]), + ], + dependencies: [ + // Dependencies declare other packages that this package depends on. + // .package(url: /* package url */, from: "1.0.0"), + ], + targets: [ + // Targets are the basic building blocks of a package. A target can define a module or a test suite. + // Targets can depend on other targets in this package, and on products in packages this package depends on. + .binaryTarget( + name: "bdkFFI", + url: "BDKFFIURL", + checksum: "BDKFFICHECKSUM"), + .target( + name: "BitcoinDevKit", + dependencies: ["bdkFFI"]), + .testTarget( + name: "BitcoinDevKitTests", + dependencies: ["BitcoinDevKit"]), + ] +) diff --git a/build.sh b/build.sh deleted file mode 100755 index f18881d..0000000 --- a/build.sh +++ /dev/null @@ -1,76 +0,0 @@ -#!/usr/bin/env bash -set -euo pipefail - -## confirm bdk-ffi rust lib builds -pushd bdk-ffi -echo "Confirm bdk-ffi rust lib builds" -cargo build --release - -echo "Generate bdk-ffi swift bindings" -cargo run --package bdk-ffi-bindgen -- --language swift --out-dir ../Sources/BitcoinDevKit - -## build bdk-ffi rust libs for apple targets and add to xcframework -echo "Build bdk-ffi libs for apple targets and add to xcframework" - -TARGET_TRIPLES=("x86_64-apple-darwin" "aarch64-apple-darwin" "x86_64-apple-ios" "aarch64-apple-ios") -#XCFRAMEWORK_LIBS="" -for TARGET in ${TARGET_TRIPLES[@]}; do - echo "Build bdk-ffi lib for target $TARGET" - cargo build --release --target $TARGET - #XCFRAMEWORK_LIBS="$XCFRAMEWORK_LIBS -library target/$TARGET/release/libbdkffi.a" -done -# special build for M1 ios simulator -cargo +nightly build --release -Z build-std --target aarch64-apple-ios-sim - -echo "Create lipo static libs for ios-sim to support M1" -mkdir -p target/lipo-ios-sim/release -lipo target/aarch64-apple-ios-sim/release/libbdkffi.a target/x86_64-apple-ios/release/libbdkffi.a -create -output target/lipo-ios-sim/release/libbdkffi.a - -echo "Create lipo static libs for macos to support M1" -mkdir -p target/lipo-macos/release -lipo target/aarch64-apple-darwin/release/libbdkffi.a target/x86_64-apple-darwin/release/libbdkffi.a -create -output target/lipo-macos/release/libbdkffi.a - -#echo "Create xcframework with xcodebuild" -#xcodebuild -create-xcframework \ -# -library target/lipo-ios-sim/release/libbdkffi.a \ -# -library target/lipo-macos/release/libbdkffi.a \ -# -library target/aarch64-apple-ios/release/libbdkffi.a \ -# -output ../bdkFFI.xcframework - -popd - -# rename bdk.swift bindings to BitcoinDevKit.swift -mv Sources/BitcoinDevKit/bdk.swift Sources/BitcoinDevKit/BitcoinDevKit.swift - -XCFRAMEWORK_LIBS=("ios-arm64" "ios-arm64_x86_64-simulator" "macos-arm64_x86_64") -for LIB in ${XCFRAMEWORK_LIBS[@]}; do - # copy possibly updated header file - cp Sources/BitcoinDevKit/bdkFFI.h bdkFFI.xcframework/$LIB/bdkFFI.framework/Headers -done - -echo "Copy libbdkffi.a files to bdkFFI.xcframework/bdkFFI" -cp bdk-ffi/target/aarch64-apple-ios/release/libbdkffi.a bdkFFI.xcframework/ios-arm64/bdkFFI.framework/bdkFFI -cp bdk-ffi/target/lipo-ios-sim/release/libbdkffi.a bdkFFI.xcframework/ios-arm64_x86_64-simulator/bdkFFI.framework/bdkFFI -cp bdk-ffi/target/lipo-macos/release/libbdkffi.a bdkFFI.xcframework/macos-arm64_x86_64/bdkFFI.framework/bdkFFI - -# remove unneed .h and .modulemap files -rm Sources/BitcoinDevKit/bdkFFI.h -rm Sources/BitcoinDevkit/bdkFFI.modulemap - -# TODO add license info - -if test -f "bdkFFI.xcframework.zip"; then - echo "Remove old bdkFFI.xcframework.zip" - rm bdkFFI.xcframework.zip -fi - - -# zip bdkFFI.xcframework directory into a bundle for distribution -zip -9 -r bdkFFI.xcframework.zip bdkFFI.xcframework - -# compute bdkFFI.xcframework.zip checksum -echo checksum: -swift package compute-checksum bdkFFI.xcframework.zip - -# TODO update Package.swift with checksum -# TODO upload zip to github release