insert native lib into jar
This commit is contained in:
parent
96bb989ad5
commit
aa3c3377d0
@ -29,6 +29,11 @@ dependencies {
|
||||
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:${kotlinCoroutinesVersion}")
|
||||
}
|
||||
|
||||
sourceSets.main {
|
||||
resources {
|
||||
srcDirs("src/main/resources", "build/natives")
|
||||
}
|
||||
}
|
||||
kotlin {
|
||||
jvmToolchain(24)
|
||||
}
|
||||
@ -36,4 +41,12 @@ kotlin {
|
||||
tasks.test {
|
||||
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"
|
||||
import "C"
|
||||
import (
|
||||
@ -1,5 +1,19 @@
|
||||
package moe.rosa.planterette.jni
|
||||
|
||||
import java.io.File
|
||||
import java.nio.file.Files
|
||||
|
||||
object GoFile {
|
||||
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)
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user