Remove bindings and examples, update README.md
This commit is contained in:
parent
9188dec2f2
commit
55462fb426
105
README.md
105
README.md
@ -1,89 +1,34 @@
|
|||||||
# Foreign language bindings for BDK (bdk-ffi)
|
# Native language bindings for BDK
|
||||||
|
|
||||||
This repository contains source code for generating foreign language bindings
|
This repository contains source code for generating native language bindings for the rust based
|
||||||
for the rust library bdk for the Bitcoin Dev Kit (BDK) project.
|
[bdk] library which is the central artifact of the [Bitcoin Dev Kit] project.
|
||||||
|
|
||||||
|
Each supported language has it's own repository that includes this project as a [git submodule].
|
||||||
|
The rust code in this project is a wrapper around the [bdk] library to expose it's APIs in a
|
||||||
|
uniform way using the [mozilla/uniffi-rs] bindings generator for each supported target language.
|
||||||
|
|
||||||
## Supported target languages and platforms
|
## Supported target languages and platforms
|
||||||
|
|
||||||
| Language | Platform | Status |
|
The below repositories include instructions for using, building, and publishing the native
|
||||||
| --- | --- | --- |
|
language binding for [bdk] supported by this project.
|
||||||
| Kotlin | JVM | WIP |
|
|
||||||
| Kotlin | Android | WIP |
|
|
||||||
| Swift | iOS | WIP |
|
|
||||||
|
|
||||||
|
| Language | Platform | Repository |
|
||||||
|
| -------- | ------------ | ------------ |
|
||||||
|
| Kotlin | jvm | [bdk-kotlin] |
|
||||||
|
| Kotlin | android | [bdk-kotlin] |
|
||||||
|
| Swift | iOS, macOS | [bdk-swift] |
|
||||||
|
| Python | linux, macOS | [bdk-python] |
|
||||||
|
|
||||||
## Getting Started (User)
|
[bdk]: https://github.com/bitcoindevkit/bdk
|
||||||
|
[Bitcoin Dev Kit]: https://github.com/bitcoindevkit
|
||||||
|
[git submodule]: https://git-scm.com/book/en/v2/Git-Tools-Submodules
|
||||||
|
[uniffi-rs]: https://github.com/mozilla/uniffi-rs
|
||||||
|
|
||||||
If you just want to consume the language bindings:
|
[bdk-kotlin]: https://github.com/bitcoindevkit/bdk-kotlin
|
||||||
|
[bdk-swift]: https://github.com/bitcoindevkit/bdk-swift
|
||||||
|
[bdk-python]: https://github.com/thunderbiscuit/bdk-python
|
||||||
|
|
||||||
### Kotlin (JVM)
|
## Contributing
|
||||||
|
|
||||||
Just add the dependency `org.bitcoindevkit:bdk-jvm:0.1.1`. The package is `org.bitcoindevkit.bdk`.
|
|
||||||
|
|
||||||
### Kotlin (Android)
|
|
||||||
|
|
||||||
Just add the dependency `org.bitcoindevkit:bdk-android:0.1.1`. The package is `org.bitcoindevkit.bdk`.
|
|
||||||
|
|
||||||
## Getting Started (Developer)
|
|
||||||
|
|
||||||
This project uses rust. A basic knowledge of the rust ecosystem is helpful.
|
|
||||||
|
|
||||||
### General
|
|
||||||
1. Install `uniffi-bindgen`
|
|
||||||
```sh
|
|
||||||
cargo install uniffi_bindgen
|
|
||||||
```
|
|
||||||
1. See the [UniFFI User Guide](https://mozilla.github.io/uniffi-rs/) for more info
|
|
||||||
|
|
||||||
### Kotlin Bindings for JVM (OSX / Linux)
|
|
||||||
|
|
||||||
1. Install required targets
|
|
||||||
```sh
|
|
||||||
rustup target add x86_64-apple-darwin x86_64-unknown-linux-gnu
|
|
||||||
```
|
|
||||||
1. Build kotlin (JVM) bindings
|
|
||||||
```sh
|
|
||||||
./build.sh -k
|
|
||||||
```
|
|
||||||
1. Generated kotlin bindings are available at `/bindings/bdk-kotlin/`
|
|
||||||
1. A demo app is available at `/bindings/bdk-kotlin/demo/`. It uses stdin for
|
|
||||||
inputs and can be run from gradle.
|
|
||||||
```sh
|
|
||||||
cd bindings/bdk-kotlin
|
|
||||||
./gradlew :demo:run
|
|
||||||
```
|
|
||||||
|
|
||||||
### Kotlin bindings for Android
|
|
||||||
|
|
||||||
1. Install required targets
|
|
||||||
```sh
|
|
||||||
rustup target add x86_64-linux-android aarch64-linux-android
|
|
||||||
armv7-linux-androideabi i686-linux-android
|
|
||||||
```
|
|
||||||
1. Install Android SDK and Build-Tools for API level 30+
|
|
||||||
1. Setup `$ANDROID_NDK_HOME` and `$ANDROID_SDK_ROOT` path variables (which are
|
|
||||||
required by the build scripts)
|
|
||||||
1. Build kotlin (Android) bindings
|
|
||||||
```sh
|
|
||||||
./build.sh -a
|
|
||||||
```
|
|
||||||
2. A demo android app is available at [notmandatory/bdk-sample-app](https://github.com/notmandatory/bitcoindevkit-android-sample-app/tree/upgrade-to-bdk-ffi/)
|
|
||||||
|
|
||||||
### Swift bindings for iOS
|
|
||||||
|
|
||||||
1. Install the latest version of xcode, download and install the advanced tools.
|
|
||||||
1. Ensure Swift is installed
|
|
||||||
1. Install required targets
|
|
||||||
```sh
|
|
||||||
rustup target add aarch64-apple-ios x86_64-apple-ios
|
|
||||||
```
|
|
||||||
1. Build swift (iOS) bindings
|
|
||||||
```sh
|
|
||||||
./build.sh -s
|
|
||||||
```
|
|
||||||
1. Example iOS app can be found in `/examples/iOS` which can be run by xcode.
|
|
||||||
|
|
||||||
## Notes
|
|
||||||
|
|
||||||
### Adding new structs and functions
|
### Adding new structs and functions
|
||||||
|
|
||||||
@ -109,4 +54,6 @@ See the [UniFFI User Guide](https://mozilla.github.io/uniffi-rs/)
|
|||||||
|
|
||||||
## Thanks
|
## Thanks
|
||||||
|
|
||||||
This project is made possible thanks to the wonderful work on [mozilla/uniffi-rs](https://github.com/mozilla/uniffi-rs)
|
This project is made possible thanks to the wonderful work by the [mozilla/uniffi-rs] team.
|
||||||
|
|
||||||
|
[mozilla/uniffi-rs]: https://github.com/mozilla/uniffi-rs
|
||||||
|
107
build.sh
107
build.sh
@ -1,107 +0,0 @@
|
|||||||
#!/usr/bin/env bash
|
|
||||||
set -eo pipefail
|
|
||||||
|
|
||||||
# functions
|
|
||||||
|
|
||||||
## help
|
|
||||||
help()
|
|
||||||
{
|
|
||||||
# Display Help
|
|
||||||
echo "Build bdk-ffi and related libraries."
|
|
||||||
echo
|
|
||||||
echo "Syntax: build [-a|h|k|s]"
|
|
||||||
echo "options:"
|
|
||||||
echo "-a Android."
|
|
||||||
echo "-h Print this Help."
|
|
||||||
echo "-k Kotlin."
|
|
||||||
echo
|
|
||||||
}
|
|
||||||
|
|
||||||
## rust
|
|
||||||
build_rust() {
|
|
||||||
echo "Build Rust library"
|
|
||||||
cargo fmt
|
|
||||||
cargo build --release
|
|
||||||
cargo test
|
|
||||||
}
|
|
||||||
|
|
||||||
## copy to bdk-bdk-kotlin
|
|
||||||
copy_lib_kotlin() {
|
|
||||||
echo -n "Copy "
|
|
||||||
case $OS in
|
|
||||||
"Darwin")
|
|
||||||
echo -n "darwin "
|
|
||||||
mkdir -p bindings/bdk-kotlin/jvm/src/main/resources/darwin-x86-64
|
|
||||||
cp target/release/libbdkffi.dylib bindings/bdk-kotlin/jvm/src/main/resources/darwin-x86-64
|
|
||||||
;;
|
|
||||||
"Linux")
|
|
||||||
echo -n "linux "
|
|
||||||
mkdir -p bindings/bdk-kotlin/jvm/src/main/resources/linux-x86-64
|
|
||||||
cp target/release/libbdkffi.so bindings/bdk-kotlin/jvm/src/main/resources/linux-x86-64
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
echo "libs to kotlin sub-project"
|
|
||||||
}
|
|
||||||
|
|
||||||
## 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
|
|
||||||
}
|
|
||||||
|
|
||||||
## rust android
|
|
||||||
build_android() {
|
|
||||||
build_kotlin
|
|
||||||
|
|
||||||
# If ANDROID_NDK_HOME is not set then set it to github actions default
|
|
||||||
[ -z "$ANDROID_NDK_HOME" ] && export ANDROID_NDK_HOME=$ANDROID_HOME/ndk-bundle
|
|
||||||
|
|
||||||
# Update this line accordingly if you are not building *from* darwin-x86_64 or linux-x86_64
|
|
||||||
export PATH=$PATH:$ANDROID_NDK_HOME/toolchains/llvm/prebuilt/`uname | tr '[:upper:]' '[:lower:]'`-x86_64/bin
|
|
||||||
|
|
||||||
# Required for 'ring' dependency to cross-compile to Android platform, must be at least 21
|
|
||||||
export CFLAGS="-D__ANDROID_API__=21"
|
|
||||||
|
|
||||||
# IMPORTANT: make sure every target is not a substring of a different one. We check for them with grep later on
|
|
||||||
BUILD_TARGETS="${BUILD_TARGETS:-aarch64,x86_64,i686}"
|
|
||||||
|
|
||||||
mkdir -p bindings/bdk-kotlin/android/src/main/jniLibs/ bindings/bdk-kotlin/android/src/main/jniLibs/arm64-v8a bindings/bdk-kotlin/android/src/main/jniLibs/x86_64 bindings/bdk-kotlin/android/src/main/jniLibs/x86
|
|
||||||
|
|
||||||
if echo $BUILD_TARGETS | grep "aarch64"; then
|
|
||||||
CARGO_TARGET_AARCH64_LINUX_ANDROID_LINKER="aarch64-linux-android21-clang" CC="aarch64-linux-android21-clang" cargo build --release --target=aarch64-linux-android
|
|
||||||
cp target/aarch64-linux-android/release/libbdkffi.so bindings/bdk-kotlin/android/src/main/jniLibs/arm64-v8a
|
|
||||||
fi
|
|
||||||
if echo $BUILD_TARGETS | grep "x86_64"; then
|
|
||||||
CARGO_TARGET_X86_64_LINUX_ANDROID_LINKER="x86_64-linux-android21-clang" CC="x86_64-linux-android21-clang" cargo build --release --target=x86_64-linux-android
|
|
||||||
cp target/x86_64-linux-android/release/libbdkffi.so bindings/bdk-kotlin/android/src/main/jniLibs/x86_64
|
|
||||||
fi
|
|
||||||
if echo $BUILD_TARGETS | grep "i686"; then
|
|
||||||
CARGO_TARGET_I686_LINUX_ANDROID_LINKER="i686-linux-android21-clang" CC="i686-linux-android21-clang" cargo build --release --target=i686-linux-android
|
|
||||||
cp target/i686-linux-android/release/libbdkffi.so bindings/bdk-kotlin/android/src/main/jniLibs/x86
|
|
||||||
fi
|
|
||||||
|
|
||||||
# copy sources
|
|
||||||
cp -R bindings/bdk-kotlin/jvm/src/main/kotlin bindings/bdk-kotlin/android/src/main
|
|
||||||
|
|
||||||
# bdk-kotlin aar
|
|
||||||
(cd bindings/bdk-kotlin && ./gradlew :android:build)
|
|
||||||
}
|
|
||||||
|
|
||||||
OS=$(uname)
|
|
||||||
|
|
||||||
if [ "$1" == "-h" ]
|
|
||||||
then
|
|
||||||
help
|
|
||||||
else
|
|
||||||
build_rust
|
|
||||||
|
|
||||||
while [ -n "$1" ]; do # while loop starts
|
|
||||||
case "$1" in
|
|
||||||
-a) build_android ;;
|
|
||||||
-k) build_kotlin ;;
|
|
||||||
-h) help ;;
|
|
||||||
*) echo "Option $1 not recognized" ;;
|
|
||||||
esac
|
|
||||||
shift
|
|
||||||
done
|
|
||||||
fi
|
|
44
test.sh
44
test.sh
@ -1,44 +0,0 @@
|
|||||||
#!/usr/bin/env bash
|
|
||||||
set -eo pipefail
|
|
||||||
|
|
||||||
# functions
|
|
||||||
|
|
||||||
## help
|
|
||||||
help()
|
|
||||||
{
|
|
||||||
# Display Help
|
|
||||||
echo "Test bdk-uniffi and related libraries."
|
|
||||||
echo
|
|
||||||
echo "Syntax: build [-a|h|k]"
|
|
||||||
echo "options:"
|
|
||||||
echo "-a Android connected device tests."
|
|
||||||
echo "-h Print this Help."
|
|
||||||
echo "-k Kotlin tests."
|
|
||||||
echo
|
|
||||||
}
|
|
||||||
|
|
||||||
test_kotlin() {
|
|
||||||
(cd bindings/bdk-kotlin && ./gradlew :jvm:test -Djna.debug_load=true)
|
|
||||||
}
|
|
||||||
|
|
||||||
test_android() {
|
|
||||||
(cd bindings/bdk-kotlin && ./gradlew :android:connectedDebugAndroidTest)
|
|
||||||
}
|
|
||||||
|
|
||||||
if [ $1 = "-h" ]
|
|
||||||
then
|
|
||||||
help
|
|
||||||
else
|
|
||||||
cargo test
|
|
||||||
|
|
||||||
# optional tests
|
|
||||||
while [ -n "$1" ]; do # while loop starts
|
|
||||||
case "$1" in
|
|
||||||
-a) test_android ;;
|
|
||||||
-h) help ;;
|
|
||||||
-k) test_kotlin ;;
|
|
||||||
*) echo "Option $1 not recognized" ;;
|
|
||||||
esac
|
|
||||||
shift
|
|
||||||
done
|
|
||||||
fi
|
|
Loading…
x
Reference in New Issue
Block a user