Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use shell scripts to build bdk-jvm and bdk-android #584

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 2 additions & 6 deletions .github/workflows/live-tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,10 @@ jobs:
- name: "Set default Rust version to 1.77.1"
run: rustup default 1.77.1

- name: "Build bdk-jvm library"
run: |
cd bdk-jvm
./gradlew buildJvmLib

- name: "Run live JVM tests"
- name: "Build library and run tests"
run: |
cd bdk-jvm
bash ./scripts/build-linux-x86_64.sh
./gradlew test

swift-tests:
Expand Down
8 changes: 1 addition & 7 deletions .github/workflows/publish-android.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,10 @@ jobs:
distribution: temurin
java-version: 17

- name: "Set default Rust version to 1.77.1"
run: rustup default 1.77.1

- name: "Install Rust Android targets"
run: rustup target add x86_64-linux-android aarch64-linux-android armv7-linux-androideabi

- name: "Build bdk-android library"
run: |
cd bdk-android
./gradlew buildAndroidLib
bash ./scripts/build-linux-x86_64.sh

- name: "Publish to Maven Central"
env:
Expand Down
22 changes: 4 additions & 18 deletions .github/workflows/publish-jvm.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,11 @@ jobs:
distribution: temurin
java-version: 17

- name: "Set default Rust version to 1.77.1"
run: rustup default 1.77.1

- name: "Install aarch64 Rust target"
run: rustup target add aarch64-apple-darwin

- name: "Build bdk-jvm library"
run: |
cd bdk-jvm
./gradlew buildJvmLib
bash ./scripts/build-macos-aarch64.sh
bash ./scripts/build-macos-x86_64.sh

- name: "Upload macOS native libraries for reuse in publishing job"
uses: actions/upload-artifact@v3
Expand All @@ -54,16 +49,10 @@ jobs:
distribution: temurin
java-version: 17

- name: "Set default Rust version to 1.77.1"
run: rustup default 1.77.1

- name: "Install x86_64-pc-windows-msvc Rust target"
run: rustup target add x86_64-pc-windows-msvc

- name: "Build bdk-jvm library"
run: |
cd bdk-jvm
./gradlew buildJvmLib
bash ./scripts/build-windows-x86_64.sh

- name: "Upload Windows native libraries for reuse in publishing job"
uses: actions/upload-artifact@v3
Expand Down Expand Up @@ -94,13 +83,10 @@ jobs:
distribution: temurin
java-version: 17

- name: "Set default Rust version to 1.77.1"
run: rustup default 1.77.1

- name: "Build bdk-jvm library"
run: |
cd bdk-jvm
./gradlew buildJvmLib
bash ./scripts/build-linux-x86_64.sh

- name: "Download macOS native binaries from previous job"
uses: actions/download-artifact@v3
Expand Down
8 changes: 1 addition & 7 deletions .github/workflows/test-android.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,10 @@ jobs:
distribution: temurin
java-version: 17

- name: "Set default Rust version to 1.77.1"
run: rustup default 1.77.1

- name: "Install Rust Android targets"
run: rustup target add x86_64-linux-android aarch64-linux-android armv7-linux-androideabi

- name: "Build Android library"
run: |
cd bdk-android
./gradlew buildAndroidLib --console=plain
bash ./scripts/build-linux-x86_64.sh

# There are currently no unit tests for bdk-android (see the tests in bdk-jvm instead) and the
# integration tests require the macOS image which is not working with the older NDK version we
Expand Down
4 changes: 1 addition & 3 deletions .github/workflows/test-jvm.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,8 @@ jobs:
distribution: temurin
java-version: 17

- name: "Set default Rust version to 1.77.1"
run: rustup default 1.77.1

- name: "Run JVM tests"
run: |
cd bdk-jvm
bash ./scripts/build-linux-x86_64.sh
./gradlew test -P excludeConnectedTests
1 change: 0 additions & 1 deletion bdk-android/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ plugins {
id("org.jetbrains.kotlin.android").version("1.9.23").apply(false)
id("org.gradle.maven-publish")
id("org.gradle.signing")
id("org.bitcoindevkit.plugins.generate-android-bindings").apply(false)
id("io.github.gradle-nexus.publish-plugin").version("1.1.0").apply(true)
}

