insert native lib into jar
This commit is contained in:
@@ -29,6 +29,11 @@ dependencies {
|
|||||||
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:${kotlinCoroutinesVersion}")
|
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:${kotlinCoroutinesVersion}")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sourceSets.main {
|
||||||
|
resources {
|
||||||
|
srcDirs("src/main/resources", "build/natives")
|
||||||
|
}
|
||||||
|
}
|
||||||
kotlin {
|
kotlin {
|
||||||
jvmToolchain(24)
|
jvmToolchain(24)
|
||||||
}
|
}
|
||||||
@@ -36,4 +41,12 @@ kotlin {
|
|||||||
tasks.test {
|
tasks.test {
|
||||||
useJUnitPlatform()
|
useJUnitPlatform()
|
||||||
}
|
}
|
||||||
project.layout.buildDirectory.set(file("../../build"))
|
tasks.register<Exec>("compileNativeLib") {
|
||||||
|
val java_home = System.getProperty("java.home")
|
||||||
|
environment("CGO_CFLAGS" to "-I$java_home/include -I$java_home/include/linux")
|
||||||
|
workingDir("src/main/go")
|
||||||
|
commandLine("go", "build", "-linkshared", "-buildmode=c-shared", "-o", layout.buildDirectory.get().dir("natives").file("pltbuild.so"))
|
||||||
|
}
|
||||||
|
tasks.processResources {
|
||||||
|
dependsOn += "compileNativeLib"
|
||||||
|
}
|
||||||
@@ -1,6 +1,5 @@
|
|||||||
package _go
|
package main
|
||||||
|
|
||||||
//#cgo CFLAGS: -I "$JAVA_HOME/include" -I "$JAVA_HOME/include/linux"
|
|
||||||
//#include "pltbuild.h"
|
//#include "pltbuild.h"
|
||||||
import "C"
|
import "C"
|
||||||
import (
|
import (
|
||||||
@@ -1,5 +1,19 @@
|
|||||||
package moe.rosa.planterette.jni
|
package moe.rosa.planterette.jni
|
||||||
|
|
||||||
|
import java.io.File
|
||||||
|
import java.nio.file.Files
|
||||||
|
|
||||||
object GoFile {
|
object GoFile {
|
||||||
external fun write(fd: Int, str: String)
|
external fun write(fd: Int, str: String)
|
||||||
|
init {
|
||||||
|
val libname = "pltbuild.so"
|
||||||
|
val url = GoFile::class.java.getResource("/$libname")
|
||||||
|
val tmpDir = Files.createTempDirectory("pltbuild").toFile()
|
||||||
|
tmpDir.deleteOnExit()
|
||||||
|
val nativeLibTmpFile = File(tmpDir, libname)
|
||||||
|
url?.openStream().use {
|
||||||
|
Files.copy(it!!, nativeLibTmpFile.toPath())
|
||||||
|
}
|
||||||
|
System.load(nativeLibTmpFile.absolutePath)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user