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