Expand Down
7 changes: 5 additions & 2 deletions bdk-android/justfile
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
default:
just --list

build:
./gradlew buildAndroidLib
build-linux:
bash ./scripts/build-linux-x86_64.sh

build-macos:
bash ./scripts/build-macos-aarch64.sh

clean:
rm -rf ../bdk-ffi/target/
Expand Down
18 changes: 0 additions & 18 deletions bdk-android/lib/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@ plugins {
id("org.jetbrains.kotlin.android")
id("org.gradle.maven-publish")
id("org.gradle.signing")

// Custom plugin to generate the native libs and bindings file
id("org.bitcoindevkit.plugins.generate-android-bindings")
}

android {
Expand All @@ -19,7 +16,6 @@ android {

defaultConfig {
minSdk = 24
targetSdk = 34
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles("consumer-rules.pro")
}
Expand Down Expand Up @@ -106,15 +102,6 @@ afterEvaluate {
}
}
}

// This is required because we must ensure the moveNativeAndroidLibs task is executed after
// the mergeReleaseJniLibFolders (hard requirement introduced by our upgrade to Gradle 8.7)
tasks.named("mergeReleaseJniLibFolders") {
dependsOn(":lib:moveNativeAndroidLibs")
}
tasks.named("mergeDebugJniLibFolders") {
dependsOn(":lib:moveNativeAndroidLibs")
}
}

