Skip to content

Commit

Permalink
Samples: Get rid of KotlinNativeTarget and KonanTarget imports
Browse files Browse the repository at this point in the history
  • Loading branch information
ilmat192 committed Jun 5, 2019
1 parent edda913 commit 90decbf
Show file tree
Hide file tree
Showing 13 changed files with 201 additions and 245 deletions.
29 changes: 13 additions & 16 deletions samples/csvparser/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,28 +1,25 @@
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTargetPreset

plugins {
kotlin("multiplatform")
}

// Determine host preset.
val hostOs = System.getProperty("os.name")

val hostPreset: KotlinNativeTargetPreset = when {
hostOs == "Mac OS X" -> "macosX64"
hostOs == "Linux" -> "linuxX64"
hostOs.startsWith("Windows") -> "mingwX64"
else -> throw GradleException("Host OS '$hostOs' is not supported in Kotlin/Native $project.")
}.let {
kotlin.presets[it] as KotlinNativeTargetPreset
}

kotlin {
targetFromPreset(hostPreset, "csvParser") {
// Determine host preset.
val hostOs = System.getProperty("os.name")

// Create target for the host platform.
val hostTarget = when {
hostOs == "Mac OS X" -> macosX64("csvParser")
hostOs == "Linux" -> linuxX64("csvParser")
hostOs.startsWith("Windows") -> mingwX64("csvParser")
else -> throw GradleException("Host OS '$hostOs' is not supported in Kotlin/Native $project.")
}

hostTarget.apply {
binaries {
executable {
entryPoint = "sample.csvparser.main"
runTask?.args("./European_Mammals_Red_List_Nov_2009.csv", 4, 100)
}
}
}
}
}
31 changes: 14 additions & 17 deletions samples/curl/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTargetPreset
import org.jetbrains.kotlin.konan.target.KonanTarget.*

plugins {
kotlin("multiplatform")
}
Expand All @@ -11,26 +8,26 @@ repositories {
maven("file://$localRepo")
}

// Determine host preset.
val hostOs = System.getProperty("os.name")

val hostPreset: KotlinNativeTargetPreset = when {
hostOs == "Mac OS X" -> "macosX64"
hostOs == "Linux" -> "linuxX64"
hostOs.startsWith("Windows") -> "mingwX64"
else -> throw GradleException("Host OS '$hostOs' is not supported in Kotlin/Native $project.")
}.let {
kotlin.presets[it] as KotlinNativeTargetPreset
}

val mingwPath = File(System.getenv("MINGW64_DIR") ?: "C:/msys64/mingw64")

