blyat multi arch gcc
This commit is contained in:
149
build.gradle.kts
149
build.gradle.kts
@ -24,8 +24,12 @@ kotlin {
|
|||||||
jvmToolchain(25)
|
jvmToolchain(25)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val targets = listOf(
|
||||||
|
"x86_64-linux-gnu" to "linux-x86_64",
|
||||||
|
"aarch64-linux-gnu" to "linux-aarch64"
|
||||||
|
)
|
||||||
|
|
||||||
tasks.jar {
|
tasks.jar {
|
||||||
dependsOn("buildTunLib")
|
|
||||||
dependsOn(configurations.runtimeClasspath)
|
dependsOn(configurations.runtimeClasspath)
|
||||||
|
|
||||||
manifest {
|
manifest {
|
||||||
@ -85,7 +89,7 @@ tasks.register("generateTestClientConfig") {
|
|||||||
file.writeText("""
|
file.writeText("""
|
||||||
{
|
{
|
||||||
"type": "client",
|
"type": "client",
|
||||||
"host": "192.168.88.247",
|
"host": "192.168.88.227",
|
||||||
"address": "10.1.0.2",
|
"address": "10.1.0.2",
|
||||||
"port": 9093
|
"port": 9093
|
||||||
}
|
}
|
||||||
@ -93,67 +97,79 @@ tasks.register("generateTestClientConfig") {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
tasks.register<JavaExec>("runServer") {
|
targets.forEach { (toolchain, folder) ->
|
||||||
group = "app"
|
tasks.register<JavaExec>("runClient_$folder") {
|
||||||
description = "Run server"
|
group = "app/$folder"
|
||||||
classpath = sourceSets["main"].runtimeClasspath
|
description = "Run client"
|
||||||
mainClass.set("su.sonoma.MainKt")
|
classpath = sourceSets["main"].runtimeClasspath
|
||||||
args = listOf("${projectDir}/build/tmp/server.json")
|
mainClass.set("su.sonoma.MainKt")
|
||||||
jvmArgs = listOf(
|
args = listOf("${projectDir}/build/tmp/client.json")
|
||||||
"--add-opens=java.base/java.io=ALL-UNNAMED"
|
jvmArgs = listOf(
|
||||||
)
|
"--add-opens=java.base/java.io=ALL-UNNAMED"
|
||||||
dependsOn("buildTunLib")
|
)
|
||||||
dependsOn("generateTestServerConfig")
|
dependsOn("buildTunLib_$folder")
|
||||||
|
dependsOn("generateTestClientConfig")
|
||||||
|
|
||||||
systemProperty(
|
systemProperty(
|
||||||
"java.library.path",
|
"java.library.path",
|
||||||
"${projectDir}/build/native/"
|
"${projectDir}/build/native/$folder/"
|
||||||
)
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
tasks.register<JavaExec>("runClient") {
|
targets.forEach { (toolchain, folder) ->
|
||||||
group = "app"
|
tasks.register<JavaExec>("runServer_$folder") {
|
||||||
description = "Run client"
|
group = "app/$folder"
|
||||||
classpath = sourceSets["main"].runtimeClasspath
|
description = "Run server"
|
||||||
mainClass.set("su.sonoma.MainKt")
|
classpath = sourceSets["main"].runtimeClasspath
|
||||||
args = listOf("${projectDir}/build/tmp/client.json")
|
mainClass.set("su.sonoma.MainKt")
|
||||||
jvmArgs = listOf(
|
args = listOf("${projectDir}/build/tmp/server.json")
|
||||||
"--add-opens=java.base/java.io=ALL-UNNAMED"
|
jvmArgs = listOf(
|
||||||
)
|
"--add-opens=java.base/java.io=ALL-UNNAMED"
|
||||||
dependsOn("buildTunLib")
|
)
|
||||||
dependsOn("generateTestClientConfig")
|
dependsOn("buildTunLib_$folder")
|
||||||
|
dependsOn("generateTestServerConfig")
|
||||||
|
|
||||||
systemProperty(
|
systemProperty(
|
||||||
"java.library.path",
|
"java.library.path",
|
||||||
"${projectDir}/build/native/"
|
"${projectDir}/build/native/$folder/"
|
||||||
)
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
val javaHome = Jvm.current().javaHome.absolutePath
|
val javaHome = Jvm.current().javaHome.absolutePath
|
||||||
|
|
||||||
tasks.register<Exec>("buildTunLib") {
|
|
||||||
group = "build"
|
|
||||||
|
|
||||||
val outputDir = layout.buildDirectory.dir("native").get().asFile
|
targets.forEach { (toolchain, folder) ->
|
||||||
|
tasks.register<Exec>("buildTunLib_$folder") {
|
||||||
|
group = "build"
|
||||||
|
|
||||||
doFirst {
|
val outputDir = layout.buildDirectory.dir("native/$folder").get().asFile
|
||||||
outputDir.mkdirs()
|
|
||||||
|
doFirst {
|
||||||
|
outputDir.mkdirs()
|
||||||
|
}
|
||||||
|
|
||||||
|
commandLine(
|
||||||
|
"$toolchain-gcc",
|
||||||
|
"-shared",
|
||||||
|
"-fPIC",
|
||||||
|
"-z", "noexecstack",
|
||||||
|
|
||||||
|
"-o",
|
||||||
|
"${outputDir.absolutePath}/libtun.so",
|
||||||
|
|
||||||
|
"src/main/c/tun.c",
|
||||||
|
|
||||||
|
"-I$javaHome/include",
|
||||||
|
"-I$javaHome/include/linux"
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
commandLine(
|
tasks.register("buildTunLib") {
|
||||||
"gcc",
|
group = "build"
|
||||||
"-shared",
|
dependsOn(tasks.matching { it.name.startsWith("buildTunLib_") })
|
||||||
"-fPIC",
|
|
||||||
"-z", "noexecstack",
|
|
||||||
|
|
||||||
"-o",
|
|
||||||
"${outputDir.absolutePath}/libtun.so",
|
|
||||||
|
|
||||||
"src/main/c/tun.c",
|
|
||||||
|
|
||||||
"-I$javaHome/include",
|
|
||||||
"-I$javaHome/include/linux"
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
tasks.register("generateRunScript") {
|
tasks.register("generateRunScript") {
|
||||||
@ -181,26 +197,35 @@ tasks.register("generateRunScript") {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
tasks.register<Tar>("packageApp") {
|
targets.forEach { (toolchain, folder) ->
|
||||||
group = "build"
|
tasks.register<Tar>("packageApp_$folder") {
|
||||||
|
group = "build"
|
||||||
|
|
||||||
destinationDirectory.set(layout.buildDirectory.dir("dist"))
|
destinationDirectory.set(layout.buildDirectory.dir("dist/$folder"))
|
||||||
|
|
||||||
compression = Compression.GZIP
|
compression = Compression.GZIP
|
||||||
|
|
||||||
dependsOn("jar")
|
dependsOn("jar")
|
||||||
dependsOn("generateRunScript")
|
dependsOn("buildTunLib_$folder")
|
||||||
|
dependsOn("generateRunScript")
|
||||||
|
|
||||||
val name = rootProject.name.plus('-').plus(version)
|
val name = rootProject.name.plus('-').plus(version)
|
||||||
val jarName = name.plus(".jar")
|
val jarName = name.plus(".jar")
|
||||||
|
|
||||||
archiveFileName.set("$name.tar.gz")
|
archiveFileName.set("$name-$folder.tar.gz")
|
||||||
|
|
||||||
|
|
||||||
from("build/libs/$jarName")
|
from("build/libs/$jarName")
|
||||||
|
|
||||||
from("build/native/libtun.so")
|
from("build/native/$folder/libtun.so")
|
||||||
|
|
||||||
from("build/tmp/${rootProject.name}")
|
from("build/tmp/${rootProject.name}")
|
||||||
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
tasks.register("packageApp") {
|
||||||
|
group = "build"
|
||||||
|
dependsOn(tasks.matching { it.name.startsWith("packageApp_") })
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
@ -14,13 +14,14 @@ fun startClient(host: String, address: String, port: Int) = runBlocking {
|
|||||||
val input = socket.getInputStream()
|
val input = socket.getInputStream()
|
||||||
val output = socket.getOutputStream()
|
val output = socket.getOutputStream()
|
||||||
|
|
||||||
|
println("Client trying to pair")
|
||||||
|
|
||||||
launch {
|
launch {
|
||||||
val buffer = ByteArray(32768)
|
val buffer = ByteArray(32768)
|
||||||
println("Client trying to pair")
|
println("Client connected - $host:$port")
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
val len = tun.input.read(buffer)
|
val len = tun.input.read(buffer)
|
||||||
println("Client connected - $host:$port")
|
|
||||||
|
|
||||||
if (len > 0) {
|
if (len > 0) {
|
||||||
output.write(len shr 8)
|
output.write(len shr 8)
|
||||||
|
|||||||
Reference in New Issue
Block a user