signing {
Expand All @@ -128,8 +115,3 @@ signing {
useInMemoryPgpKeys(signingKeyId, signingKey, signingPassword)
sign(publishing.publications)
}

// This task dependency ensures that we build the bindings binaries before running the tests
tasks.withType<KotlinCompile> {
dependsOn("buildAndroidLib")
}
39 changes: 39 additions & 0 deletions bdk-android/scripts/build-linux-x86_64.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/bin/bash

if [ -z "$ANDROID_NDK_ROOT" ]; then
echo "Error: ANDROID_NDK_ROOT is not defined in your environment"
exit 1
fi

PATH="$ANDROID_NDK_ROOT/toolchains/llvm/prebuilt/linux-x86_64/bin:$PATH"
CFLAGS="-D__ANDROID_MIN_SDK_VERSION__=24"
AR="llvm-ar"
LIB_NAME="libbdkffi.so"
COMPILATION_TARGET_ARM64_V8A="aarch64-linux-android"
COMPILATION_TARGET_X86_64="x86_64-linux-android"
COMPILATION_TARGET_ARMEABI_V7A="armv7-linux-androideabi"
RESOURCE_DIR_ARM64_V8A="arm64-v8a"
RESOURCE_DIR_X86_64="x86_64"
RESOURCE_DIR_ARMEABI_V7A="armeabi-v7a"

# Move to the Rust library directory
cd ../bdk-ffi/ || exit
rustup default 1.77.1
rustup target add $COMPILATION_TARGET_ARM64_V8A $COMPILATION_TARGET_ARMEABI_V7A $COMPILATION_TARGET_X86_64

# Build the binaries
# The CC and CARGO_TARGET_<TARGET>_LINUX_ANDROID_LINKER environment variables must be declared on the same line as the cargo build command
CC="aarch64-linux-android24-clang" CARGO_TARGET_AARCH64_LINUX_ANDROID_LINKER="aarch64-linux-android24-clang" cargo build --profile release-smaller --target $COMPILATION_TARGET_ARM64_V8A
CC="x86_64-linux-android24-clang" CARGO_TARGET_X86_64_LINUX_ANDROID_LINKER="x86_64-linux-android24-clang" cargo build --profile release-smaller --target $COMPILATION_TARGET_X86_64
CC="armv7a-linux-androideabi24-clang" CARGO_TARGET_ARMV7_LINUX_ANDROIDEABI_LINKER="armv7a-linux-androideabi24-clang" cargo build --profile release-smaller --target $COMPILATION_TARGET_ARMEABI_V7A

# Copy the binaries to their respective resource directories
mkdir -p ../bdk-android/lib/src/main/jniLibs/$RESOURCE_DIR_ARM64_V8A/
mkdir -p ../bdk-android/lib/src/main/jniLibs/$RESOURCE_DIR_ARMEABI_V7A/
mkdir -p ../bdk-android/lib/src/main/jniLibs/$RESOURCE_DIR_X86_64/
cp ./target/$COMPILATION_TARGET_ARM64_V8A/release-smaller/$LIB_NAME ../bdk-android/lib/src/main/jniLibs/$RESOURCE_DIR_ARM64_V8A/
cp ./target/$COMPILATION_TARGET_ARMEABI_V7A/release-smaller/$LIB_NAME ../bdk-android/lib/src/main/jniLibs/$RESOURCE_DIR_ARMEABI_V7A/
cp ./target/$COMPILATION_TARGET_X86_64/release-smaller/$LIB_NAME ../bdk-android/lib/src/main/jniLibs/$RESOURCE_DIR_X86_64/

# Generate Kotlin bindings using uniffi-bindgen
cargo run --bin uniffi-bindgen generate --library ./target/$COMPILATION_TARGET_ARM64_V8A/release-smaller/$LIB_NAME --language kotlin --out-dir ../bdk-android/lib/src/main/kotlin/ --no-format
39 changes: 39 additions & 0 deletions bdk-android/scripts/build-macos-aarch64.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/bin/bash

if [ -z "$ANDROID_NDK_ROOT" ]; then
echo "Error: ANDROID_NDK_ROOT is not defined in your environment"
exit 1
fi

PATH="$ANDROID_NDK_ROOT/toolchains/llvm/prebuilt/darwin-x86_64/bin:$PATH"
CFLAGS="-D__ANDROID_MIN_SDK_VERSION__=24"
AR="llvm-ar"
LIB_NAME="libbdkffi.so"
COMPILATION_TARGET_ARM64_V8A="aarch64-linux-android"
COMPILATION_TARGET_X86_64="x86_64-linux-android"
COMPILATION_TARGET_ARMEABI_V7A="armv7-linux-androideabi"
RESOURCE_DIR_ARM64_V8A="arm64-v8a"
RESOURCE_DIR_X86_64="x86_64"
RESOURCE_DIR_ARMEABI_V7A="armeabi-v7a"

# Move to the Rust library directory
cd ../bdk-ffi/ || exit
rustup default 1.77.1
rustup target add $COMPILATION_TARGET_ARM64_V8A $COMPILATION_TARGET_ARMEABI_V7A $COMPILATION_TARGET_X86_64

# Build the binaries
# The CC and CARGO_TARGET_<TARGET>_LINUX_ANDROID_LINKER environment variables must be declared on the same line as the cargo build command
CC="aarch64-linux-android24-clang" CARGO_TARGET_AARCH64_LINUX_ANDROID_LINKER="aarch64-linux-android24-clang" cargo build --profile release-smaller --target $COMPILATION_TARGET_ARM64_V8A
CC="x86_64-linux-android24-clang" CARGO_TARGET_X86_64_LINUX_ANDROID_LINKER="x86_64-linux-android24-clang" cargo build --profile release-smaller --target $COMPILATION_TARGET_X86_64
CC="armv7a-linux-androideabi24-clang" CARGO_TARGET_ARMV7_LINUX_ANDROIDEABI_LINKER="armv7a-linux-androideabi24-clang" cargo build --profile release-smaller --target $COMPILATION_TARGET_ARMEABI_V7A

# Copy the binaries to their respective resource directories
mkdir -p ../bdk-android/lib/src/main/jniLibs/$RESOURCE_DIR_ARM64_V8A/
mkdir -p ../bdk-android/lib/src/main/jniLibs/$RESOURCE_DIR_ARMEABI_V7A/
mkdir -p ../bdk-android/lib/src/main/jniLibs/$RESOURCE_DIR_X86_64/
cp ./target/$COMPILATION_TARGET_ARM64_V8A/release-smaller/$LIB_NAME ../bdk-android/lib/src/main/jniLibs/$RESOURCE_DIR_ARM64_V8A/
cp ./target/$COMPILATION_TARGET_ARMEABI_V7A/release-smaller/$LIB_NAME ../bdk-android/lib/src/main/jniLibs/$RESOURCE_DIR_ARMEABI_V7A/
cp ./target/$COMPILATION_TARGET_X86_64/release-smaller/$LIB_NAME ../bdk-android/lib/src/main/jniLibs/$RESOURCE_DIR_X86_64/

# Generate Kotlin bindings using uniffi-bindgen
cargo run --bin uniffi-bindgen generate --library ./target/$COMPILATION_TARGET_ARM64_V8A/release-smaller/$LIB_NAME --language kotlin --out-dir ../bdk-android/lib/src/main/kotlin/ --no-format
1 change: 0 additions & 1 deletion bdk-android/settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
rootProject.name = "bdk-android"

include(":lib")
includeBuild("plugins")

pluginManagement {
repositories {
Expand Down
1 change: 0 additions & 1 deletion bdk-jvm/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ plugins {
id("org.gradle.java-library")
id("org.gradle.maven-publish")
id("org.gradle.signing")
id("org.bitcoindevkit.plugins.generate-jvm-bindings").apply(false)
id("io.github.gradle-nexus.publish-plugin") version "1.1.0"
}

Expand Down
14 changes: 11 additions & 3 deletions bdk-jvm/justfile
Original file line number Diff line number Diff line change
@@ -1,14 +1,22 @@
default:
just --list

build:
./gradlew buildJvmLib
build-linux:
bash ./scripts/build-linux-x86_64.sh

build-macos-aarch64:
bash ./scripts/build-macos-aarch64.sh

build-macos-x86_64:
bash ./scripts/build-macos-x86_64.sh

build-windows:
bash ./scripts/build-windows-x86_64.sh

clean:
rm -rf ../bdk-ffi/target/
rm -rf ./build/
rm -rf ./lib/build/
rm -rf ./plugins/build/

publish-local:
./gradlew publishToMavenLocal -P localBuild
Expand Down
19 changes: 6 additions & 13 deletions bdk-jvm/lib/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@ plugins {
id("org.gradle.java-library")
id("org.gradle.maven-publish")
id("org.gradle.signing")

// Custom plugin to generate the native libs and bindings file
id("org.bitcoindevkit.plugins.generate-jvm-bindings")
}

java {
Expand All @@ -22,6 +19,12 @@ java {
withJavadocJar()
}

tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile> {
kotlinOptions {
jvmTarget = "11"
}
}

// This block ensures that the tests that require access to a blockchain are not
// run if the -P excludeConnectedTests flag is passed to gradle.
// This ensures our CI runs are not fickle by not requiring access to testnet or signet.
Expand Down Expand Up @@ -120,13 +123,3 @@ signing {
useInMemoryPgpKeys(signingKeyId, signingKey, signingPassword)
sign(publishing.publications)
}

// This task dependency ensures that we build the bindings
// binaries before running the tests
tasks.withType<KotlinCompile> {
dependsOn("buildJvmLib")

kotlinOptions {
jvmTarget = "11"
}
}
16 changes: 0 additions & 16 deletions bdk-jvm/plugins/README.md

This file was deleted.

13 changes: 0 additions & 13 deletions bdk-jvm/plugins/build.gradle.kts

This file was deleted.

8 changes: 0 additions & 8 deletions bdk-jvm/plugins/settings.gradle.kts

This file was deleted.

16 changes: 0 additions & 16 deletions bdk-jvm/plugins/src/main/kotlin/org/bitcoindevkit/plugins/Enums.kt

This file was deleted.

Loading
Loading