kotlin {
targetFromPreset(hostPreset, "curl") {
// Determine host preset.
val hostOs = System.getProperty("os.name")
val isMingwX64 = hostOs.startsWith("Windows")

// Create target for the host platform.
val hostTarget = when {
hostOs == "Mac OS X" -> macosX64("curl")
hostOs == "Linux" -> linuxX64("curl")
isMingwX64 -> mingwX64("curl")
else -> throw GradleException("Host OS '$hostOs' is not supported in Kotlin/Native $project.")
}

hostTarget.apply {
binaries {
executable {
entryPoint = "sample.curl.main"
if (hostPreset.konanTarget == MINGW_X64) {
if (isMingwX64) {
// Add lib path to `libcurl` and its dependencies:
linkerOpts(mingwPath.resolve("lib").toString())
runTask?.environment("PATH" to mingwPath.resolve("bin"))
Expand Down
44 changes: 19 additions & 25 deletions samples/echoServer/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,31 @@ plugins {
kotlin("multiplatform")
}

// Determine host preset.
val hostOs = System.getProperty("os.name")

val hostPreset: KotlinNativeTargetPreset = when {
hostOs == "Mac OS X" -> "macosX64"
hostOs == "Linux" -> "linuxX64"
hostOs.startsWith("Windows") -> "mingwX64"
else -> throw GradleException("Host OS '$hostOs' is not supported in Kotlin/Native $project.")
}.let {
kotlin.presets[it] as KotlinNativeTargetPreset
}

// Add two additional presets for Raspberry Pi.
val raspberryPiPresets: List<KotlinNativeTargetPreset> = listOf("linuxArm32Hfp", "linuxArm64").map {
kotlin.presets[it] as KotlinNativeTargetPreset
}

kotlin {
targetFromPreset(hostPreset, "echoServer") {
// Determine host preset.
val hostOs = System.getProperty("os.name")

// 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 raspberryPiTargets = raspberryPiPresets.map { preset ->
val targetName = "echoServer${preset.name.capitalize()}"
targetFromPreset(preset, targetName) {}
}

// Configure executables for all targets.
configure(raspberryPiTargets + listOf(hostTarget)) {
binaries {
executable {
entryPoint = "sample.echoserver.main"
Expand All @@ -31,18 +37,6 @@ kotlin {
}
}

raspberryPiPresets.forEach { preset ->
val targetName = "echoServer${preset.name.capitalize()}"
targetFromPreset(preset, targetName) {
binaries {
executable {
entryPoint = "sample.echoserver.main"
runTask?.args(3000)
}
}
}
}

sourceSets {
val echoServerMain by getting
raspberryPiPresets.forEach { preset ->
Expand Down
39 changes: 18 additions & 21 deletions samples/gitchurn/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,30 +1,27 @@
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTargetPreset
import org.jetbrains.kotlin.konan.target.KonanTarget.*

plugins {
kotlin("multiplatform")
}

// Determine host preset.
val hostOs = System.getProperty("os.name")

val hostPreset: KotlinNativeTargetPreset = when {
hostOs == "Mac OS X" -> "macosX64"
hostOs == "Linux" -> "linuxX64"
hostOs.startsWith("Windows") -> "mingwX64"
else -> throw GradleException("Host OS '$hostOs' is not supported in Kotlin/Native $project.")
}.let {
kotlin.presets[it] as KotlinNativeTargetPreset
}

val mingwPath = File(System.getenv("MINGW64_DIR") ?: "C:/msys64/mingw64")

kotlin {
targetFromPreset(hostPreset, "gitChurn") {
// Determine host preset.
val hostOs = System.getProperty("os.name")
val isMingwX64 = hostOs.startsWith("Windows")

// Create a target for the host platform.
val hostTarget = when {
hostOs == "Mac OS X" -> macosX64("gitChurn")
hostOs == "Linux" -> linuxX64("gitChurn")
isMingwX64 -> mingwX64("gitChurn")
else -> throw GradleException("Host OS '$hostOs' is not supported in Kotlin/Native $project.")
}

hostTarget.apply {
binaries {
executable {
entryPoint = "sample.gitchurn.main"
if (hostPreset.konanTarget == MINGW_X64) {
if (isMingwX64) {
linkerOpts(mingwPath.resolve("lib").toString())
runTask?.environment("PATH" to mingwPath.resolve("bin"))
}
Expand All @@ -33,10 +30,10 @@ kotlin {
}
compilations["main"].cinterops {
val libgit2 by creating {
when (hostPreset.konanTarget) {
MACOS_X64 -> includeDirs.headerFilterOnly("/opt/local/include", "/usr/local/include")
LINUX_X64 -> includeDirs.headerFilterOnly("/usr/include")
MINGW_X64 -> includeDirs.headerFilterOnly(mingwPath.resolve("include"))
when (preset) {
presets["macosX64"] -> includeDirs.headerFilterOnly("/opt/local/include", "/usr/local/include")
presets["linuxX64"] -> includeDirs.headerFilterOnly("/usr/include")
presets["mingwX64"] -> includeDirs.headerFilterOnly(mingwPath.resolve("include"))
}
}
}
Expand Down
25 changes: 11 additions & 14 deletions samples/globalState/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,23 +1,20 @@
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTargetPreset

plugins {
kotlin("multiplatform")
}

// Determine host preset.
val hostOs = System.getProperty("os.name")
kotlin {
// Determine host preset.
val hostOs = System.getProperty("os.name")

val hostPreset: KotlinNativeTargetPreset = when {
hostOs == "Mac OS X" -> "macosX64"
hostOs == "Linux" -> "linuxX64"
hostOs.startsWith("Windows") -> "mingwX64"
else -> throw GradleException("Host OS '$hostOs' is not supported in Kotlin/Native $project.")
}.let {
kotlin.presets[it] as KotlinNativeTargetPreset
}
// Create target for the host platform.
val hostTarget = when {
hostOs == "Mac OS X" -> macosX64("globalState")
hostOs == "Linux" -> linuxX64("globalState")
hostOs.startsWith("Windows") -> mingwX64("globalState")
else -> throw GradleException("Host OS '$hostOs' is not supported in Kotlin/Native $project.")
}

kotlin {
targetFromPreset(hostPreset, "globalState") {
hostTarget.apply {
binaries {
executable {
entryPoint = "sample.globalstate.main"
Expand Down
37 changes: 17 additions & 20 deletions samples/gtk/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,39 +1,36 @@
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTargetPreset
import org.jetbrains.kotlin.konan.target.KonanTarget.*

plugins {
kotlin("multiplatform")
}

// Determine host preset.
val hostOs = System.getProperty("os.name")

val hostPreset: KotlinNativeTargetPreset = when {
hostOs == "Mac OS X" -> "macosX64"
hostOs == "Linux" -> "linuxX64"
hostOs.startsWith("Windows") -> "mingwX64"
else -> throw GradleException("Host OS '$hostOs' is not supported in Kotlin/Native $project.")
}.let {
kotlin.presets[it] as KotlinNativeTargetPreset
}

val mingwPath = File(System.getenv("MINGW64_DIR") ?: "C:/msys64/mingw64")

kotlin {
targetFromPreset(hostPreset, "gtk") {
// Determine host preset.
val hostOs = System.getProperty("os.name")
val isMingwX64 = hostOs.startsWith("Windows")

// Create a target for the host platform.
val hostTarget = when {
hostOs == "Mac OS X" -> macosX64("gtk")
hostOs == "Linux" -> linuxX64("gtk")
isMingwX64 -> mingwX64("gtk")
else -> throw GradleException("Host OS '$hostOs' is not supported in Kotlin/Native $project.")
}

hostTarget.apply {
binaries {
executable {
entryPoint = "sample.gtk.main"
if (hostPreset.konanTarget == MINGW_X64) {
if (isMingwX64) {
linkerOpts(mingwPath.resolve("lib").toString())
runTask?.environment("PATH" to mingwPath.resolve("bin"))
}
}
}
compilations["main"].cinterops {
val gtk3 by creating {
when (hostPreset.konanTarget) {
MACOS_X64, LINUX_X64 -> {
when (preset) {
presets["macosX64"], presets["linuxX64"] -> {
listOf("/opt/local/include", "/usr/include", "/usr/local/include").forEach {
includeDirs(
"$it/atk-1.0",
Expand All @@ -51,7 +48,7 @@ kotlin {
"/usr/local/lib/glib-2.0/include"
)
}
MINGW_X64 -> {
presets["mingwX64"] -> {
listOf(
"/include/atk-1.0",
"/include/gdk-pixbuf-2.0",
Expand Down
37 changes: 17 additions & 20 deletions samples/libcurl/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTargetPreset
import org.jetbrains.kotlin.konan.target.KonanTarget.*

plugins {
kotlin("multiplatform")
`maven-publish`
Expand All @@ -21,28 +18,28 @@ val cleanLocalRepo by tasks.creating(Delete::class) {
delete(localRepo)
}

// Determine host preset.
val hostOs = System.getProperty("os.name")

val hostPreset: KotlinNativeTargetPreset = when {
hostOs == "Mac OS X" -> "macosX64"
hostOs == "Linux" -> "linuxX64"
hostOs.startsWith("Windows") -> "mingwX64"
else -> throw GradleException("Host OS '$hostOs' is not supported in Kotlin/Native $project.")
}.let {
kotlin.presets[it] as KotlinNativeTargetPreset
}

val mingwPath = File(System.getenv("MINGW64_DIR") ?: "C:/msys64/mingw64")

kotlin {
targetFromPreset(hostPreset, "libcurl") {

// Determine host preset.
val hostOs = System.getProperty("os.name")

// Create target for the host platform.
val hostTarget = when {
hostOs == "Mac OS X" -> macosX64("libcurl")
hostOs == "Linux" -> linuxX64("libcurl")
hostOs.startsWith("Windows") -> mingwX64("libcurl")
else -> throw GradleException("Host OS '$hostOs' is not supported in Kotlin/Native $project.")
}

hostTarget.apply {
compilations["main"].cinterops {
val libcurl by creating {
when (hostPreset.konanTarget) {
MACOS_X64 -> includeDirs.headerFilterOnly("/opt/local/include", "/usr/local/include")
LINUX_X64 -> includeDirs.headerFilterOnly("/usr/include", "/usr/include/x86_64-linux-gnu")
MINGW_X64 -> includeDirs.headerFilterOnly(mingwPath.resolve("/include"))
when (preset) {
presets["macosX64"] -> includeDirs.headerFilterOnly("/opt/local/include", "/usr/local/include")
presets["linuxX64"] -> includeDirs.headerFilterOnly("/usr/include", "/usr/include/x86_64-linux-gnu")
presets["mingwX64"] -> includeDirs.headerFilterOnly(mingwPath.resolve("/include"))
}
}
}
Expand Down
Loading

0 comments on commit 90decbf

Please sign in to comment.