Temp: Start Android plugin

This commit is contained in:
thunderbiscuit 2022-04-07 13:50:34 -04:00
parent e566c4017c
commit 758608419b
No known key found for this signature in database
GPG Key ID: 88253696EB836462
2 changed files with 96 additions and 0 deletions

View File

@ -3,7 +3,12 @@ plugins {
id("kotlin-android") id("kotlin-android")
id("maven-publish") id("maven-publish")
id("signing") id("signing")
// API docs
id("org.jetbrains.dokka") version "1.6.10" id("org.jetbrains.dokka") version "1.6.10"
// Custom plugin to generate the native libs and bindings file
id("org.bitcoindevkit.plugins.generate-android-bindings")
} }
android { android {

View File

@ -0,0 +1,91 @@
package org.bitcoindevkit.plugins
import org.gradle.kotlin.dsl.register
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("buildAndroidLib") {
// group = "Bitcoindevkit"
// description = "Aggregate task to build Android library"
// dependsOn(buildJvmBinary, moveNativeJvmLib, generateJvmBindings)
// }