Build both x86_64 and aarch64 binaries when building bdk-jvm on macOS
This commit is contained in:
parent
c9c85875a5
commit
9b8cc006ba
@ -1,65 +1,81 @@
|
|||||||
package org.bitcoindevkit.plugins
|
package org.bitcoindevkit.plugins
|
||||||
|
|
||||||
// register a task of type Exec called buildJvmBinary
|
// register a task called buildJvmBinaries which will run something like
|
||||||
// which will run something like
|
|
||||||
// cargo build --release --target aarch64-apple-darwin
|
// cargo build --release --target aarch64-apple-darwin
|
||||||
val buildJvmBinary by tasks.register<Exec>("buildJvmBinary") {
|
val buildJvmBinaries by tasks.register<DefaultTask>("buildJvmBinaries") {
|
||||||
|
if (operatingSystem == OS.MAC) {
|
||||||
|
exec {
|
||||||
workingDir("${project.projectDir}/../bdk-ffi")
|
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")
|
executable("cargo")
|
||||||
|
val cargoArgs: List<String> = listOf("build", "--release", "--target", "x86_64-apple-darwin")
|
||||||
|
args(cargoArgs)
|
||||||
|
}
|
||||||
|
exec {
|
||||||
|
workingDir("${project.projectDir}/../bdk-ffi")
|
||||||
|
executable("cargo")
|
||||||
|
val cargoArgs: List<String> = listOf("build", "--release", "--target", "aarch64-apple-darwin")
|
||||||
|
args(cargoArgs)
|
||||||
|
}
|
||||||
|
} else if(operatingSystem == OS.LINUX) {
|
||||||
|
exec {
|
||||||
|
workingDir("${project.projectDir}/../bdk-ffi")
|
||||||
|
executable("cargo")
|
||||||
|
val cargoArgs: List<String> = listOf("build", "--release", "--target", "x86_64-unknown-linux-gnu")
|
||||||
args(cargoArgs)
|
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/
|
// move the native libs build by cargo from bdk-ffi/target/.../release/
|
||||||
// to their place in the bdk-jvm library
|
// to their place in the bdk-jvm library
|
||||||
val moveNativeJvmLib by tasks.register<Copy>("moveNativeJvmLib") {
|
val moveNativeJvmLibs by tasks.register<DefaultTask>("moveNativeJvmLibs") {
|
||||||
|
|
||||||
dependsOn(buildJvmBinary)
|
// dependsOn(buildJvmBinaryX86_64MacOS, buildJvmBinaryAarch64MacOS, buildJvmBinaryLinux)
|
||||||
|
dependsOn(buildJvmBinaries)
|
||||||
|
|
||||||
var targetDir = ""
|
data class CopyMetadata(val targetDir: String, val resDir: String, val ext: String)
|
||||||
var resDir = ""
|
val libsToCopy: MutableList<CopyMetadata> = mutableListOf()
|
||||||
var ext = ""
|
|
||||||
if (operatingSystem == OS.MAC && architecture == Arch.X86_64) {
|
if (operatingSystem == OS.MAC) {
|
||||||
targetDir = "x86_64-apple-darwin"
|
libsToCopy.add(
|
||||||
resDir = "darwin-x86-64"
|
CopyMetadata(
|
||||||
|
targetDir = "aarch64-apple-darwin",
|
||||||
|
resDir = "darwin-aarch64",
|
||||||
ext = "dylib"
|
ext = "dylib"
|
||||||
} else if (operatingSystem == OS.MAC && architecture == Arch.AARCH64) {
|
)
|
||||||
targetDir = "aarch64-apple-darwin"
|
)
|
||||||
resDir = "darwin-aarch64"
|
libsToCopy.add(
|
||||||
|
CopyMetadata(
|
||||||
|
targetDir = "x86_64-apple-darwin",
|
||||||
|
resDir = "darwin-x86-64",
|
||||||
ext = "dylib"
|
ext = "dylib"
|
||||||
|
)
|
||||||
|
)
|
||||||
} else if (operatingSystem == OS.LINUX) {
|
} else if (operatingSystem == OS.LINUX) {
|
||||||
targetDir = "x86_64-unknown-linux-gnu"
|
libsToCopy.add(
|
||||||
resDir = "linux-x86-64"
|
CopyMetadata(
|
||||||
|
targetDir = "x86_64-unknown-linux-gnu",
|
||||||
|
resDir = "linux-x86-64",
|
||||||
ext = "so"
|
ext = "so"
|
||||||
|
)
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
from("${project.projectDir}/../bdk-ffi/target/$targetDir/release/libbdkffi.$ext")
|
libsToCopy.forEach {
|
||||||
into("${project.projectDir}/../jvm/src/main/resources/$resDir/")
|
doFirst {
|
||||||
|
copy {
|
||||||
doLast {
|
with(it) {
|
||||||
println("$targetDir native binaries for JVM moved to ./jvm/src/main/resources/$resDir/")
|
from("${project.projectDir}/../bdk-ffi/target/${this.targetDir}/release/libbdkffi.${this.ext}")
|
||||||
|
into("${project.projectDir}/../jvm/src/main/resources/${this.resDir}/")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// generate the bindings using the bdk-ffi-bindgen tool
|
// generate the bindings using the bdk-ffi-bindgen tool created in the bdk-ffi submodule
|
||||||
// created in the bdk-ffi submodule
|
|
||||||
val generateJvmBindings by tasks.register<Exec>("generateJvmBindings") {
|
val generateJvmBindings by tasks.register<Exec>("generateJvmBindings") {
|
||||||
|
|
||||||
dependsOn(moveNativeJvmLib)
|
dependsOn(moveNativeJvmLibs)
|
||||||
|
|
||||||
workingDir("${project.projectDir}/../bdk-ffi")
|
workingDir("${project.projectDir}/../bdk-ffi")
|
||||||
executable("cargo")
|
executable("cargo")
|
||||||
@ -70,15 +86,15 @@ val generateJvmBindings by tasks.register<Exec>("generateJvmBindings") {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// create an aggregate task which will run the 3 required tasks to build the JVM libs in order
|
// 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 group and description
|
// the task will also appear in the printout of the ./gradlew tasks task with a group and description
|
||||||
tasks.register("buildJvmLib") {
|
tasks.register("buildJvmLib") {
|
||||||
group = "Bitcoindevkit"
|
group = "Bitcoindevkit"
|
||||||
description = "Aggregate task to build JVM library"
|
description = "Aggregate task to build JVM library"
|
||||||
|
|
||||||
dependsOn(
|
dependsOn(
|
||||||
buildJvmBinary,
|
buildJvmBinaries,
|
||||||
moveNativeJvmLib,
|
moveNativeJvmLibs,
|
||||||
generateJvmBindings
|
generateJvmBindings
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user