[K/N] Samples: Migrate 'echoServer' to modern multiplatform

^KT-50547 Fixed
This commit is contained in:
Sebastian Sellmair
2023-11-22 20:32:14 +01:00
committed by Space Team
parent 97ef2de6e3
commit 359f5fe7b3
4 changed files with 13 additions and 38 deletions
@@ -49,7 +49,7 @@ val buildSamplesWithPlatformLibs by tasks.creating {
dependsOn(":workers:assemble")
if (isMacos || isLinux) {
dependsOn(":echoServer:assemble") // https://youtrack.jetbrains.com/issue/KT-50547
dependsOn(":echoServer:assemble") //https://youtrack.jetbrains.com/issue/KT-63721/
dependsOn(":nonBlockingEchoServer:assemble")
dependsOn(":tensorflow:assemble")
}
@@ -1,33 +1,22 @@
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTargetPreset
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget
plugins {
kotlin("multiplatform")
}
val additionalPresets: List<KotlinNativeTargetPreset> = listOf("linuxArm64").map {
kotlin.presets[it] as KotlinNativeTargetPreset
}
kotlin {
// Determine host preset.
val hostOs = System.getProperty("os.name")
macosX64()
macosArm64()
linuxArm64()
linuxX64()
/*
https://youtrack.jetbrains.com/issue/KT-63721/Commonizer-Uncovered-platform.posix.socket-not-commonized-for-mingw-linux-macos
Not building for windows, because it would require writing expect/actuals around
signed vs unsigned socket APIs:
mingwX64()
*/
// Create a target for the host platform.
val hostTarget = when {
hostOs == "Mac OS X" -> macosX64("echoServer")
hostOs == "Linux" -> linuxX64("echoServer")
hostOs.startsWith("Windows") -> mingwX64("echoServer")
else -> throw GradleException("Host OS '$hostOs' is not supported in Kotlin/Native $project.")
}
// Create cross-targets.
val additionalTargets = additionalPresets.map { preset ->
val targetName = "echoServer${preset.name.capitalize()}"
targetFromPreset(preset, targetName) {}
}
// Configure executables for all targets.
configure(additionalTargets + listOf(hostTarget)) {
targets.withType<KotlinNativeTarget>().configureEach {
binaries {
executable {
entryPoint = "sample.echoserver.main"
@@ -35,17 +24,4 @@ kotlin {
}
}
}
sourceSets {
val echoServerMain by getting
additionalPresets.forEach { preset ->
val mainSourceSetName = "echoServer${preset.name.capitalize()}Main"
getByName(mainSourceSetName).dependsOn(echoServerMain)
}
}
// Enable experimental stdlib API used by the sample.
sourceSets.all {
languageSettings.optIn("kotlin.ExperimentalStdlibApi")
}
}
@@ -1,2 +1 @@
kotlin.code.style=official
kotlin.import.noCommonSourceSets=true