From e95be11ade63491d26593e5d86b89512f74f5b6c Mon Sep 17 00:00:00 2001 From: Dmitriy Dolovov Date: Wed, 29 May 2019 11:54:42 +0300 Subject: [PATCH] Samples: Drop MPPTools + migrate to KTS --- samples/build.gradle | 69 --------- samples/build.gradle.kts | 73 ++++++++++ samples/buildSrc/build.gradle | 26 ---- samples/buildSrc/settings.gradle | 20 --- samples/buildSrc/src/main/kotlin/Internals.kt | 39 ----- samples/buildSrc/src/main/kotlin/MPPTools.kt | 67 --------- samples/coverage/build.gradle.kts | 6 +- samples/csvparser/build.gradle | 17 --- samples/csvparser/build.gradle.kts | 28 ++++ samples/curl/build.gradle | 57 -------- samples/curl/build.gradle.kts | 74 ++++++++++ samples/echoServer/build.gradle | 39 ----- samples/echoServer/build.gradle.kts | 53 +++++++ samples/gitchurn/build.gradle | 36 ----- samples/gitchurn/build.gradle.kts | 44 ++++++ samples/globalState/build.gradle | 19 --- samples/globalState/build.gradle.kts | 30 ++++ samples/gtk/build.gradle | 52 ------- samples/gtk/build.gradle.kts | 71 +++++++++ samples/html5Canvas/build.gradle | 82 ----------- samples/html5Canvas/build.gradle.kts | 97 +++++++++++++ samples/libcurl/build.gradle | 56 -------- samples/libcurl/build.gradle.kts | 60 ++++++++ samples/nonBlockingEchoServer/build.gradle | 17 --- .../nonBlockingEchoServer/build.gradle.kts | 28 ++++ samples/objc/build.gradle | 16 --- samples/objc/build.gradle.kts | 13 ++ samples/opengl/build.gradle | 16 --- samples/opengl/build.gradle.kts | 13 ++ samples/settings.gradle | 54 ------- samples/settings.gradle.kts | 51 +++++++ samples/tensorflow/build.gradle | 32 ----- samples/tensorflow/build.gradle.kts | 51 +++++++ samples/tetris/build.gradle | 134 ----------------- samples/tetris/build.gradle.kts | 135 ++++++++++++++++++ samples/torch/build.gradle | 38 ----- samples/torch/build.gradle.kts | 64 +++++++++ samples/videoplayer/build.gradle | 57 -------- samples/videoplayer/build.gradle.kts | 53 +++++++ samples/win32/build.gradle | 17 --- samples/win32/build.gradle.kts | 14 ++ samples/workers/build.gradle | 16 --- samples/workers/build.gradle.kts | 27 ++++ 43 files changed, 981 insertions(+), 980 deletions(-) delete mode 100644 samples/build.gradle create mode 100644 samples/build.gradle.kts delete mode 100644 samples/buildSrc/build.gradle delete mode 100644 samples/buildSrc/settings.gradle delete mode 100644 samples/buildSrc/src/main/kotlin/Internals.kt delete mode 100644 samples/buildSrc/src/main/kotlin/MPPTools.kt delete mode 100644 samples/csvparser/build.gradle create mode 100644 samples/csvparser/build.gradle.kts delete mode 100644 samples/curl/build.gradle create mode 100644 samples/curl/build.gradle.kts delete mode 100644 samples/echoServer/build.gradle create mode 100644 samples/echoServer/build.gradle.kts delete mode 100644 samples/gitchurn/build.gradle create mode 100644 samples/gitchurn/build.gradle.kts delete mode 100644 samples/globalState/build.gradle create mode 100644 samples/globalState/build.gradle.kts delete mode 100644 samples/gtk/build.gradle create mode 100644 samples/gtk/build.gradle.kts delete mode 100644 samples/html5Canvas/build.gradle create mode 100644 samples/html5Canvas/build.gradle.kts delete mode 100644 samples/libcurl/build.gradle create mode 100644 samples/libcurl/build.gradle.kts delete mode 100644 samples/nonBlockingEchoServer/build.gradle create mode 100644 samples/nonBlockingEchoServer/build.gradle.kts delete mode 100644 samples/objc/build.gradle create mode 100644 samples/objc/build.gradle.kts delete mode 100644 samples/opengl/build.gradle create mode 100644 samples/opengl/build.gradle.kts delete mode 100644 samples/settings.gradle create mode 100644 samples/settings.gradle.kts delete mode 100644 samples/tensorflow/build.gradle create mode 100644 samples/tensorflow/build.gradle.kts delete mode 100644 samples/tetris/build.gradle create mode 100644 samples/tetris/build.gradle.kts delete mode 100644 samples/torch/build.gradle create mode 100644 samples/torch/build.gradle.kts delete mode 100644 samples/videoplayer/build.gradle create mode 100644 samples/videoplayer/build.gradle.kts delete mode 100644 samples/win32/build.gradle create mode 100644 samples/win32/build.gradle.kts delete mode 100644 samples/workers/build.gradle create mode 100644 samples/workers/build.gradle.kts diff --git a/samples/build.gradle b/samples/build.gradle deleted file mode 100644 index a44d3403661..00000000000 --- a/samples/build.gradle +++ /dev/null @@ -1,69 +0,0 @@ -buildscript { - repositories { - mavenCentral() - maven { url 'https://dl.bintray.com/kotlin/kotlin-dev' } - maven { url 'https://dl.bintray.com/kotlin/kotlin-eap' } - } - - dependencies { - classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" - } -} - -allprojects { - repositories { - mavenCentral() - maven { url 'https://dl.bintray.com/kotlin/kotlin-dev' } - maven { url 'https://dl.bintray.com/kotlin/kotlin-eap' } - } -} - -def localRepo = rootProject.file('build/.m2-local') - -task clean { - doLast { - delete(localRepo) - } -} - -task buildSh(type: Exec) { - errorOutput = System.out - ignoreExitValue = true - workingDir projectDir - enabled = !MPPTools.isWindows() - if (MPPTools.isLinux() || MPPTools.isMacos()) { - commandLine "$projectDir/build.sh" - } -} - -task buildSamplesWithPlatformLibs() { - dependsOn ':csvparser:assemble' - dependsOn ':curl:assemble' - dependsOn ':echoServer:assemble' - dependsOn ':globalState:assemble' - dependsOn ':html5Canvas:assemble' - dependsOn ':workers:assemble' - - if (MPPTools.isMacos() || MPPTools.isLinux()) { - dependsOn ':nonBlockingEchoServer:assemble' - dependsOn ':tensorflow:assemble' - } - - if (MPPTools.isMacos()) { - dependsOn ':objc:assemble' - dependsOn ':opengl:assemble' - dependsOn ':uikit:assemble' - dependsOn ':coverage:assemble' - } - - if (MPPTools.isWindows()) { - dependsOn ':win32:assemble' - } -} - -task buildAllSamples() { - subprojects.each { - dependsOn("${it.path}:assemble") - } - finalizedBy buildSh -} diff --git a/samples/build.gradle.kts b/samples/build.gradle.kts new file mode 100644 index 00000000000..7fd1a66c6b4 --- /dev/null +++ b/samples/build.gradle.kts @@ -0,0 +1,73 @@ +buildscript { + repositories { + mavenCentral() + maven("https://dl.bintray.com/kotlin/kotlin-dev") + maven("https://dl.bintray.com/kotlin/kotlin-eap") + } + + val kotlin_version: String by rootProject + dependencies { + classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version") + } +} + +allprojects { + repositories { + mavenCentral() + maven("https://dl.bintray.com/kotlin/kotlin-dev") + maven("https://dl.bintray.com/kotlin/kotlin-eap") + } +} + +val hostOs = System.getProperty("os.name") +val isMacos = hostOs == "Mac OS X" +val isLinux = hostOs == "Linux" +val isWindows = hostOs.startsWith("Windows") + +val localRepo = rootProject.file("build/.m2-local") + +val clean by tasks.creating(Delete::class) { + delete(localRepo) +} + +val buildSh by tasks.creating(Exec::class) { + errorOutput = System.out + isIgnoreExitValue = true + workingDir = projectDir + enabled = !isWindows + if (isLinux || isMacos) { + commandLine = listOf(projectDir.resolve("build.sh").toString()) + } +} + +val buildSamplesWithPlatformLibs by tasks.creating { + dependsOn(":csvparser:assemble") + dependsOn(":curl:assemble") + dependsOn(":echoServer:assemble") + dependsOn(":globalState:assemble") + dependsOn(":html5Canvas:assemble") + dependsOn(":workers:assemble") + + if (isMacos || isLinux) { + dependsOn(":nonBlockingEchoServer:assemble") + dependsOn(":tensorflow:assemble") + } + + if (isMacos) { + dependsOn(":objc:assemble") + dependsOn(":opengl:assemble") + dependsOn(":uikit:assemble") + dependsOn(":coverage:assemble") + } + + if (isWindows) { + dependsOn(":win32:assemble") + } +} + +val buildAllSamples by tasks.creating { + subprojects.forEach { + dependsOn("${it.path}:assemble") + } + finalizedBy(buildSh) +} diff --git a/samples/buildSrc/build.gradle b/samples/buildSrc/build.gradle deleted file mode 100644 index f167e041313..00000000000 --- a/samples/buildSrc/build.gradle +++ /dev/null @@ -1,26 +0,0 @@ -buildscript { - repositories { - mavenCentral() - maven { url 'https://dl.bintray.com/kotlin/kotlin-dev' } - maven { url 'https://dl.bintray.com/kotlin/kotlin-eap' } - } - - dependencies { - classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" - } -} - -apply plugin: 'kotlin' - -repositories { - mavenCentral() - maven { url 'https://dl.bintray.com/kotlin/kotlin-dev' } - maven { url 'https://dl.bintray.com/kotlin/kotlin-eap' } - maven { url 'https://plugins.gradle.org/m2/' } -} - -dependencies { - compileOnly gradleApi() - implementation 'org.jetbrains.kotlin:kotlin-gradle-plugin' - implementation 'org.jetbrains.kotlin:kotlin-stdlib' -} diff --git a/samples/buildSrc/settings.gradle b/samples/buildSrc/settings.gradle deleted file mode 100644 index 43c08c10733..00000000000 --- a/samples/buildSrc/settings.gradle +++ /dev/null @@ -1,20 +0,0 @@ -// Reuse Kotlin version from the root project. -File rootProjectGradlePropertiesFile = file("${rootProject.projectDir}/../gradle.properties") -if (!rootProjectGradlePropertiesFile.isFile()) { - throw new Exception("File $rootProjectGradlePropertiesFile does not exist or is not a file") -} - -Properties rootProjectProperties = new Properties() -rootProjectGradlePropertiesFile.withInputStream { inputStream -> - rootProjectProperties.load(inputStream) - if (!rootProjectProperties.containsKey('kotlin_version')) { - throw new Exception("No 'kotlin_version' property in $rootProjectGradlePropertiesFile file") - } -} - -gradle.beforeProject { project -> - rootProjectProperties.forEach { String key, value -> - if (!project.hasProperty(key)) - project.ext[key] = value - } -} diff --git a/samples/buildSrc/src/main/kotlin/Internals.kt b/samples/buildSrc/src/main/kotlin/Internals.kt deleted file mode 100644 index d3c994c708f..00000000000 --- a/samples/buildSrc/src/main/kotlin/Internals.kt +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license - * that can be found in the license/LICENSE.txt file. - */ - -import org.gradle.api.NamedDomainObjectCollection -import org.gradle.api.NamedDomainObjectContainer -import org.gradle.api.Project -import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension -import org.jetbrains.kotlin.gradle.plugin.KotlinCompilation -import org.jetbrains.kotlin.gradle.plugin.KotlinTargetPreset -import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeCompilation -import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTargetPreset - -/* - * This file includes internal short-cuts visible only inside of the 'buildSrc' module. - */ - -internal val hostOs by lazy { System.getProperty("os.name") } -internal val userHome by lazy { System.getProperty("user.home") } - -internal val mingwX64Path by lazy { System.getenv("MINGW64_DIR") ?: "c:/msys64/mingw64" } -internal val mingwX86Path by lazy { System.getenv("MINGW32_DIR") ?: "c:/msys32/mingw32" } - - -internal val Project.kotlin: KotlinMultiplatformExtension - get() = extensions.getByName("kotlin") as KotlinMultiplatformExtension - -internal val NamedDomainObjectCollection>.macosX64: KotlinNativeTargetPreset - get() = getByName(::macosX64.name) as KotlinNativeTargetPreset - -internal val NamedDomainObjectCollection>.linuxX64: KotlinNativeTargetPreset - get() = getByName(::linuxX64.name) as KotlinNativeTargetPreset - -internal val NamedDomainObjectCollection>.mingwX64: KotlinNativeTargetPreset - get() = getByName(::mingwX64.name) as KotlinNativeTargetPreset - -internal val NamedDomainObjectContainer>.main: KotlinNativeCompilation - get() = getByName(::main.name) as KotlinNativeCompilation diff --git a/samples/buildSrc/src/main/kotlin/MPPTools.kt b/samples/buildSrc/src/main/kotlin/MPPTools.kt deleted file mode 100644 index 2dc0659cff5..00000000000 --- a/samples/buildSrc/src/main/kotlin/MPPTools.kt +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license - * that can be found in the license/LICENSE.txt file. - */ - -@file:JvmName("MPPTools") - -import groovy.lang.Closure -import org.gradle.api.Project -import org.gradle.api.Task -import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget -import org.jetbrains.kotlin.gradle.plugin.KotlinTargetPreset -import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTargetPreset -import org.jetbrains.kotlin.konan.target.KonanTarget -import java.nio.file.Paths - -/* - * This file includes short-cuts that may potentially be implemented in Kotlin MPP Gradle plugin in the future. - */ - -// Short-cuts for detecting the host OS. -@get:JvmName("isMacos") -val isMacos by lazy { hostOs == "Mac OS X" } - -@get:JvmName("isWindows") -val isWindows by lazy { hostOs.startsWith("Windows") } - -@get:JvmName("isLinux") -val isLinux by lazy { hostOs == "Linux" } - -// Short-cuts for mostly used paths. -@JvmOverloads -fun mingwPath(preset: KotlinNativeTargetPreset? = null) = when (preset?.konanTarget) { - null, is KonanTarget.MINGW_X64 -> mingwX64Path - is KonanTarget.MINGW_X86 -> mingwX86Path - else -> error("Not a MinGW preset: $preset") -} - -@get:JvmName("kotlinNativeDataPath") -val kotlinNativeDataPath by lazy { - System.getenv("KONAN_DATA_DIR") ?: Paths.get(userHome, ".konan").toString() -} - -// A short-cut for evaluation of the default host Kotlin/Native preset. -@JvmOverloads -fun defaultHostPreset( - subproject: Project, - whitelist: List> = with(subproject.kotlin.presets) { listOf(macosX64, linuxX64, mingwX64) } -): KotlinTargetPreset<*> { - - if (whitelist.isEmpty()) - throw Exception("Preset whitelist must not be empty in Kotlin/Native ${subproject.displayName}.") - - val presetCandidate = with(subproject.kotlin.presets) { - when { - isMacos -> macosX64 - isLinux -> linuxX64 - isWindows -> mingwX64 - else -> null - } - } - - return if (presetCandidate != null && presetCandidate in whitelist) - presetCandidate - else - throw Exception("Host OS '$hostOs' is not supported in Kotlin/Native ${subproject.displayName}.") -} diff --git a/samples/coverage/build.gradle.kts b/samples/coverage/build.gradle.kts index 8e23ae4968c..7d418bea020 100644 --- a/samples/coverage/build.gradle.kts +++ b/samples/coverage/build.gradle.kts @@ -1,7 +1,7 @@ import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget plugins { - id("org.jetbrains.kotlin.multiplatform") + kotlin("multiplatform") } kotlin { @@ -24,9 +24,7 @@ kotlin { executable(listOf(DEBUG)) } binaries.getExecutable("test", DEBUG).apply { - freeCompilerArgs = mutableListOf( - "-Xlibrary-to-cover=${compilations["main"].output.classesDirs.singleFile.absolutePath}" - ) + freeCompilerArgs.add("-Xlibrary-to-cover=${compilations["main"].output.classesDirs.singleFile.absolutePath}") } } } diff --git a/samples/csvparser/build.gradle b/samples/csvparser/build.gradle deleted file mode 100644 index 798da67f738..00000000000 --- a/samples/csvparser/build.gradle +++ /dev/null @@ -1,17 +0,0 @@ -plugins { - id 'kotlin-multiplatform' -} - -// Determine host preset. -def hostPreset = MPPTools.defaultHostPreset(project) - -kotlin { - targetFromPreset(hostPreset, 'csvParser') { - binaries { - executable() { - entryPoint = 'sample.csvparser.main' - runTask?.args './European_Mammals_Red_List_Nov_2009.csv', 4, 100 - } - } - } -} \ No newline at end of file diff --git a/samples/csvparser/build.gradle.kts b/samples/csvparser/build.gradle.kts new file mode 100644 index 00000000000..0be263ea749 --- /dev/null +++ b/samples/csvparser/build.gradle.kts @@ -0,0 +1,28 @@ +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") { + binaries { + executable { + entryPoint = "sample.csvparser.main" + runTask?.args("./European_Mammals_Red_List_Nov_2009.csv", 4, 100) + } + } + } +} \ No newline at end of file diff --git a/samples/curl/build.gradle b/samples/curl/build.gradle deleted file mode 100644 index dbfddc0d9e3..00000000000 --- a/samples/curl/build.gradle +++ /dev/null @@ -1,57 +0,0 @@ -plugins { - id 'kotlin-multiplatform' -} - -def localRepo = rootProject.file('build/.m2-local') - -repositories { - maven { url = "file://$localRepo" } -} - -// Determine host preset. -def hostPreset = MPPTools.defaultHostPreset(project, [kotlin.presets.macosX64, kotlin.presets.linuxX64, kotlin.presets.mingwX64]) - -kotlin { - targetFromPreset(hostPreset, 'curl') { - binaries { - executable() { - entryPoint = 'sample.curl.main' - if (presets.mingwX64 == hostPreset) { - // Add lib path to `libcurl` and its dependencies: - linkerOpts += ["-L${MPPTools.mingwPath()}/lib".toString()] - runTask?.environment('PATH': "${MPPTools.mingwPath()}/bin".toString()) - } - runTask?.args('https://www.jetbrains.com/') - } - } - } - - sourceSets { - curlMain { - dependencies { - implementation 'org.jetbrains.kotlin.sample.native:libcurl:1.0' - } - } - } -} - -// The code snippet below is needed to make all compile tasks depend on publication of -// "libcurl" library. So that to the time of compilation the library will already be -// in Maven repo and will be successfully resolved as a dependency of this project. -tasks.withType(AbstractCompile) { - dependsOn ':libcurl:publish' -} - -// The following snippet is needed to give instructions for IDEA user who just imported project -// and sees "Could not resolve..." message in IDEA console. -gradle.buildFinished { - String configurationName = kotlin.targets.curl.compilations.main.compileDependencyConfigurationName - Configuration configuration = project.configurations.getByName(configurationName) - if (configuration.canBeResolved && configuration.state == Configuration.State.RESOLVED_WITH_FAILURES) { - println( - "\nIMPORTANT:\n" + - "\tThe message about unresolved \"libcurl\" dependency likely means that \"libcurl\" has not been built and published to local Maven repo yet.\n" + - "\tPlease run \"publish\" task for \"libcurl\" sub-project and re-import Kotlin/Native samples in IDEA.\n" - ) - } -} diff --git a/samples/curl/build.gradle.kts b/samples/curl/build.gradle.kts new file mode 100644 index 00000000000..d8a1391ba3c --- /dev/null +++ b/samples/curl/build.gradle.kts @@ -0,0 +1,74 @@ +import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTargetPreset +import org.jetbrains.kotlin.konan.target.KonanTarget.* + +plugins { + kotlin("multiplatform") +} + +val localRepo = rootProject.file("build/.m2-local") + +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") { + binaries { + executable { + entryPoint = "sample.curl.main" + if (hostPreset.konanTarget == MINGW_X64) { + // Add lib path to `libcurl` and its dependencies: + linkerOpts(mingwPath.resolve("lib").toString()) + runTask?.environment("PATH" to mingwPath.resolve("bin")) + } + runTask?.args("https://www.jetbrains.com/") + } + } + } + + sourceSets { + val curlMain by getting { + dependencies { + implementation("org.jetbrains.kotlin.sample.native:libcurl:1.0") + } + } + } +} + +// The code snippet below is needed to make all compile tasks depend on publication of +// "libcurl" library. So that to the time of compilation the library will already be +// in Maven repo and will be successfully resolved as a dependency of this project. +tasks.withType(AbstractCompile::class) { + dependsOn(":libcurl:publish") +} + +// The following snippet is needed to give instructions for IDEA user who just imported project +// and sees "Could not resolve..." message in IDEA console. +gradle.buildFinished { + val configurationName = kotlin.targets["curl"].compilations["main"].compileDependencyConfigurationName + val configuration = project.configurations[configurationName] + if (configuration.isCanBeResolved && configuration.state == Configuration.State.RESOLVED_WITH_FAILURES) { + println( + """ + | + |IMPORTANT: + |The message about unresolved "libcurl" dependency likely means that "libcurl" has not been built and published to local Maven repo yet. + |Please run "publish" task for "libcurl" sub-project and re-import Kotlin/Native samples in IDEA. + """.trimMargin() + ) + } +} diff --git a/samples/echoServer/build.gradle b/samples/echoServer/build.gradle deleted file mode 100644 index 4f1c94e85a7..00000000000 --- a/samples/echoServer/build.gradle +++ /dev/null @@ -1,39 +0,0 @@ -plugins { - id 'kotlin-multiplatform' -} - -// Determine host preset. -def hostPreset = MPPTools.defaultHostPreset(project) - -// Add two additional presets for Raspberry Pi. -def raspberryPiPresets = [kotlin.presets.linuxArm32Hfp, kotlin.presets.linuxArm64] - -kotlin { - targetFromPreset(hostPreset, 'echoServer') { - binaries { - executable() { - entryPoint = 'sample.echoserver.main' - runTask?.args(3000) - } - } - } - - raspberryPiPresets.each { preset -> - def targetName = 'echoServer' + preset.name.capitalize() - targetFromPreset(preset, targetName) { - binaries { - executable() { - entryPoint = 'sample.echoserver.main' - runTask?.args(3000) - } - } - } - } - - sourceSets { - raspberryPiPresets.each { preset -> - String mainSourceSetName = 'echoServer' + preset.name.capitalize() + 'Main' - getByName(mainSourceSetName) dependsOn echoServerMain - } - } -} diff --git a/samples/echoServer/build.gradle.kts b/samples/echoServer/build.gradle.kts new file mode 100644 index 00000000000..6c7bb70230c --- /dev/null +++ b/samples/echoServer/build.gradle.kts @@ -0,0 +1,53 @@ +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 +} + +// Add two additional presets for Raspberry Pi. +val raspberryPiPresets: List = listOf("linuxArm32Hfp", "linuxArm64").map { + kotlin.presets[it] as KotlinNativeTargetPreset +} + +kotlin { + targetFromPreset(hostPreset, "echoServer") { + binaries { + executable { + entryPoint = "sample.echoserver.main" + runTask?.args(3000) + } + } + } + + 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 -> + val mainSourceSetName = "echoServer${preset.name.capitalize()}Main" + getByName(mainSourceSetName).dependsOn(echoServerMain) + } + } +} diff --git a/samples/gitchurn/build.gradle b/samples/gitchurn/build.gradle deleted file mode 100644 index 236e20d7aea..00000000000 --- a/samples/gitchurn/build.gradle +++ /dev/null @@ -1,36 +0,0 @@ -plugins { - id 'kotlin-multiplatform' -} - -// Determine host preset. -def hostPreset = MPPTools.defaultHostPreset(project) - -kotlin { - targetFromPreset(hostPreset, 'gitChurn') { - binaries { - executable() { - entryPoint = 'sample.gitchurn.main' - if (presets.mingwX64 == hostPreset) { - linkerOpts = ["-L${MPPTools.mingwPath()}/lib".toString()] - runTask?.environment('PATH', "${MPPTools.mingwPath()}/bin".toString()) - } - runTask?.args(project.getRootProject().getRootDir().toString() + '/..') - } - } - compilations.main.cinterops { - libgit2 { - switch (hostPreset) { - case presets.macosX64: - includeDirs.headerFilterOnly '/opt/local/include', '/usr/local/include' - break - case presets.linuxX64: - includeDirs.headerFilterOnly '/usr/include' - break - case presets.mingwX64: - includeDirs.headerFilterOnly "${MPPTools.mingwPath()}/include" - break - } - } - } - } -} diff --git a/samples/gitchurn/build.gradle.kts b/samples/gitchurn/build.gradle.kts new file mode 100644 index 00000000000..1c6a1d2577c --- /dev/null +++ b/samples/gitchurn/build.gradle.kts @@ -0,0 +1,44 @@ +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") { + binaries { + executable { + entryPoint = "sample.gitchurn.main" + if (hostPreset.konanTarget == MINGW_X64) { + linkerOpts(mingwPath.resolve("lib").toString()) + runTask?.environment("PATH" to mingwPath.resolve("bin")) + } + runTask?.args(rootProject.rootDir.resolve("..")) + } + } + 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")) + } + } + } + } +} diff --git a/samples/globalState/build.gradle b/samples/globalState/build.gradle deleted file mode 100644 index c151997839d..00000000000 --- a/samples/globalState/build.gradle +++ /dev/null @@ -1,19 +0,0 @@ -plugins { - id 'kotlin-multiplatform' -} - -// Determine host preset. -def hostPreset = MPPTools.defaultHostPreset(project) - -kotlin { - targetFromPreset(hostPreset, 'globalState') { - binaries { - executable() { - entryPoint = 'sample.globalstate.main' - } - } - compilations.main.cinterops { - global - } - } -} \ No newline at end of file diff --git a/samples/globalState/build.gradle.kts b/samples/globalState/build.gradle.kts new file mode 100644 index 00000000000..e7cc821fd2a --- /dev/null +++ b/samples/globalState/build.gradle.kts @@ -0,0 +1,30 @@ +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, "globalState") { + binaries { + executable { + entryPoint = "sample.globalstate.main" + } + } + compilations["main"].cinterops { + val global by creating + } + } +} diff --git a/samples/gtk/build.gradle b/samples/gtk/build.gradle deleted file mode 100644 index e86bbe4007c..00000000000 --- a/samples/gtk/build.gradle +++ /dev/null @@ -1,52 +0,0 @@ -plugins { - id 'kotlin-multiplatform' -} - -// Determine host preset. -def hostPreset = MPPTools.defaultHostPreset(project) - -kotlin { - targetFromPreset(hostPreset, 'gtk') { - binaries { - executable() { - entryPoint = 'sample.gtk.main' - if (presets.mingwX64 == hostPreset) { - linkerOpts += ["-L${MPPTools.mingwPath()}/lib".toString()] - runTask?.environment('PATH', "${MPPTools.mingwPath()}/bin".toString()) - } - } - } - compilations.main.cinterops { - gtk3 { - switch (hostPreset) { - case presets.macosX64: - case presets.linuxX64: - ['/opt/local/include', - '/usr/include', - '/usr/local/include' - ].each { - includeDirs "$it/atk-1.0", - "$it/gdk-pixbuf-2.0", - "$it/cairo", - "$it/pango-1.0", - "$it/gtk-3.0", - "$it/glib-2.0" - } - includeDirs '/opt/local/lib/glib-2.0/include', - '/usr/lib/x86_64-linux-gnu/glib-2.0/include', - '/usr/local/lib/glib-2.0/include' - break - case presets.mingwX64: - includeDirs "${MPPTools.mingwPath()}/include/atk-1.0", - "${MPPTools.mingwPath()}/include/gdk-pixbuf-2.0", - "${MPPTools.mingwPath()}/include/cairo", - "${MPPTools.mingwPath()}/include/pango-1.0", - "${MPPTools.mingwPath()}/include/gtk-3.0", - "${MPPTools.mingwPath()}/include/glib-2.0", - "${MPPTools.mingwPath()}/lib/glib-2.0/include" - break - } - } - } - } -} \ No newline at end of file diff --git a/samples/gtk/build.gradle.kts b/samples/gtk/build.gradle.kts new file mode 100644 index 00000000000..de104bfcec8 --- /dev/null +++ b/samples/gtk/build.gradle.kts @@ -0,0 +1,71 @@ +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") { + binaries { + executable { + entryPoint = "sample.gtk.main" + if (hostPreset.konanTarget == MINGW_X64) { + 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 -> { + listOf("/opt/local/include", "/usr/include", "/usr/local/include").forEach { + includeDirs( + "$it/atk-1.0", + "$it/gdk-pixbuf-2.0", + "$it/cairo", + "$it/pango-1.0", + "$it/gtk-3.0", + "$it/glib-2.0" + ) + } + + includeDirs( + "/opt/local/lib/glib-2.0/include", + "/usr/lib/x86_64-linux-gnu/glib-2.0/include", + "/usr/local/lib/glib-2.0/include" + ) + } + MINGW_X64 -> { + listOf( + "/include/atk-1.0", + "/include/gdk-pixbuf-2.0", + "/include/cairo", + "/include/pango-1.0", + "/include/gtk-3.0", + "/include/glib-2.0", + "/lib/glib-2.0/include" + ).forEach { + includeDirs(mingwPath.resolve(it)) + } + } + } + } + } + } +} \ No newline at end of file diff --git a/samples/html5Canvas/build.gradle b/samples/html5Canvas/build.gradle deleted file mode 100644 index b26d2799f44..00000000000 --- a/samples/html5Canvas/build.gradle +++ /dev/null @@ -1,82 +0,0 @@ -import org.jetbrains.kotlin.gradle.dsl.KotlinJvmCompile -import org.jetbrains.kotlin.gradle.tasks.KotlinNativeCompile - -import java.nio.file.Paths - -plugins { - id 'kotlin-multiplatform' -} - -repositories { - jcenter() - maven { url 'https://dl.bintray.com/kotlin/ktor' } -} - -String packageName = 'kotlinx.interop.wasm.dom' -String jsinteropKlibFileName = Paths.get(buildDir.toString(), 'klib', "$packageName-jsinterop.klib").toString() - -kotlin { - targetFromPreset(presets.wasm32, 'html5Canvas') { - binaries { - executable() { - entryPoint = 'sample.html5canvas.main' - } - } - } - jvm('httpServer') - sourceSets { - html5CanvasMain { - dependencies { - implementation files(jsinteropKlibFileName) - } - } - httpServerMain { - dependencies { - implementation 'io.ktor:ktor-server-netty:1.2.1' - } - } - } -} - -task jsinterop(type: Exec) { - workingDir projectDir - def ext = MPPTools.isWindows() ? '.bat' : '' - def distributionPath = project.properties['org.jetbrains.kotlin.native.home'] as String - if (distributionPath != null) { - def jsinteropCommand = Paths.get(file(distributionPath).path, 'bin', "jsinterop$ext").toString() - - inputs.property('jsinteropCommand', jsinteropCommand) - inputs.property('jsinteropPackageName', packageName) - outputs.file(jsinteropKlibFileName) - - commandLine jsinteropCommand, - '-pkg', packageName, - '-o', jsinteropKlibFileName, - '-target', 'wasm32' - } else { - doFirst { - // Abort build execution if the distribution path isn't specified. - throw new GradleException("""\ - |Kotlin/Native distribution path must be specified to build the JavaScript interop. - |Use 'org.jetbrains.kotlin.native.home' project property to specify it. - """.stripMargin()) - } - } -} - -tasks.withType(KotlinNativeCompile).all { - dependsOn jsinterop -} - -// This is to run embedded HTTP server with Ktor: -task runProgram(type: JavaExec) { - dependsOn assemble - main = 'sample.html5canvas.httpserver.HttpServer' - classpath = files(kotlin.targets.httpServer.compilations.main.output) + kotlin.targets.httpServer.compilations.main.runtimeDependencyFiles - args projectDir -} - -tasks.withType(KotlinJvmCompile).all { - runProgram.dependsOn it - kotlinOptions.jvmTarget = '1.8' -} diff --git a/samples/html5Canvas/build.gradle.kts b/samples/html5Canvas/build.gradle.kts new file mode 100644 index 00000000000..a9d7bd4d7d4 --- /dev/null +++ b/samples/html5Canvas/build.gradle.kts @@ -0,0 +1,97 @@ +import org.jetbrains.kotlin.gradle.dsl.KotlinJvmCompile +import org.jetbrains.kotlin.gradle.targets.jvm.KotlinJvmTarget +import org.jetbrains.kotlin.gradle.tasks.KotlinNativeCompile + +plugins { + kotlin("multiplatform") +} + +repositories { + jcenter() + maven("https://dl.bintray.com/kotlin/ktor") +} + +val hostOs = System.getProperty("os.name") +val isWindows = hostOs.startsWith("Windows") + +val packageName = "kotlinx.interop.wasm.dom" +val jsinteropKlibFile = buildDir.resolve("klib").resolve("$packageName-jsinterop.klib") + +kotlin { + wasm32("html5Canvas") { + binaries { + executable { + entryPoint = "sample.html5canvas.main" + } + } + } + jvm("httpServer") + sourceSets { + val html5CanvasMain by getting { + dependencies { + implementation(files(jsinteropKlibFile)) + } + } + val httpServerMain by getting { + dependencies { + implementation("io.ktor:ktor-server-netty:1.2.1") + } + } + } +} + +val jsinterop by tasks.creating(Exec::class) { + workingDir = projectDir + + val ext = if (isWindows) ".bar" else "" + val distributionPath = project.properties["org.jetbrains.kotlin.native.home"] as String? + + if (distributionPath != null) { + val jsinteropCommand = file(distributionPath).resolve("bin").resolve("jsinterop$ext") + + inputs.property("jsinteropCommand", jsinteropCommand) + inputs.property("jsinteropPackageName", packageName) + outputs.file(jsinteropKlibFile) + + commandLine( + jsinteropCommand, + "-pkg", packageName, + "-o", jsinteropKlibFile, + "-target", "wasm32" + ) + } else { + doFirst { + // Abort build execution if the distribution path isn't specified. + throw GradleException( + """ + | + |Kotlin/Native distribution path must be specified to build the JavaScript interop. + |Use 'org.jetbrains.kotlin.native.home' project property to specify it. + """.trimMargin() + ) + } + } +} + +tasks.withType(KotlinNativeCompile::class).all { + dependsOn(jsinterop) +} + +val assemble by tasks.getting + +// This is to run embedded HTTP server with Ktor: +val runProgram by tasks.creating(JavaExec::class) { + dependsOn(assemble) + + val httpServer: KotlinJvmTarget by kotlin.targets + val httpServerMainCompilation = httpServer.compilations["main"] + + main = "sample.html5canvas.httpserver.HttpServer" + classpath = files(httpServerMainCompilation.output) + httpServerMainCompilation.runtimeDependencyFiles + args = listOf(projectDir.toString()) +} + +tasks.withType(KotlinJvmCompile::class).all { + runProgram.dependsOn(this) + kotlinOptions.jvmTarget = "1.8" +} diff --git a/samples/libcurl/build.gradle b/samples/libcurl/build.gradle deleted file mode 100644 index 99d386ed7c7..00000000000 --- a/samples/libcurl/build.gradle +++ /dev/null @@ -1,56 +0,0 @@ -import java.nio.file.Paths - -plugins { - id 'kotlin-multiplatform' - id 'maven-publish' -} - -group 'org.jetbrains.kotlin.sample.native' -version '1.0' - -def localRepo = rootProject.file('build/.m2-local') - -publishing { - repositories { - maven { url = "file://$localRepo" } - } -} - -task cleanLocalRepo(type: Delete) { - delete localRepo -} - -// Determine host preset. -def hostPreset = MPPTools.defaultHostPreset(project, [kotlin.presets.macosX64, kotlin.presets.linuxX64, kotlin.presets.mingwX64]) - -kotlin { - targets { - fromPreset(hostPreset, 'libcurl') { - compilations.main.cinterops { - libcurl { - switch (hostPreset) { - case presets.macosX64: - includeDirs.headerFilterOnly '/opt/local/include', '/usr/local/include' - break - case presets.linuxX64: - includeDirs.headerFilterOnly '/usr/include', '/usr/include/x86_64-linux-gnu' - break - case presets.mingwX64: - includeDirs.headerFilterOnly "${MPPTools.mingwPath()}/include" - break - } - } - } - - mavenPublication { - pom { - withXml { - def root = asNode() - root.appendNode('name', 'libcurl interop library') - root.appendNode('description', 'A library providing interoperability with host libcurl') - } - } - } - } - } -} diff --git a/samples/libcurl/build.gradle.kts b/samples/libcurl/build.gradle.kts new file mode 100644 index 00000000000..7618113d0fc --- /dev/null +++ b/samples/libcurl/build.gradle.kts @@ -0,0 +1,60 @@ +import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTargetPreset +import org.jetbrains.kotlin.konan.target.KonanTarget.* + +plugins { + kotlin("multiplatform") + `maven-publish` +} + +group = "org.jetbrains.kotlin.sample.native" +version = "1.0" + +val localRepo = rootProject.file("build/.m2-local") + +publishing { + repositories { + maven("file://$localRepo") + } +} + +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") { + 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")) + } + } + } + + mavenPublication { + pom { + withXml { + val root = asNode() + root.appendNode("name", "libcurl interop library") + root.appendNode("description", "A library providing interoperability with host libcurl") + } + } + } + } +} diff --git a/samples/nonBlockingEchoServer/build.gradle b/samples/nonBlockingEchoServer/build.gradle deleted file mode 100644 index 02238b836ed..00000000000 --- a/samples/nonBlockingEchoServer/build.gradle +++ /dev/null @@ -1,17 +0,0 @@ -plugins { - id 'kotlin-multiplatform' -} - -// Determine host preset. -def hostPreset = MPPTools.defaultHostPreset(project, [kotlin.presets.macosX64, kotlin.presets.linuxX64]) - -kotlin { - targetFromPreset(hostPreset, 'nonBlockingEchoServer') { - binaries { - executable() { - entryPoint = 'sample.nbechoserver.main' - runTask?.args(3000) - } - } - } -} \ No newline at end of file diff --git a/samples/nonBlockingEchoServer/build.gradle.kts b/samples/nonBlockingEchoServer/build.gradle.kts new file mode 100644 index 00000000000..60e4c06a994 --- /dev/null +++ b/samples/nonBlockingEchoServer/build.gradle.kts @@ -0,0 +1,28 @@ +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" + // Windows is not supported + else -> throw GradleException("Host OS '$hostOs' is not supported in Kotlin/Native $project.") +}.let { + kotlin.presets[it] as KotlinNativeTargetPreset +} + +kotlin { + targetFromPreset(hostPreset, "nonBlockingEchoServer") { + binaries { + executable { + entryPoint = "sample.nbechoserver.main" + runTask?.args(3000) + } + } + } +} \ No newline at end of file diff --git a/samples/objc/build.gradle b/samples/objc/build.gradle deleted file mode 100644 index 1af3f01110e..00000000000 --- a/samples/objc/build.gradle +++ /dev/null @@ -1,16 +0,0 @@ -plugins { - id 'kotlin-multiplatform' -} - -// Determine host preset. -def hostPreset = MPPTools.defaultHostPreset(project, [kotlin.presets.macosX64]) - -kotlin { - targetFromPreset(hostPreset, 'objc') { - binaries { - executable() { - entryPoint = 'sample.objc.main' - } - } - } -} \ No newline at end of file diff --git a/samples/objc/build.gradle.kts b/samples/objc/build.gradle.kts new file mode 100644 index 00000000000..6fb69738b9b --- /dev/null +++ b/samples/objc/build.gradle.kts @@ -0,0 +1,13 @@ +plugins { + kotlin("multiplatform") +} + +kotlin { + macosX64("objc") { + binaries { + executable { + entryPoint = "sample.objc.main" + } + } + } +} \ No newline at end of file diff --git a/samples/opengl/build.gradle b/samples/opengl/build.gradle deleted file mode 100644 index d1762bb0353..00000000000 --- a/samples/opengl/build.gradle +++ /dev/null @@ -1,16 +0,0 @@ -plugins { - id 'kotlin-multiplatform' -} - -// Determine host preset. -def hostPreset = MPPTools.defaultHostPreset(project, [kotlin.presets.macosX64]) - -kotlin { - targetFromPreset(hostPreset, 'opengl') { - binaries { - executable() { - entryPoint = 'sample.opengl.main' - } - } - } -} \ No newline at end of file diff --git a/samples/opengl/build.gradle.kts b/samples/opengl/build.gradle.kts new file mode 100644 index 00000000000..fbd3012308f --- /dev/null +++ b/samples/opengl/build.gradle.kts @@ -0,0 +1,13 @@ +plugins { + kotlin("multiplatform") +} + +kotlin { + macosX64("opengl") { + binaries { + executable { + entryPoint = "sample.opengl.main" + } + } + } +} \ No newline at end of file diff --git a/samples/settings.gradle b/samples/settings.gradle deleted file mode 100644 index c2940ca16c2..00000000000 --- a/samples/settings.gradle +++ /dev/null @@ -1,54 +0,0 @@ -pluginManagement { - resolutionStrategy { - eachPlugin { - if (requested.id.id == "kotlin-multiplatform") { - useModule("org.jetbrains.kotlin:kotlin-gradle-plugin:${requested.version}") - } - } - } - - repositories { - mavenCentral() - maven { url 'https://dl.bintray.com/kotlin/kotlin-dev' } - maven { url 'https://dl.bintray.com/kotlin/kotlin-eap' } - } -} - -enableFeaturePreview('GRADLE_METADATA') - -/* - * The following projects are only available for certain platforms. - * - * IMPORTANT: If a new sample doesn't include interop with third-party libraries, - * add it into the 'buildSamplesWithPlatfromLibs' task in the root build.gradle. - */ -if (MPPTools.isMacos() || MPPTools.isLinux() || MPPTools.isWindows()) { - include ':csvparser' - include ':curl' - include ':echoServer' - include ':gitchurn' - include ':globalState' - include ':gtk' - include ':html5Canvas' - include ':libcurl' - include ':tetris' - include ':videoplayer' - include ':workers' -} - -if (MPPTools.isMacos() || MPPTools.isLinux()) { - include ':nonBlockingEchoServer' - include ':tensorflow' - include ':torch' -} - -if (MPPTools.isMacos()) { - include ':objc' - include ':opengl' - include ':uikit' - include ':coverage' -} - -if (MPPTools.isWindows()) { - include ':win32' -} diff --git a/samples/settings.gradle.kts b/samples/settings.gradle.kts new file mode 100644 index 00000000000..f932a91617e --- /dev/null +++ b/samples/settings.gradle.kts @@ -0,0 +1,51 @@ +pluginManagement { + repositories { + mavenCentral() + maven("https://dl.bintray.com/kotlin/kotlin-dev") + maven("https://dl.bintray.com/kotlin/kotlin-eap") + } +} + +enableFeaturePreview("GRADLE_METADATA") + +val hostOs = System.getProperty("os.name") +val isMacos = hostOs == "Mac OS X" +val isLinux = hostOs == "Linux" +val isWindows = hostOs.startsWith("Windows") + +/* + * The following projects are only available for certain platforms. + * + * IMPORTANT: If a new sample doesn't include interop with third-party libraries, + * add it into the 'buildSamplesWithPlatfromLibs' task in the root build.gradle. + */ +if (isMacos || isLinux || isWindows) { + include(":csvparser") + include(":curl") + include(":echoServer") + include(":gitchurn") + include(":globalState") + include(":gtk") + include(":html5Canvas") + include(":libcurl") + include(":tetris") + include(":videoplayer") + include(":workers") +} + +if (isMacos || isLinux) { + include(":nonBlockingEchoServer") + include(":tensorflow") + include(":torch") +} + +if (isMacos) { + include(":objc") + include(":opengl") + include(":uikit") + include(":coverage") +} + +if (isWindows) { + include(":win32") +} \ No newline at end of file diff --git a/samples/tensorflow/build.gradle b/samples/tensorflow/build.gradle deleted file mode 100644 index bc13dafcb96..00000000000 --- a/samples/tensorflow/build.gradle +++ /dev/null @@ -1,32 +0,0 @@ -plugins { - id 'kotlin-multiplatform' -} - -def tensorflowHome = "${MPPTools.kotlinNativeDataPath()}/third-party/tensorflow" - -// Determine host preset. -def hostPreset = MPPTools.defaultHostPreset(project, [kotlin.presets.macosX64, kotlin.presets.linuxX64]) - -kotlin { - targetFromPreset(hostPreset, 'tensorflow') { - binaries { - executable() { - entryPoint = 'sample.tensorflow.main' - linkerOpts += ["-L$tensorflowHome/lib".toString(), '-ltensorflow'] - runTask?.environment('LD_LIBRARY_PATH', "$tensorflowHome/lib".toString()) - runTask?.environment('DYLD_LIBRARY_PATH', "$tensorflowHome/lib".toString()) - } - } - compilations.main.cinterops { - tensorflow { - includeDirs "$tensorflowHome/include" - } - } - } -} - -task downloadTensorflow(type: Exec) { - workingDir projectDir - commandLine './downloadTensorflow.sh' -} -tasks[kotlin.targets.tensorflow.compilations.main.cinterops.tensorflow.interopProcessingTaskName].dependsOn downloadTensorflow \ No newline at end of file diff --git a/samples/tensorflow/build.gradle.kts b/samples/tensorflow/build.gradle.kts new file mode 100644 index 00000000000..ef818470daf --- /dev/null +++ b/samples/tensorflow/build.gradle.kts @@ -0,0 +1,51 @@ +import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget +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" + // Windows is not supported + else -> throw GradleException("Host OS '$hostOs' is not supported in Kotlin/Native $project.") +}.let { + kotlin.presets[it] as KotlinNativeTargetPreset +} + +val kotlinNativeDataPath = System.getenv("KONAN_DATA_DIR")?.let { File(it) } + ?: File(System.getProperty("user.home")).resolve(".konan") + +val tensorflowHome = kotlinNativeDataPath.resolve("third-party/tensorflow") + +kotlin { + targetFromPreset(hostPreset, "tensorflow") { + binaries { + executable { + entryPoint = "sample.tensorflow.main" + linkerOpts("-L${tensorflowHome.resolve("lib")}", "-ltensorflow") + runTask?.environment( + "LD_LIBRARY_PATH" to tensorflowHome.resolve("lib"), + "DYLD_LIBRARY_PATH" to tensorflowHome.resolve("lib") + ) + } + } + compilations["main"].cinterops { + val tensorflow by creating { + includeDirs(tensorflowHome.resolve("/include")) + } + } + } +} + +val downloadTensorflow by tasks.creating(Exec::class) { + workingDir = projectDir + commandLine("./downloadTensorflow.sh") +} + +val tensorflow: KotlinNativeTarget by kotlin.targets +tasks[tensorflow.compilations["main"].cinterops["tensorflow"].interopProcessingTaskName].dependsOn(downloadTensorflow) diff --git a/samples/tetris/build.gradle b/samples/tetris/build.gradle deleted file mode 100644 index 2d304806b55..00000000000 --- a/samples/tetris/build.gradle +++ /dev/null @@ -1,134 +0,0 @@ -plugins { - id 'kotlin-multiplatform' -} - -File winCompiledResourceFile = file("$buildDir/compiledWindowsResources/Tetris.res") -def hostPreset = determinePreset() - -kotlin { - targetFromPreset(hostPreset, 'tetris') { - binaries { - executable() { - entryPoint = 'sample.tetris.main' - switch (hostPreset) { - case presets.macosX64: - linkerOpts += ['-L/opt/local/lib', '-L/usr/local/lib', '-lSDL2'] - break - case presets.linuxX64: - linkerOpts += ['-L/usr/lib64', '-L/usr/lib/x86_64-linux-gnu', '-lSDL2'] - break - case presets.mingwX86: - case presets.mingwX64: - linkerOpts += [winCompiledResourceFile.path, - "-L${MPPTools.mingwPath(hostPreset)}/lib".toString(), - '-Wl,-Bstatic', - '-lstdc++', - '-static', - '-lSDL2', - '-limm32', - '-lole32', - '-loleaut32', - '-lversion', - '-lwinmm', - '-lsetupapi', - '-mwindows'] - break - case presets.linuxArm32Hfp: - linkerOpts += ['-lSDL2'] - break - } - runTask?.workingDir(project.provider { - kotlin.targets.tetris.binaries.getExecutable(buildType).outputDirectory - }) - } - } - - compilations.main.cinterops { - sdl { - switch (hostPreset) { - case presets.macosX64: - includeDirs '/opt/local/include/SDL2', '/usr/local/include/SDL2' - break - case presets.linuxX64: - includeDirs '/usr/include/SDL2' - break - case presets.mingwX86: - case presets.mingwX64: - includeDirs "${MPPTools.mingwPath(hostPreset)}/include/SDL2" - break - case presets.linuxArm32Hfp: - includeDirs "${MPPTools.kotlinNativeDataPath()}/dependencies/target-sysroot-1-raspberrypi/usr/include/SDL2" - break - } - } - } - } -} - -if ((hostPreset == kotlin.presets.mingwX86) || (hostPreset == kotlin.presets.mingwX64)) { - tasks.create('compileWindowsResources', Exec) { - def windresDir = null - if (hostPreset == kotlin.presets.mingwX86) - windresDir = "${MPPTools.kotlinNativeDataPath()}/dependencies/msys2-mingw-w64-i686-gcc-7.4.0-clang-llvm-6.0.1/bin" - else - windresDir = "${MPPTools.kotlinNativeDataPath()}/dependencies/msys2-mingw-w64-x86_64-gcc-7.3.0-clang-llvm-lld-6.0.1-2/bin" - assert windresDir != null - - def winResourceFile = kotlin.sourceSets.tetrisMain.resources.files.find { it.name == 'Tetris.rc' } - def path = System.getenv('PATH') - - commandLine "$windresDir/windres", winResourceFile, '-O', 'coff', '-o', winCompiledResourceFile - environment 'PATH', "$windresDir;$path" - - inputs.file winResourceFile - outputs.file winCompiledResourceFile - } -} - -afterEvaluate { - kotlin.targets.tetris.compilations.main { mainCompilation -> - def linkTasks = ['RELEASE', 'DEBUG'] - .collect { kotlin.targets.tetris.binaries.getExecutable(it).linkTask } - .findAll { it != null } - - def compileWindowsResourcesTask = tasks.findByName('compileWindowsResources') - - linkTasks.each { task -> - if (compileWindowsResourcesTask != null) - task.dependsOn compileWindowsResourcesTask - - task.doLast { - copy { - from kotlin.sourceSets.tetrisMain.resources - into task.outputFile.get().parentFile - exclude '*.rc' - } - } - } - } -} - -private def determinePreset() { - def preset = null - if (isRaspberryPiBuild()) { - preset = kotlin.presets.linuxArm32Hfp // aka RaspberryPi - } else if (isMingwX86Build()) { - preset = kotlin.presets.mingwX86 - } else { - preset = MPPTools.defaultHostPreset(project) - } - assert preset != null - - println("$project has been configured for ${preset.name} platform.") - preset -} - -// If host platform is Linux and RaspberryPi target is activated. -private boolean isRaspberryPiBuild() { - MPPTools.isLinux() && Boolean.parseBoolean(project.findProperty('tetris.raspberrypi.build') as String) -} - -// If host platform is Windows and x86 target is activated. -private boolean isMingwX86Build() { - MPPTools.isWindows() && Boolean.parseBoolean(project.findProperty('tetris.mingwX86.build') as String) -} diff --git a/samples/tetris/build.gradle.kts b/samples/tetris/build.gradle.kts new file mode 100644 index 00000000000..51c7c39ce1c --- /dev/null +++ b/samples/tetris/build.gradle.kts @@ -0,0 +1,135 @@ +import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget +import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTargetPreset +import org.jetbrains.kotlin.gradle.plugin.mpp.NativeBuildType +import org.jetbrains.kotlin.konan.target.KonanTarget.* + +plugins { + kotlin("multiplatform") +} + +val hostOs = System.getProperty("os.name") +val isLinux = hostOs == "Linux" +val isWindows = hostOs.startsWith("Windows") + +// If host platform is Linux and RaspberryPi target is activated. +val isRaspberryPiBuild = + isLinux && project.findProperty("tetris.raspberrypi.build")?.toString()?.toBoolean() == true + +// If host platform is Windows and x86 target is activated. +val isMingwX86Build = + isWindows && project.findProperty("tetris.mingwX86.build")?.toString()?.toBoolean() == true + +val hostPreset = determinePreset() + +val winCompiledResourceFile = buildDir.resolve("compiledWindowsResources/Tetris.res") + +val kotlinNativeDataPath = System.getenv("KONAN_DATA_DIR")?.let { File(it) } + ?: File(System.getProperty("user.home")).resolve(".konan") + +val mingwPath = if (isMingwX86Build) + File(System.getenv("MINGW32_DIR") ?: "C:/msys32/mingw32") +else + File(System.getenv("MINGW64_DIR") ?: "C:/msys64/mingw64") + +kotlin { + targetFromPreset(hostPreset, "tetris") { + binaries { + executable { + entryPoint = "sample.tetris.main" + when (hostPreset.konanTarget) { + MACOS_X64 -> linkerOpts("-L/opt/local/lib", "-L/usr/local/lib", "-lSDL2") + LINUX_X64 -> linkerOpts("-L/usr/lib64", "-L/usr/lib/x86_64-linux-gnu", "-lSDL2") + MINGW_X64, MINGW_X86 -> linkerOpts( + winCompiledResourceFile.toString(), + mingwPath.resolve("lib").toString(), + "-Wl,-Bstatic", + "-lstdc++", + "-static", + "-lSDL2", + "-limm32", + "-lole32", + "-loleaut32", + "-lversion", + "-lwinmm", + "-lsetupapi", + "-mwindows" + ) + LINUX_ARM32_HFP -> linkerOpts("-lSDL2") + } + runTask?.workingDir(project.provider { + val tetris: KotlinNativeTarget by kotlin.targets + tetris.binaries.getExecutable(buildType).outputDirectory + }) + } + } + + compilations["main"].cinterops { + val sdl by creating { + when (hostPreset.konanTarget) { + MACOS_X64 -> includeDirs("/opt/local/include/SDL2", "/usr/local/include/SDL2") + LINUX_X64 -> includeDirs("/usr/include/SDL2") + MINGW_X64, MINGW_X86 -> includeDirs(mingwPath.resolve("/include/SDL2")) + LINUX_ARM32_HFP -> includeDirs(kotlinNativeDataPath.resolve("dependencies/target-sysroot-1-raspberrypi/usr/include/SDL2")) + } + } + } + } +} + +val compileWindowsResources: Exec? = if (hostPreset.konanTarget == MINGW_X64 || hostPreset.konanTarget == MINGW_X86) { + val compileWindowsResources: Exec by tasks.creating(Exec::class) { + val windresDir = if (isMingwX86Build) + kotlinNativeDataPath.resolve("dependencies/msys2-mingw-w64-i686-gcc-7.4.0-clang-llvm-6.0.1/bin") + else + kotlinNativeDataPath.resolve("dependencies/msys2-mingw-w64-x86_64-gcc-7.3.0-clang-llvm-lld-6.0.1-2/bin") + + val winResourceFile = kotlin.sourceSets["tetrisMain"].resources.files.first { it.name == "Tetris.rc" } + val path = System.getenv("PATH") + + commandLine( + windresDir.resolve("windres"), + winResourceFile, + "-O", "coff", + "-o", winCompiledResourceFile + ) + environment("PATH" to "$windresDir;$path") + + inputs.file(winResourceFile) + outputs.file(winCompiledResourceFile) + } + + compileWindowsResources +} else null + +afterEvaluate { + val tetris: KotlinNativeTarget by kotlin.targets + val linkTasks = NativeBuildType.values().mapNotNull { tetris.binaries.getExecutable(it).linkTask } + + linkTasks.forEach { linkTask -> + if (compileWindowsResources != null) linkTask.dependsOn(compileWindowsResources) + linkTask.doLast { + copy { + from(kotlin.sourceSets["tetrisMain"].resources) + into(linkTask.outputFile.get().parentFile) + exclude("*.rc") + } + } + } +} + +fun determinePreset(): KotlinNativeTargetPreset { + val preset = when { + isRaspberryPiBuild -> kotlin.presets["linuxArm32Hfp"] as KotlinNativeTargetPreset // aka RaspberryPi + isMingwX86Build -> kotlin.presets["mingwX86"] as KotlinNativeTargetPreset + else -> return 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 + } + } + println("$project has been configured for ${preset.name} platform.") + return preset +} diff --git a/samples/torch/build.gradle b/samples/torch/build.gradle deleted file mode 100644 index c465f91cb14..00000000000 --- a/samples/torch/build.gradle +++ /dev/null @@ -1,38 +0,0 @@ -plugins { - id 'kotlin-multiplatform' -} - -def torchHome = "${MPPTools.kotlinNativeDataPath()}/third-party/torch" - -// Determine host preset. -def hostPreset = MPPTools.defaultHostPreset(project, [kotlin.presets.macosX64, kotlin.presets.linuxX64]) - -kotlin { - targetFromPreset(hostPreset, 'torch') { - binaries { - executable() { - entryPoint = 'sample.torch.main' - linkerOpts += ["-L$torchHome/lib".toString(), '-lATen'] - runTask?.dependsOn 'downloadMNIST' - runTask?.environment('LD_LIBRARY_PATH', "$torchHome/lib".toString()) - runTask?.environment('DYLD_LIBRARY_PATH', "$torchHome/lib".toString()) - } - } - compilations.main.cinterops { - torch { - includeDirs "$torchHome/include", "$torchHome/include/TH" - } - } - } -} - -task downloadTorch(type: Exec) { - workingDir projectDir - commandLine './downloadTorch.sh' -} -tasks[kotlin.targets.torch.compilations.main.cinterops.torch.interopProcessingTaskName].dependsOn downloadTorch - -task downloadMNIST(type: Exec) { - workingDir projectDir - commandLine './downloadMNIST.sh' -} \ No newline at end of file diff --git a/samples/torch/build.gradle.kts b/samples/torch/build.gradle.kts new file mode 100644 index 00000000000..754478eda0c --- /dev/null +++ b/samples/torch/build.gradle.kts @@ -0,0 +1,64 @@ +import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget +import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTargetPreset +import org.jetbrains.kotlin.gradle.plugin.mpp.NativeBuildType + +plugins { + kotlin("multiplatform") +} + +val kotlinNativeDataPath = System.getenv("KONAN_DATA_DIR")?.let { File(it) } + ?: File(System.getProperty("user.home")).resolve(".konan") + +val torchHome = kotlinNativeDataPath.resolve("third-party/torch") + +// Determine host preset. +val hostOs = System.getProperty("os.name") + +val hostPreset: KotlinNativeTargetPreset = when { + hostOs == "Mac OS X" -> "macosX64" + hostOs == "Linux" -> "linuxX64" + // Windows is not supported + else -> throw GradleException("Host OS '$hostOs' is not supported in Kotlin/Native $project.") +}.let { + kotlin.presets[it] as KotlinNativeTargetPreset +} + +kotlin { + targetFromPreset(hostPreset, "torch") { + binaries { + executable { + entryPoint = "sample.torch.main" + linkerOpts("-L${torchHome.resolve("lib")}", "-lATen") + runTask?.environment( + "LD_LIBRARY_PATH" to torchHome.resolve("lib"), + "DYLD_LIBRARY_PATH" to torchHome.resolve("lib") + ) + } + } + compilations["main"].cinterops { + val torch by creating { + includeDirs( + torchHome.resolve("/include"), + torchHome.resolve("/include/TH") + ) + } + } + } +} + +val downloadTorch by tasks.creating(Exec::class) { + workingDir = projectDir + commandLine("./downloadTorch.sh") +} + +val torch: KotlinNativeTarget by kotlin.targets +tasks[torch.compilations["main"].cinterops["torch"].interopProcessingTaskName].dependsOn(downloadTorch) + +val downloadMNIST by tasks.creating(Exec::class) { + workingDir = projectDir + commandLine("./downloadMNIST.sh") +} + +NativeBuildType.values() + .mapNotNull { torch.binaries.getExecutable(it).runTask } + .forEach { runTask -> runTask.dependsOn(downloadMNIST) } diff --git a/samples/videoplayer/build.gradle b/samples/videoplayer/build.gradle deleted file mode 100644 index 218fe03c42c..00000000000 --- a/samples/videoplayer/build.gradle +++ /dev/null @@ -1,57 +0,0 @@ -plugins { - id 'kotlin-multiplatform' -} - -// Determine host preset. -def hostPreset = MPPTools.defaultHostPreset(project, [kotlin.presets.macosX64, kotlin.presets.linuxX64, kotlin.presets.mingwX64]) - -kotlin { - targetFromPreset(hostPreset, 'videoPlayer') { - binaries { - executable() { - entryPoint = 'sample.videoplayer.main' - - switch (hostPreset) { - case presets.macosX64: - linkerOpts += ['-L/opt/local/lib', '-L/usr/local/lib'] - break - case presets.linuxX64: - linkerOpts += ['-L/usr/lib/x86_64-linux-gnu', '-L/usr/lib64'] - break - case presets.mingwX64: - linkerOpts += ["-L${MPPTools.mingwPath()}/lib".toString()] - break - } - } - } - - compilations.main.cinterops { - ffmpeg { - switch (hostPreset) { - case presets.macosX64: - includeDirs.headerFilterOnly '/opt/local/include', '/usr/local/include' - break - case presets.linuxX64: - includeDirs.headerFilterOnly '/usr/include', '/usr/include/x86_64-linux-gnu', '/usr/include/ffmpeg' - break - case presets.mingwX64: - includeDirs "${MPPTools.mingwPath()}/include" - break - } - } - sdl { - switch (hostPreset) { - case presets.macosX64: - includeDirs '/opt/local/include/SDL2', '/usr/local/include/SDL2' - break - case presets.linuxX64: - includeDirs '/usr/include/SDL2' - break - case presets.mingwX64: - includeDirs "${MPPTools.mingwPath()}/include/SDL2" - break - } - } - } - } -} diff --git a/samples/videoplayer/build.gradle.kts b/samples/videoplayer/build.gradle.kts new file mode 100644 index 00000000000..95e9329b3b8 --- /dev/null +++ b/samples/videoplayer/build.gradle.kts @@ -0,0 +1,53 @@ +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, "videoPlayer") { + binaries { + executable { + entryPoint = "sample.videoplayer.main" + + when (hostPreset.konanTarget) { + MACOS_X64 -> linkerOpts("-L/opt/local/lib", "-L/usr/local/lib") + LINUX_X64 -> linkerOpts("-L/usr/lib/x86_64-linux-gnu", "-L/usr/lib64") + MINGW_X64 -> linkerOpts(mingwPath.resolve("lib").toString()) + } + } + } + + compilations["main"].cinterops { + val ffmpeg 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", "/usr/include/ffmpeg") + MINGW_X64 -> includeDirs(mingwPath.resolve("/include")) + } + } + val sdl by creating { + when (hostPreset.konanTarget) { + MACOS_X64 -> includeDirs("/opt/local/include/SDL2", "/usr/local/include/SDL2") + LINUX_X64 -> includeDirs("/usr/include/SDL2") + MINGW_X64 -> includeDirs(mingwPath.resolve("/include/SDL2")) + } + } + } + } +} diff --git a/samples/win32/build.gradle b/samples/win32/build.gradle deleted file mode 100644 index 64fcdf94681..00000000000 --- a/samples/win32/build.gradle +++ /dev/null @@ -1,17 +0,0 @@ -plugins { - id 'kotlin-multiplatform' -} - -// Determine host preset. -def hostPreset = MPPTools.defaultHostPreset(project, [kotlin.presets.mingwX64]) - -kotlin { - targetFromPreset(hostPreset, 'win32') { - binaries { - executable() { - entryPoint = 'sample.win32.main' - linkerOpts += ['-Wl,--subsystem,windows'] - } - } - } -} diff --git a/samples/win32/build.gradle.kts b/samples/win32/build.gradle.kts new file mode 100644 index 00000000000..f938185f3f7 --- /dev/null +++ b/samples/win32/build.gradle.kts @@ -0,0 +1,14 @@ +plugins { + kotlin("multiplatform") +} + +kotlin { + mingwX64("win32") { + binaries { + executable { + entryPoint = "sample.win32.main" + linkerOpts("-Wl,--subsystem,windows") + } + } + } +} diff --git a/samples/workers/build.gradle b/samples/workers/build.gradle deleted file mode 100644 index 0edb7d56cbd..00000000000 --- a/samples/workers/build.gradle +++ /dev/null @@ -1,16 +0,0 @@ -plugins { - id 'kotlin-multiplatform' -} - -// Determine host preset. -def hostPreset = MPPTools.defaultHostPreset(project) - -kotlin { - targetFromPreset(hostPreset, 'workers') { - binaries { - executable() { - entryPoint = 'sample.workers.main' - } - } - } -} \ No newline at end of file diff --git a/samples/workers/build.gradle.kts b/samples/workers/build.gradle.kts new file mode 100644 index 00000000000..f9ec6224f7f --- /dev/null +++ b/samples/workers/build.gradle.kts @@ -0,0 +1,27 @@ +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, "workers") { + binaries { + executable { + entryPoint = "sample.workers.main" + } + } + } +} \ No newline at end of file