Remove intermediate tasks from Bitcoindevkit group

This ensures they don't show up when using ./gradlew :jvm:tasks. The
only two tasks that will appear in the end will be buildJvmLib and
buildAndroidLib.
This commit is contained in:
thunderbiscuit
2022-04-05 22:17:12 -04:00
parent 35f097542b
commit e566c4017c
3 changed files with 22 additions and 11 deletions

View File

@@ -0,0 +1,13 @@
package org.bitcoindevkit.plugins
enum class Arch {
AARCH64,
X86_64,
OTHER,
}
enum class OS {
MAC,
LINUX,
OTHER,
}

View File

@@ -0,0 +1,88 @@
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
else -> OS.OTHER
}
val architecture: Arch = when (System.getProperty("os.arch")) {
"x86_64" -> Arch.X86_64
"aarch64" -> Arch.AARCH64
else -> Arch.OTHER
}
// register a task of type Exec called buildJvmBinary
// which will run something like
// cargo build --release --target aarch64-apple-darwin
val buildJvmBinary by tasks.register<Exec>("buildJvmBinary") {
// group = "Bitcoindevkit"
// description = "Build the JVM binaries for the bitcoindevkit"
workingDir("${project.projectDir}/../bdk-ffi")
val cargoArgs: MutableList<String> = mutableListOf("build", "--release", "--target")
if (operatingSystem == OS.MAC && architecture == Arch.X86_64) {
cargoArgs.add("x86_64-apple-darwin")
} else if (operatingSystem == OS.MAC && architecture == Arch.AARCH64) {
cargoArgs.add("aarch64-apple-darwin")
} else if (operatingSystem == OS.LINUX) {
cargoArgs.add("x86_64-unknown-linux-gnu")
}
executable("cargo")
args(cargoArgs)
doLast {
println("Native library for bdk-jvm on ${cargoArgs.last()} successfully built")
}
}
// move the native libs build by cargo from bdk-ffi/target/.../release/
// to their place in the bdk-jvm library
val moveNativeJvmLib by tasks.register<Copy>("moveNativeJvmLib") {
// group = "Bitcoindevkit"
// description = "Move the native libraries to the bdk-jvm project"
dependsOn(buildJvmBinary)
var targetDir = ""
var resDir = ""
if (operatingSystem == OS.MAC && architecture == Arch.X86_64) {
targetDir = "x86_64-apple-darwin"
resDir = "darwin-x86-64"
} else if (operatingSystem == OS.MAC && architecture == Arch.AARCH64) {
targetDir = "aarch64-apple-darwin"
resDir = "darwin-aarch64"
} else if (operatingSystem == OS.LINUX) {
targetDir = "x86_64-unknown-linux-gnu"
resDir = "linux-x86-64"
}
from("${project.projectDir}/../bdk-ffi/target/$targetDir/release/libbdkffi.dylib")
into("${project.projectDir}/../jvm/src/main/resources/$resDir/")
doLast {
println("$targetDir native binaries for JVM moved to ./jvm/src/main/resources/$resDir/")
}
}
// generate the bindings using the bdk-ffi-bindgen tool
// created in the bdk-ffi submodule
val generateJvmBindings by tasks.register<Exec>("generateJvmBindings") {
// group = "Bitcoindevkit"
// description = "Building the bindings file for the bitcoindevkit"
dependsOn(moveNativeJvmLib)
workingDir("${project.projectDir}/../bdk-ffi")
executable("cargo")
args("run", "--package", "bdk-ffi-bindgen", "--", "--language", "kotlin", "--out-dir", "../jvm/src/main/kotlin")
doLast {
println("JVM bindings file successfully created")
}
}
tasks.register("buildJvmLib") {
group = "Bitcoindevkit"
description = "Aggregate task to build JVM library"
dependsOn(buildJvmBinary, moveNativeJvmLib, generateJvmBindings)
}