Skip to content

Commit

Permalink
Update publish-spm workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
notmandatory committed Nov 26, 2022
1 parent d2a2073 commit d760730
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 61 deletions.
56 changes: 28 additions & 28 deletions .github/workflows/publish-spm.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,20 @@ jobs:
name: Build, tag and create release
runs-on: macos-12
steps:
- name: Checkout release branch
uses: actions/checkout@v2
- name: Checkout build repo
uses: actions/checkout@v3
with:
submodules: true
repository: ${{ github.repository_owner }}/bdk-ffi
path: build
ref: v${{ inputs.version }}

- name: Cache
uses: actions/cache@v3
- name: Checkout dist repo
uses: actions/checkout@v3
with:
path: |
~/.cargo/registry
~/.cargo/git
./bdk-ffi/target
key: ${{ runner.os }}-${{ hashFiles('**/Cargo.toml','**/Cargo.lock') }}
path: dist

- name: Install Rust targets
working-directory: build
run: |
rustup install nightly-x86_64-apple-darwin
rustup component add rust-src --toolchain nightly-x86_64-apple-darwin
Expand All @@ -35,78 +34,79 @@ jobs:
rustup target add aarch64-apple-darwin x86_64-apple-darwin
- name: Run bdk-ffi-bindgen
working-directory: bdk-ffi
working-directory: build/bdk-ffi
run: |
cargo run --package bdk-ffi-bindgen -- --language swift --out-dir ../Sources/BitcoinDevKit
cargo run --package bdk-ffi-bindgen -- --language swift --out-dir ../bdk-swift/Sources/BitcoinDevKit
- name: Build bdk-ffi for x86_64-apple-darwin
working-directory: bdk-ffi
working-directory: build
run: |
cargo build --profile release-smaller --target x86_64-apple-darwin
- name: Build bdk-ffi for aarch64-apple-darwin
working-directory: bdk-ffi
working-directory: build
run: |
cargo build --profile release-smaller --target aarch64-apple-darwin
- name: Build bdk-ffi for x86_64-apple-ios
working-directory: bdk-ffi
working-directory: build
run: |
cargo build --profile release-smaller --target x86_64-apple-ios
- name: Build bdk-ffi for aarch64-apple-ios
working-directory: bdk-ffi
working-directory: build
run: |
cargo build --profile release-smaller --target aarch64-apple-ios
- name: Build bdk-ffi for aarch64-apple-ios-sim
working-directory: bdk-ffi
working-directory: build
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
working-directory: build
run: |
mkdir -p target/lipo-ios-sim/release-smaller
lipo target/aarch64-apple-ios-sim/release/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
- name: Create bdkFFI.xcframework
working-directory: build/bdk-swift
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-smaller/libbdkffi.a bdkFFI.xcframework/ios-arm64/bdkFFI.framework/bdkFFI
cp bdk-ffi/target/lipo-ios-sim/release-smaller/libbdkffi.a bdkFFI.xcframework/ios-arm64_x86_64-simulator/bdkFFI.framework/bdkFFI
cp bdk-ffi/target/lipo-macos/release-smaller/libbdkffi.a bdkFFI.xcframework/macos-arm64_x86_64/bdkFFI.framework/bdkFFI
cp ../target/aarch64-apple-ios/release-smaller/libbdkffi.a bdkFFI.xcframework/ios-arm64/bdkFFI.framework/bdkFFI
cp ../target/lipo-ios-sim/release-smaller/libbdkffi.a bdkFFI.xcframework/ios-arm64_x86_64-simulator/bdkFFI.framework/bdkFFI
cp ../target/lipo-macos/release-smaller/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
- name: Update and tag release dist repo
working-directory: build/bdk-swift
run: |
echo checksum = ${{ env.BDKFFICHECKSUM }}
echo url = ${{ env.BDKFFIURL }}
sed "s/BDKFFICHECKSUM/${BDKFFICHECKSUM}/;s/BDKFFIURL/${BDKFFIURL}/" Package.swift.txt > Package.swift
sed "s/BDKFFICHECKSUM/${BDKFFICHECKSUM}/;s/BDKFFIURL/${BDKFFIURL}/" Package.swift.txt > ../../dist/Package.swift
cp Sources/BitcoinDevKit/BitcoinDevKit.swift ../../dist/Sources/BitcoinDevKit/BitcoinDevKit.swift
cd ../../dist
git add Sources/BitcoinDevKit/BitcoinDevKit.swift
git add Package.swift
git commit -m "Update BitcoinDevKit.swift and 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
- name: Create release
uses: ncipollo/release-action@v1
with:
artifacts: "bdkFFI.xcframework.zip"
artifacts: "build/bdk-swift/bdkFFI.xcframework.zip"
tag: ${{ inputs.version }}
token: ${{ secrets.GITHUB_TOKEN }}
name: Release ${{ inputs.version }}
Expand Down
46 changes: 14 additions & 32 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,41 +1,23 @@
# bdk-swift

