diff --git a/.github/workflows/live-tests.yaml b/.github/workflows/live-tests.yaml index 9d34e234..359c888d 100644 --- a/.github/workflows/live-tests.yaml +++ b/.github/workflows/live-tests.yaml @@ -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: diff --git a/.github/workflows/publish-android.yaml b/.github/workflows/publish-android.yaml index 2d7ba16d..c4467883 100644 --- a/.github/workflows/publish-android.yaml +++ b/.github/workflows/publish-android.yaml @@ -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: diff --git a/.github/workflows/publish-jvm.yaml b/.github/workflows/publish-jvm.yaml index afbdbc6a..1e01a697 100644 --- a/.github/workflows/publish-jvm.yaml +++ b/.github/workflows/publish-jvm.yaml @@ -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 @@ -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 @@ -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 diff --git a/.github/workflows/test-android.yaml b/.github/workflows/test-android.yaml index 9101a9da..2403c8de 100644 --- a/.github/workflows/test-android.yaml +++ b/.github/workflows/test-android.yaml @@ -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 diff --git a/.github/workflows/test-jvm.yaml b/.github/workflows/test-jvm.yaml index bf6f8830..62a92192 100644 --- a/.github/workflows/test-jvm.yaml +++ b/.github/workflows/test-jvm.yaml @@ -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 diff --git a/bdk-android/build.gradle.kts b/bdk-android/build.gradle.kts index f2b1b52f..00c0beaa 100644 --- a/bdk-android/build.gradle.kts +++ b/bdk-android/build.gradle.kts @@ -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) } diff --git a/bdk-android/justfile b/bdk-android/justfile index b5522ff0..489fa2e5 100644 --- a/bdk-android/justfile +++ b/bdk-android/justfile @@ -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/ diff --git a/bdk-android/lib/build.gradle.kts b/bdk-android/lib/build.gradle.kts index 96d960ae..4e240092 100644 --- a/bdk-android/lib/build.gradle.kts +++ b/bdk-android/lib/build.gradle.kts @@ -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 { @@ -19,7 +16,6 @@ android { defaultConfig { minSdk = 24 - targetSdk = 34 testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" consumerProguardFiles("consumer-rules.pro") } @@ -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 { @@ -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 { - dependsOn("buildAndroidLib") -} diff --git a/bdk-android/scripts/build-linux-x86_64.sh b/bdk-android/scripts/build-linux-x86_64.sh new file mode 100644 index 00000000..d524e026 --- /dev/null +++ b/bdk-android/scripts/build-linux-x86_64.sh @@ -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__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 diff --git a/bdk-android/scripts/build-macos-aarch64.sh b/bdk-android/scripts/build-macos-aarch64.sh new file mode 100644 index 00000000..516bda6b --- /dev/null +++ b/bdk-android/scripts/build-macos-aarch64.sh @@ -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__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 diff --git a/bdk-android/settings.gradle.kts b/bdk-android/settings.gradle.kts index cf43879b..3ddd6f3d 100644 --- a/bdk-android/settings.gradle.kts +++ b/bdk-android/settings.gradle.kts @@ -1,7 +1,6 @@ rootProject.name = "bdk-android" include(":lib") -includeBuild("plugins") pluginManagement { repositories { diff --git a/bdk-jvm/build.gradle.kts b/bdk-jvm/build.gradle.kts index 32cfd4f7..1a352b3e 100644 --- a/bdk-jvm/build.gradle.kts +++ b/bdk-jvm/build.gradle.kts @@ -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" } diff --git a/bdk-jvm/justfile b/bdk-jvm/justfile index 0e350898..7228ecb8 100644 --- a/bdk-jvm/justfile +++ b/bdk-jvm/justfile @@ -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 diff --git a/bdk-jvm/lib/build.gradle.kts b/bdk-jvm/lib/build.gradle.kts index 8c226d79..d314c8d0 100644 --- a/bdk-jvm/lib/build.gradle.kts +++ b/bdk-jvm/lib/build.gradle.kts @@ -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 { @@ -22,6 +19,12 @@ java { withJavadocJar() } +tasks.withType { + 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. @@ -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 { - dependsOn("buildJvmLib") - - kotlinOptions { - jvmTarget = "11" - } -} diff --git a/bdk-jvm/plugins/README.md b/bdk-jvm/plugins/README.md deleted file mode 100644 index b80e5d2f..00000000 --- a/bdk-jvm/plugins/README.md +++ /dev/null @@ -1,16 +0,0 @@ -# Readme -The purpose of this directory is to host the Gradle plugin that adds tasks for building the native binaries required by bdk-jvm, and building the language bindings files. - -The plugin is applied to the `build.gradle.kts` file through the `plugins` block: -```kotlin -plugins { - id("org.bitcoindevkit.plugin.generate-jvm-bindings") -} -``` - -The plugin adds a series of tasks which are brought together into an aggregate task called `buildJvmLib` for `bdk-jvm`. - -This aggregate task: -1. Builds the native library(ies) using `bdk-ffi` -2. Places it in the correct resource directory -3. Builds the bindings file diff --git a/bdk-jvm/plugins/build.gradle.kts b/bdk-jvm/plugins/build.gradle.kts deleted file mode 100644 index 91dfb288..00000000 --- a/bdk-jvm/plugins/build.gradle.kts +++ /dev/null @@ -1,13 +0,0 @@ -plugins { - id("java-gradle-plugin") - `kotlin-dsl` -} - -gradlePlugin { - plugins { - create("uniFfiJvmBindings") { - id = "org.bitcoindevkit.plugins.generate-jvm-bindings" - implementationClass = "org.bitcoindevkit.plugins.UniFfiJvmPlugin" - } - } -} diff --git a/bdk-jvm/plugins/settings.gradle.kts b/bdk-jvm/plugins/settings.gradle.kts deleted file mode 100644 index ca62a7a7..00000000 --- a/bdk-jvm/plugins/settings.gradle.kts +++ /dev/null @@ -1,8 +0,0 @@ -dependencyResolutionManagement { - repositories { - mavenCentral() - google() - } -} - -// include(":plugins") diff --git a/bdk-jvm/plugins/src/main/kotlin/org/bitcoindevkit/plugins/Enums.kt b/bdk-jvm/plugins/src/main/kotlin/org/bitcoindevkit/plugins/Enums.kt deleted file mode 100644 index 85c089b0..00000000 --- a/bdk-jvm/plugins/src/main/kotlin/org/bitcoindevkit/plugins/Enums.kt +++ /dev/null @@ -1,16 +0,0 @@ -package org.bitcoindevkit.plugins - - -val operatingSystem: OS = when { - System.getProperty("os.name").contains("mac", ignoreCase = true) -> OS.MAC - System.getProperty("os.name").contains("linux", ignoreCase = true) -> OS.LINUX - System.getProperty("os.name").contains("windows", ignoreCase = true) -> OS.WINDOWS - else -> OS.OTHER -} - -enum class OS { - MAC, - LINUX, - WINDOWS, - OTHER, -} diff --git a/bdk-jvm/plugins/src/main/kotlin/org/bitcoindevkit/plugins/UniFfiJvmPlugin.kt b/bdk-jvm/plugins/src/main/kotlin/org/bitcoindevkit/plugins/UniFfiJvmPlugin.kt deleted file mode 100644 index 415ccc19..00000000 --- a/bdk-jvm/plugins/src/main/kotlin/org/bitcoindevkit/plugins/UniFfiJvmPlugin.kt +++ /dev/null @@ -1,150 +0,0 @@ -package org.bitcoindevkit.plugins - -import org.gradle.api.DefaultTask -import org.gradle.api.Plugin -import org.gradle.api.Project -import org.gradle.api.tasks.Exec -import org.gradle.kotlin.dsl.getValue -import org.gradle.kotlin.dsl.provideDelegate -import org.gradle.kotlin.dsl.register - -// TODO 18: Migrate hard coded strings to constants all in the same location so they're at least easy -// to find and reason about. -internal class UniFfiJvmPlugin : Plugin { - override fun apply(target: Project): Unit = target.run { - - // register a task called buildJvmBinaries which will run something like - // cargo build --release --target aarch64-apple-darwin - val buildJvmBinaries by tasks.register("buildJvmBinaries") { - if (operatingSystem == OS.MAC) { - exec { - workingDir("${project.projectDir}/../../bdk-ffi") - executable("cargo") - val cargoArgs: List = listOf("build", "--profile", "release-smaller", "--target", "x86_64-apple-darwin") - args(cargoArgs) - } - exec { - workingDir("${project.projectDir}/../../bdk-ffi") - executable("cargo") - val cargoArgs: List = listOf("build", "--profile", "release-smaller", "--target", "aarch64-apple-darwin") - args(cargoArgs) - } - } else if (operatingSystem == OS.LINUX) { - exec { - workingDir("${project.projectDir}/../../bdk-ffi") - executable("cargo") - val cargoArgs: List = listOf("build", "--profile", "release-smaller", "--target", "x86_64-unknown-linux-gnu") - args(cargoArgs) - } - } else if (operatingSystem == OS.WINDOWS) { - exec { - workingDir("${project.projectDir}/../../bdk-ffi") - executable("cargo") - val cargoArgs: List = listOf("build", "--profile", "release-smaller", "--target", "x86_64-pc-windows-msvc") - args(cargoArgs) - } - } - } - - // move the native libs build by cargo from target/.../release/ - // to their place in the bdk-jvm library - val moveNativeJvmLibs by tasks.register("moveNativeJvmLibs") { - - // dependsOn(buildJvmBinaryX86_64MacOS, buildJvmBinaryAarch64MacOS, buildJvmBinaryLinux) - dependsOn(buildJvmBinaries) - - data class CopyMetadata(val targetDir: String, val resDir: String, val ext: String) - val libsToCopy: MutableList = mutableListOf() - - if (operatingSystem == OS.MAC) { - libsToCopy.add( - CopyMetadata( - targetDir = "aarch64-apple-darwin", - resDir = "darwin-aarch64", - ext = "dylib" - ) - ) - libsToCopy.add( - CopyMetadata( - targetDir = "x86_64-apple-darwin", - resDir = "darwin-x86-64", - ext = "dylib" - ) - ) - } else if (operatingSystem == OS.LINUX) { - libsToCopy.add( - CopyMetadata( - targetDir = "x86_64-unknown-linux-gnu", - resDir = "linux-x86-64", - ext = "so" - ) - ) - } else if (operatingSystem == OS.WINDOWS) { - libsToCopy.add( - CopyMetadata( - targetDir = "x86_64-pc-windows-msvc", - resDir = "win32-x86-64", - ext = "dll" - ) - ) - } - val libName = when (operatingSystem) { - OS.WINDOWS -> "bdkffi" - else -> "libbdkffi" - } - - libsToCopy.forEach { - doFirst { - copy { - with(it) { - from("${project.projectDir}/../../bdk-ffi/target/${this.targetDir}/release-smaller/${libName}.${this.ext}") - into("${project.projectDir}/../../bdk-jvm/lib/src/main/resources/${this.resDir}/") - } - } - } - } - } - - // generate the bindings using the bdk-ffi-bindgen tool created in the bdk-ffi submodule - val generateJvmBindings by tasks.register("generateJvmBindings") { - - dependsOn(moveNativeJvmLibs) - - // TODO 2: Is the Windows name the correct one? - // TODO 3: This will not work on mac Intel (x86_64 architecture) - val libraryPath = when (operatingSystem) { - OS.LINUX -> "./target/x86_64-unknown-linux-gnu/release-smaller/libbdkffi.so" - OS.MAC -> "./target/aarch64-apple-darwin/release-smaller/libbdkffi.dylib" - OS.WINDOWS -> "./target/x86_64-pc-windows-msvc/release-smaller/bdkffi.dll" - else -> throw Exception("Unsupported OS") - } - - workingDir("${project.projectDir}/../../bdk-ffi/") - val cargoArgs: List = listOf("run", "--bin", "uniffi-bindgen", "generate", "--library", libraryPath, "--language", "kotlin", "--out-dir", "../bdk-jvm/lib/src/main/kotlin/", "--no-format") - - // The code above was for the migration to uniffi 0.24.3 using the --library flag - // The code below works with uniffi 0.23.0 - // workingDir("${project.projectDir}/../../bdk-ffi/") - // val cargoArgs: List = listOf("run", "--bin", "uniffi-bindgen", "generate", "src/bdk.udl", "--language", "kotlin", "--out-dir", "../bdk-jvm/lib/src/main/kotlin", "--no-format") - executable("cargo") - args(cargoArgs) - - doLast { - println("JVM bindings file successfully created") - } - } - - // we need an aggregate task which will run the 3 required tasks to build the JVM libs in order - // the task will also appear in the printout of the ./gradlew tasks task with a group and description - tasks.register("buildJvmLib") { - group = "Bitcoindevkit" - description = "Aggregate task to build JVM library" - - dependsOn( - buildJvmBinaries, - moveNativeJvmLibs, - generateJvmBindings - ) - } - } -} diff --git a/bdk-jvm/scripts/build-linux-x86_64.sh b/bdk-jvm/scripts/build-linux-x86_64.sh new file mode 100644 index 00000000..badde727 --- /dev/null +++ b/bdk-jvm/scripts/build-linux-x86_64.sh @@ -0,0 +1,21 @@ +#!/bin/bash + +COMPILATION_TARGET="x86_64-unknown-linux-gnu" +TARGET_DIR="target/x86_64-unknown-linux-gnu/release-smaller" +RESOURCE_DIR="resources/linux-x86-64" +LIB_NAME="libbdkffi.so" + +# Move to the Rust library directory +cd ../bdk-ffi/ || exit + +# Build the Rust library +rustup default 1.77.1 +rustup target add $COMPILATION_TARGET +cargo build --profile release-smaller --target $COMPILATION_TARGET + +# Generate Kotlin bindings using uniffi-bindgen +cargo run --bin uniffi-bindgen generate --library ./$TARGET_DIR/$LIB_NAME --language kotlin --out-dir ../bdk-jvm/lib/src/main/kotlin/ --no-format + +# Copy the binary to the resources directory +mkdir -p ../bdk-jvm/lib/src/main/$RESOURCE_DIR/ +cp ./$TARGET_DIR/$LIB_NAME ../bdk-jvm/lib/src/main/$RESOURCE_DIR/ diff --git a/bdk-jvm/scripts/build-macos-aarch64.sh b/bdk-jvm/scripts/build-macos-aarch64.sh index 2ee9a4b3..1e6b9548 100644 --- a/bdk-jvm/scripts/build-macos-aarch64.sh +++ b/bdk-jvm/scripts/build-macos-aarch64.sh @@ -1,13 +1,21 @@ #!/bin/bash +COMPILATION_TARGET="aarch64-apple-darwin" +TARGET_DIR="target/$COMPILATION_TARGET/release-smaller" +RESOURCE_DIR="resources/darwin-aarch64" +LIB_NAME="libbdkffi.dylib" + # Move to the Rust library directory -cd ../bdk-ffi/ +cd ../bdk-ffi/ || exit # Build the Rust library -cargo build --profile release-smaller --target aarch64-apple-darwin +rustup default 1.77.1 +rustup target add $COMPILATION_TARGET +cargo build --profile release-smaller --target $COMPILATION_TARGET # Generate Kotlin bindings using uniffi-bindgen -cargo run --bin uniffi-bindgen generate --library ./target/aarch64-apple-darwin/release-smaller/libbdkffi.dylib --language kotlin --out-dir ../bdk-jvm/lib/src/main/kotlin/ --no-format +cargo run --bin uniffi-bindgen generate --library ./$TARGET_DIR/$LIB_NAME --language kotlin --out-dir ../bdk-jvm/lib/src/main/kotlin/ --no-format -# Copy the binary to the Android resources directory -cp ./target/aarch64-apple-darwin/release-smaller/libbdkffi.dylib ../bdk-jvm/lib/src/main/resources/darwin-aarch64/libbdkffi.dylib +# Copy the binary to the resources directory +mkdir -p ../bdk-jvm/lib/src/main/$RESOURCE_DIR/ +cp ./$TARGET_DIR/$LIB_NAME ../bdk-jvm/lib/src/main/$RESOURCE_DIR/ diff --git a/bdk-jvm/scripts/build-macos-x86_64.sh b/bdk-jvm/scripts/build-macos-x86_64.sh new file mode 100644 index 00000000..b81097ef --- /dev/null +++ b/bdk-jvm/scripts/build-macos-x86_64.sh @@ -0,0 +1,21 @@ +#!/bin/bash + +COMPILATION_TARGET="x86_64-apple-darwin" +TARGET_DIR="target/x86_64-apple-darwin/release-smaller" +RESOURCE_DIR="resources/darwin-x86-64" +LIB_NAME="libbdkffi.dylib" + +# Move to the Rust library directory +cd ../bdk-ffi/ || exit + +# Build the Rust library +rustup default 1.77.1 +rustup target add $COMPILATION_TARGET +cargo build --profile release-smaller --target $COMPILATION_TARGET + +# Generate Kotlin bindings using uniffi-bindgen +cargo run --bin uniffi-bindgen generate --library ./$TARGET_DIR/$LIB_NAME --language kotlin --out-dir ../bdk-jvm/lib/src/main/kotlin/ --no-format + +# Copy the binary to the resources directory +mkdir -p ../bdk-jvm/lib/src/main/$RESOURCE_DIR/ +cp ./$TARGET_DIR/$LIB_NAME ../bdk-jvm/lib/src/main/$RESOURCE_DIR/ diff --git a/bdk-jvm/scripts/build-windows-x86_64.sh b/bdk-jvm/scripts/build-windows-x86_64.sh new file mode 100644 index 00000000..a0409b56 --- /dev/null +++ b/bdk-jvm/scripts/build-windows-x86_64.sh @@ -0,0 +1,21 @@ +#!/bin/bash + +COMPILATION_TARGET="x86_64-pc-windows-msvc" +TARGET_DIR="target/x86_64-pc-windows-msvc/release-smaller" +RESOURCE_DIR="resources/win32-x86-64" +LIB_NAME="bdkffi.ddl" + +# Move to the Rust library directory +cd ../bdk-ffi/ || exit + +# Build the Rust library +rustup default 1.77.1 +rustup target add $COMPILATION_TARGET +cargo build --profile release-smaller --target $COMPILATION_TARGET + +# Generate Kotlin bindings using uniffi-bindgen +cargo run --bin uniffi-bindgen generate --library ./$TARGET_DIR/$LIB_NAME --language kotlin --out-dir ../bdk-jvm/lib/src/main/kotlin/ --no-format + +# Copy the binary to the resources directory +mkdir -p ../bdk-jvm/lib/src/main/$RESOURCE_DIR/ +cp ./$TARGET_DIR/$LIB_NAME ../bdk-jvm/lib/src/main/$RESOURCE_DIR/ diff --git a/bdk-jvm/settings.gradle.kts b/bdk-jvm/settings.gradle.kts index 8555c5ad..329cfd1d 100644 --- a/bdk-jvm/settings.gradle.kts +++ b/bdk-jvm/settings.gradle.kts @@ -1,7 +1,6 @@ rootProject.name = "bdk-jvm" include(":lib") -includeBuild("plugins") pluginManagement { repositories {