This project builds a Swift package that provides [Swift] language bindings for the
[`bdk`] library. The Swift language bindings are created by the [`bdk-ffi`] project which
is included as a git submodule of this repository.
This project is only used to publish a [Swift] package manager package called `bdk-swift` with language bindings and corresponding bdkFFI.xcframework for the
`BitcoinDevKit` framework created by the [bdk-ffi] project. The Swift language bindings files are created by the [bdk-ffi] `./bdk-ffi` sub-project which are copied into, committed and tagged in this `bdk-swift` repo by the `publish-spm` github actions workflow.

## How to Use

To use the Swift language bindings for [`bdk`] in your [Xcode] iOS or MacOS project add
the github repository (https://github.com/bitcoindevkit/bdk-swift) and select one of the
release versions. You may then import and use the `BitcoinDevKit` library in your Swift
code. For example:

```swift
import BitcoinDevKit

...
let desc = "wpkh([c258d2e4/84h/1h/0h]tpubDDYkZojQFQjht8Tm4jsS3iuEmKjTiEGjG6KnuFNKKJb5A6ZUCUZKdvLdSDWofKi4ToRCwb9poe1XdqfUnP4jaJjCB2Zwv11ZLgSbnZSNecE/0/*)"
let databaseConfig = DatabaseConfig.memory
let wallet = try Wallet.init(descriptor: desc, changeDescriptor: nil, network: Network.regtest, databaseConfig: databaseConfig)
let addressInfo = try wallet.getAddress(addressIndex: AddressIndex.new)
```
Any changes to the `bdk-swift` Swift package must be made via the [bdk-ffi] repo.

### Example Projects

* [BdkSwiftSample](https://github.com/futurepaul/BdkSwiftSample)

## How to Build and Publish
## How to Use

If you are a maintainer of this project or want to build and publish this project to your
own Github repository use the following steps:
To use the Swift language bindings for `BitcoinDevKit` in your [Xcode] iOS or MacOS project:

1. If it doesn't already exist, create a new `release/0.MINOR` branch from the `master` branch
2. Run the `publish-spm` workflow on Github for branch `release/0.MINOR` and version `0.MINOR.0`
3. Copy the changelog from corresponding `bdk-ffi` release description to this release
1. Add the "bdk-swift" package from the repo https://github.com/bitcoindevkit/bdk-swift and select one of the latest minor versions.
2. Add the `BitcoinDevKit` framework in your Target config.
3. Import and use the `BitcoinDevKit` library in your Swift code. For example:
```swift
import BitcoinDevKit

...
```

[Swift]: https://developer.apple.com/swift/
[Xcode]: https://developer.apple.com/documentation/Xcode
[`bdk`]: https://github.com/bitcoindevkit/bdk
[`bdk-ffi`]: https://github.com/bitcoindevkit/bdk-ffi
["Getting Started (Developer)"]: https://github.com/bitcoindevkit/bdk-ffi#getting-started-developer
[bdk-ffi]: https://github.com/notmandatory/bdk-ffi
1 change: 0 additions & 1 deletion bdk-ffi
Submodule bdk-ffi deleted from 064807

0 comments on commit d760730

Please sign in to comment.