From e491ef45c436daa5c802646112e72445611f8487 Mon Sep 17 00:00:00 2001 From: Ilya Matveev Date: Wed, 29 Aug 2018 23:38:23 +0700 Subject: [PATCH] [samples] Switch to the new DSL in some samples --- samples/build.gradle | 14 +-- samples/csvparser/README.md | 11 +- samples/csvparser/build.gradle | 6 +- samples/curl/README.md | 11 +- samples/curl/build.gradle | 27 ++--- samples/curl/gradle.properties | 3 +- samples/curl/src/main/kotlin/main.kt | 24 +++- .../main/kotlin/org/konan/libcurl/Program.kt | 23 ---- samples/gitchurn/README.md | 11 +- samples/gitchurn/build.gradle | 28 +++-- samples/gitchurn/gradle.properties | 1 - samples/globalState/README.md | 4 +- samples/globalState/build.gradle | 19 ++- samples/gtk/README.md | 8 +- samples/gtk/build.gradle | 26 ++--- samples/gtk/gradle.properties | 1 + samples/libcurl/README.md | 2 +- samples/libcurl/build.gradle | 52 ++++----- samples/libcurl/gradle.properties | 1 - .../src/main/kotlin/org/konan/libcurl/CUrl.kt | 0 .../main/kotlin/org/konan/libcurl/Event.kt | 0 samples/nonBlockingEchoServer/README.md | 13 +-- samples/nonBlockingEchoServer/build.gradle | 12 +- samples/objc/build.gradle | 10 +- samples/opengl/README.md | 10 +- samples/opengl/build.gradle | 11 +- samples/socket/README.md | 11 +- samples/socket/build.gradle | 7 +- samples/socket/gradle.properties | 1 - samples/tetris/README.md | 20 +--- samples/tetris/build.gradle | 110 +++++++++--------- samples/videoplayer/README.md | 4 +- samples/videoplayer/build.gradle | 86 +++++++------- samples/win32/README.md | 4 +- samples/win32/build.gradle | 10 +- samples/workers/README.md | 4 +- samples/workers/build.gradle | 6 +- 37 files changed, 256 insertions(+), 335 deletions(-) delete mode 100644 samples/curl/src/main/kotlin/org/konan/libcurl/Program.kt delete mode 100644 samples/gitchurn/gradle.properties create mode 100644 samples/gtk/gradle.properties delete mode 100644 samples/libcurl/gradle.properties rename samples/{curl => libcurl}/src/main/kotlin/org/konan/libcurl/CUrl.kt (100%) rename samples/{curl => libcurl}/src/main/kotlin/org/konan/libcurl/Event.kt (100%) delete mode 100644 samples/socket/gradle.properties diff --git a/samples/build.gradle b/samples/build.gradle index f4ff483ec79..1885277bf2c 100644 --- a/samples/build.gradle +++ b/samples/build.gradle @@ -1,15 +1,11 @@ subprojects { buildscript { repositories { - maven { - url 'https://cache-redirector.jetbrains.com/maven-central' - } - maven { - url "https://dl.bintray.com/jetbrains/kotlin-native-dependencies" - } - maven { - url "https://teamcity.jetbrains.com/guestAuth/app/rest/builds/buildType:(id:Kotlin_13M1_Compiler),number:1.3-M1-eap-77,branch:default:any/artifacts/content/maven/" - } + maven { url 'https://cache-redirector.jetbrains.com/maven-central' } + maven { url "https://dl.bintray.com/jetbrains/kotlin-native-dependencies" } + maven { + url "https://teamcity.jetbrains.com/guestAuth/app/rest/builds/buildType:(id:Kotlin_13M1_Compiler),number:1.3-M1-eap-77,branch:default:any/artifacts/content/maven/" + } } dependencies { diff --git a/samples/csvparser/README.md b/samples/csvparser/README.md index 78a87932afc..1987f9e8015 100644 --- a/samples/csvparser/README.md +++ b/samples/csvparser/README.md @@ -4,16 +4,11 @@ A sample data [European Mammals Red List for 2009](https://data.europa.eu/euodp/en/data/dataset?res_format=CSV) from EU is being used. -To build use `../gradlew build` or `./build.sh`. +To build use `../gradlew assemble` or `./build.sh`. -To run use `../gradlew run` +Now you can run artifact directly -To change run arguments, change property runArgs in gradle.propeties file -or pass `-PrunArgs="./European_Mammals_Red_List_Nov_2009.csv 4 100"` to gradle run. - -Alternatively you can run artifact directly - - ./build/konan/bin//CsvParser.kexe ./European_Mammals_Red_List_Nov_2009.csv 4 100 + ./build/exe/main/release/csvparser.kexe ./European_Mammals_Red_List_Nov_2009.csv 4 100 It will print number of all unique entries in fifth column (Family, zero-based index) in first 100 rows of the CSV file. diff --git a/samples/csvparser/build.gradle b/samples/csvparser/build.gradle index a21d21c6e13..dc821bd5983 100644 --- a/samples/csvparser/build.gradle +++ b/samples/csvparser/build.gradle @@ -1,5 +1,5 @@ -apply plugin: 'konan' +apply plugin: 'org.jetbrains.kotlin.platform.native' -konanArtifacts { - program('CsvParser') +components.main { + outputKinds = [ EXECUTABLE ] } \ No newline at end of file diff --git a/samples/curl/README.md b/samples/curl/README.md index c5ef59155d4..632e68216a0 100644 --- a/samples/curl/README.md +++ b/samples/curl/README.md @@ -4,15 +4,10 @@ This example shows how to communicate with libcurl, HTTP/HTTPS/FTP/etc client li depend on an artifact published in a maven repository. The sample depends on a library built by [libcurl sample](../libcurl) so you need to run it first. -To build use `../gradlew build`. +To build use `../gradlew assemble`. -To run use `../gradlew run`. +Now you can run the client directly -To change run arguments, change property runArgs in gradle.propeties file -or pass `-PrunArgs="https://www.jetbrains.com"` to gradle run. - -Alternatively you can run artifact directly - - ./build/konan/bin//Curl.kexe https://www.jetbrains.com + ./build/exe/main/release//curl.kexe https://www.jetbrains.com It will perform HTTP get and print out the data obtained. diff --git a/samples/curl/build.gradle b/samples/curl/build.gradle index 73df93f247c..46d14c82524 100644 --- a/samples/curl/build.gradle +++ b/samples/curl/build.gradle @@ -1,14 +1,8 @@ buildscript { repositories { - maven { - url 'https://cache-redirector.jetbrains.com/maven-central' - } - maven { - url "https://dl.bintray.com/jetbrains/kotlin-native-dependencies" - } - maven { - url "https://teamcity.jetbrains.com/guestAuth/app/rest/builds/buildType:(id:Kotlin_13M1_Compiler),number:1.3-M1-eap-77,branch:default:any/artifacts/content/maven/" - } + maven { url 'https://cache-redirector.jetbrains.com/maven-central' } + maven { url "https://dl.bintray.com/jetbrains/kotlin-native-dependencies" } + maven { url "https://teamcity.jetbrains.com/guestAuth/app/rest/builds/buildType:(id:Kotlin_13M1_Compiler),number:1.3-M1-eap-77,branch:default:any/artifacts/content/maven/" } } dependencies { @@ -16,9 +10,7 @@ buildscript { } } -apply plugin: 'konan' - -konan.targets = ['macbook', 'linux'] +apply plugin: 'org.jetbrains.kotlin.platform.native' def localMavenRepo="file://${new File(System.properties['user.home'] as String)}/.m2-kotlin-native" @@ -28,10 +20,11 @@ repositories { } } -konanArtifacts { - program('Curl') { - dependencies { - artifactCurl 'org.jetbrains.kotlin.native:libcurl:1.0' - } +components.main { + targets = ['macos_x64', 'linux_x64'] + outputKinds = [ EXECUTABLE ] + + dependencies { + implementation 'org.jetbrains.kotlin.native:libcurl:1.0' } } diff --git a/samples/curl/gradle.properties b/samples/curl/gradle.properties index 8a869536226..cdb70994cf8 100644 --- a/samples/curl/gradle.properties +++ b/samples/curl/gradle.properties @@ -1,3 +1,2 @@ konan.home=../../dist -konan.plugin.version=+ -runArgs=https://www.jetbrains.com \ No newline at end of file +konan.plugin.version=+ \ No newline at end of file diff --git a/samples/curl/src/main/kotlin/main.kt b/samples/curl/src/main/kotlin/main.kt index 5c86e12e40b..12bfa7089b6 100644 --- a/samples/curl/src/main/kotlin/main.kt +++ b/samples/curl/src/main/kotlin/main.kt @@ -1,3 +1,23 @@ +import org.konan.libcurl.* + fun main(args: Array) { - org.konan.libcurl.main(args) -} \ No newline at end of file + if (args.size == 0) + return help() + + val curl = CUrl(args[0]) + curl.header += { + println("[H] $it") + } + + curl.body += { + println("[B] $it") + } + + curl.fetch() + curl.close() +} + +fun help() { + println("ERROR: missing URL command line argument") +} + diff --git a/samples/curl/src/main/kotlin/org/konan/libcurl/Program.kt b/samples/curl/src/main/kotlin/org/konan/libcurl/Program.kt deleted file mode 100644 index b89d6dadc0e..00000000000 --- a/samples/curl/src/main/kotlin/org/konan/libcurl/Program.kt +++ /dev/null @@ -1,23 +0,0 @@ -package org.konan.libcurl - -fun main(args: Array) { - if (args.size == 0) - return help() - - val curl = CUrl(args[0]) - curl.header += { - println("[H] $it") - } - - curl.body += { - println("[B] $it") - } - - curl.fetch() - curl.close() -} - -fun help() { - println("ERROR: missing URL command line argument") -} - diff --git a/samples/gitchurn/README.md b/samples/gitchurn/README.md index 684d4c9e18d..941e02cecd9 100644 --- a/samples/gitchurn/README.md +++ b/samples/gitchurn/README.md @@ -3,15 +3,10 @@ This example shows how one could perform statistics on Git repository. libgit2 is required for this to work (`apt-get install libgit2-dev`). -To build use `../gradlew build` or `./build.sh`. +To build use `../gradlew assemble` or `./build.sh`. -To run use `../gradlew run`. +Now you can run the program directly -To change run arguments, change property runArgs in gradle.propeties file -or pass `-PrunArgs="../../"` to gradle run. - -Alternatively you can run artifact directly - - ./build/konan/bin//GitChurn.kexe ../../ + ./build/exe/main/release//gitchurn.kexe ../../ It will print most frequently modified (by number of commits) files in repository. diff --git a/samples/gitchurn/build.gradle b/samples/gitchurn/build.gradle index 9e115e0244a..8c641fc2810 100644 --- a/samples/gitchurn/build.gradle +++ b/samples/gitchurn/build.gradle @@ -1,21 +1,19 @@ -apply plugin: 'konan' +apply plugin: 'org.jetbrains.kotlin.platform.native' -konan.targets = ['macbook', 'linux'] +components.main { + targets = ['macos_x64', 'linux_x64'] + outputKinds = [EXECUTABLE] -konanArtifacts { - interop('libgit2') { - target('linux') { - includeDirs.headerFilterOnly '/usr/include' - } + dependencies { + cinterop('libgit2') { + target('linux') { + includeDirs.headerFilterOnly '/usr/include' + } - target('macbook') { - includeDirs.headerFilterOnly '/opt/local/include', '/usr/local/include' - } - } - - program('GitChurn') { - libraries { - artifact 'libgit2' + target('macbook') { + includeDirs.headerFilterOnly '/opt/local/include', '/usr/local/include' + } } } } + diff --git a/samples/gitchurn/gradle.properties b/samples/gitchurn/gradle.properties deleted file mode 100644 index 04f83d41802..00000000000 --- a/samples/gitchurn/gradle.properties +++ /dev/null @@ -1 +0,0 @@ -runArgs=../../ \ No newline at end of file diff --git a/samples/globalState/README.md b/samples/globalState/README.md index 54c8eb5ca2f..fd8614482e7 100644 --- a/samples/globalState/README.md +++ b/samples/globalState/README.md @@ -2,8 +2,8 @@ This example shows how one could implement global shared state using interop mechanisms. -To build use `../gradlew build`. +To build use `../gradlew assemble`. -To run use `./build/konan/bin//Globals.exe`. +To run use `./build/exe/main/release//globalState.kexe`. diff --git a/samples/globalState/build.gradle b/samples/globalState/build.gradle index 094c8c62b9a..b2294ed5064 100644 --- a/samples/globalState/build.gradle +++ b/samples/globalState/build.gradle @@ -1,15 +1,10 @@ -apply plugin: 'konan' +apply plugin: 'org.jetbrains.kotlin.platform.native' -konan.targets = ['macbook', 'linux', 'mingw'] +components.main { + targets = ['macos_x64', 'linux_x64', 'mingw_x64'] + outputKinds = [EXECUTABLE] -konanArtifacts { - interop('global') { - defFile 'src/main/c_interop/global.def' + dependencies { + cinterop('global') } - - program('Globals') { - libraries { - artifact 'global' - } - } -} +} \ No newline at end of file diff --git a/samples/gtk/README.md b/samples/gtk/README.md index ea54adfcb74..f7dc2947f3a 100644 --- a/samples/gtk/README.md +++ b/samples/gtk/README.md @@ -3,18 +3,14 @@ This example shows how one may use _Kotlin/Native_ to build GUI applications with the GTK toolkit. -To build use `../gradlew build` or `./build.sh [-I=/include/path]`. +To build use `../gradlew assemble` or `./build.sh [-I=/include/path]`. Do not forget to install GTK3. See bellow. On Mac use `port install gtk3`, on Debian flavours of Linux - `apt-get install libgtk-3-dev`. To run on Mac also install XQuartz X server (https://www.xquartz.org/), and then - ../gradlew run - -Alternatively you can run artifact directly - - ./build/konan/bin//Gtk3Demo.kexe + ./build/exe/main/release//gtk.kexe Dialog box with the button will be shown, and application will print message and terminate on button click. diff --git a/samples/gtk/build.gradle b/samples/gtk/build.gradle index e702b8680b5..301d26268cd 100644 --- a/samples/gtk/build.gradle +++ b/samples/gtk/build.gradle @@ -1,23 +1,17 @@ -apply plugin: 'konan' - -konan { - targets = ['macbook', 'linux'] - jvmArgs = ['-Xmx8g'] -} +apply plugin: 'org.jetbrains.kotlin.platform.native' def includePrefixes = [ '/opt/local/include', '/usr/include', '/usr/local/include' ] -konanArtifacts { - interop('gtk3') { - includePrefixes.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' - } +components.main { + targets = ['macos_x64', 'linux_x64'] + outputKinds = [EXECUTABLE] - program('Gtk3Demo') { - libraries { - artifact 'gtk3' + dependencies { + cinterop('gtk3') { + includePrefixes.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' } } } diff --git a/samples/gtk/gradle.properties b/samples/gtk/gradle.properties new file mode 100644 index 00000000000..f1b71e7cdd7 --- /dev/null +++ b/samples/gtk/gradle.properties @@ -0,0 +1 @@ +konan.jvmArgs=-Xmx8g \ No newline at end of file diff --git a/samples/libcurl/README.md b/samples/libcurl/README.md index 16f32b87482..103dd69391b 100644 --- a/samples/libcurl/README.md +++ b/samples/libcurl/README.md @@ -4,7 +4,7 @@ This example shows how to build and publish an interop library to communicate wi HTTP/HTTPS/FTP/etc client library. Debian-like distros may need to `apt-get install libcurl4-openssl-dev`. -To build use `../gradlew build` +To build use `../gradlew assemble` To publish the library into a local repo use `../gradlew publish` diff --git a/samples/libcurl/build.gradle b/samples/libcurl/build.gradle index bc03c9ca71a..a6d61544200 100644 --- a/samples/libcurl/build.gradle +++ b/samples/libcurl/build.gradle @@ -1,29 +1,36 @@ -apply plugin: 'konan' - -konan.targets = ['macbook', 'linux'] +apply plugin: 'org.jetbrains.kotlin.platform.native' +apply plugin: 'maven-publish' group 'org.jetbrains.kotlin.native' version '1.0' -konanArtifacts { - interop('libcurl') { - target('linux') { - includeDirs.headerFilterOnly '/usr/include' - } - target('macbook') { - includeDirs.headerFilterOnly '/opt/local/include', '/usr/local/include' - } - pom { - withXml { - def root = asNode() - root.appendNode('name', 'libcurl interop library') - root.appendNode('description', 'A library providing interoperability with host libcurl') +// Native component +components.main { + targets = ['macos_x64', 'linux_x64'] + + dependencies { + cinterop('libcurl-interop') { + defFile 'src/main/c_interop/libcurl.def' + + target('linux_x64') { + includeDirs.headerFilterOnly '/usr/include' } + target('macos_x64') { + includeDirs.headerFilterOnly '/opt/local/include', '/usr/local/include' + } + } + } + + pom { + withXml { + def root = asNode() + root.appendNode('name', 'libcurl interop library') + root.appendNode('description', 'A library providing interoperability with host libcurl') } } } -apply plugin: 'maven-publish' +// Publishing def localMavenRepo="file://${new File(System.properties['user.home'] as String)}/.m2-kotlin-native" task cleanLocalRepo(type: Delete) { @@ -31,20 +38,9 @@ task cleanLocalRepo(type: Delete) { } publishing { - publications{ - libcurl(MavenPublication) { - artifact sourceJar{ - classifier "source" - } - } - } repositories { maven { url = localMavenRepo } } -} - -task sourceJar(type: Jar) { - from project.files('src/main') } \ No newline at end of file diff --git a/samples/libcurl/gradle.properties b/samples/libcurl/gradle.properties deleted file mode 100644 index 2e09d1407aa..00000000000 --- a/samples/libcurl/gradle.properties +++ /dev/null @@ -1 +0,0 @@ -runArgs=https://www.jetbrains.com \ No newline at end of file diff --git a/samples/curl/src/main/kotlin/org/konan/libcurl/CUrl.kt b/samples/libcurl/src/main/kotlin/org/konan/libcurl/CUrl.kt similarity index 100% rename from samples/curl/src/main/kotlin/org/konan/libcurl/CUrl.kt rename to samples/libcurl/src/main/kotlin/org/konan/libcurl/CUrl.kt diff --git a/samples/curl/src/main/kotlin/org/konan/libcurl/Event.kt b/samples/libcurl/src/main/kotlin/org/konan/libcurl/Event.kt similarity index 100% rename from samples/curl/src/main/kotlin/org/konan/libcurl/Event.kt rename to samples/libcurl/src/main/kotlin/org/konan/libcurl/Event.kt diff --git a/samples/nonBlockingEchoServer/README.md b/samples/nonBlockingEchoServer/README.md index 8d87106841f..bdcdbfb678b 100644 --- a/samples/nonBlockingEchoServer/README.md +++ b/samples/nonBlockingEchoServer/README.md @@ -7,18 +7,11 @@ are being suspended and resumed whenever relevant. Thus, while server can process multiple connections concurrently, each individual connection handler is written in simple linear manner. -To build use `../gradlew build` or `./build.sh`. +To build use `../gradlew assemble` or `./build.sh`. -Run the server: +Now you can run the server - ../gradlew run - -To change run arguments, change property runArgs in gradle.propeties file -or pass `-PrunArgs="3000"` to gradle run. - -Alternatively you can run artifact directly - - ./build/konan/bin//EchoServer.kexe 3000 & + ./build/exe/main/release//EchoServer.kexe 3000 & Test the server by connecting to it, for example with telnet: diff --git a/samples/nonBlockingEchoServer/build.gradle b/samples/nonBlockingEchoServer/build.gradle index 02ce7d0c852..ef9cd1bea8a 100644 --- a/samples/nonBlockingEchoServer/build.gradle +++ b/samples/nonBlockingEchoServer/build.gradle @@ -1,7 +1,7 @@ -apply plugin: 'konan' +apply plugin: 'org.jetbrains.kotlin.platform.native' -konan.targets = ['macbook', 'linux'] - -konanArtifacts { - program('EchoServer') -} +components.main { + targets = ['macos_x64', 'linux_x64'] + outputKinds = [EXECUTABLE] + baseName = 'EchoServer' +} \ No newline at end of file diff --git a/samples/objc/build.gradle b/samples/objc/build.gradle index 524e5ce07da..494053c23e0 100644 --- a/samples/objc/build.gradle +++ b/samples/objc/build.gradle @@ -1,7 +1,7 @@ -apply plugin: 'konan' +apply plugin: 'org.jetbrains.kotlin.platform.native' -konan.targets = ['macbook'] - -konanArtifacts { - program('Window') +components.main { + targets = ['macos_x64'] + outputKinds = [EXECUTABLE] + baseName = 'Window' } diff --git a/samples/opengl/README.md b/samples/opengl/README.md index a51b473c866..3e9bac9d8d5 100644 --- a/samples/opengl/README.md +++ b/samples/opengl/README.md @@ -1,15 +1,13 @@ # OpenGL application - This example shows interaction with OpenGL library, to render classical 3D test model. Linux build requires `apt-get install freeglut3-dev` or similar, +This example shows interaction with OpenGL library, to render classical 3D test model. Linux build requires `apt-get install freeglut3-dev` or similar, MacOS shall work as is. -To build use `../gradlew build` or `./build.sh`. +To build use `../gradlew assemble` or `./build.sh`. -To run use `../gradlew run` - -Alternatively you can run artifact directly +Now you can run the application - ./build/konan/bin//OpenGlTeapot.kexe + ./build/exe/main/release/OpenGlTeapot.kexe It will render 3D model of teapot. Feel free to experiment with it, the whole power of OpenGL is at your hands. diff --git a/samples/opengl/build.gradle b/samples/opengl/build.gradle index 453eabb0174..0847a1fce70 100644 --- a/samples/opengl/build.gradle +++ b/samples/opengl/build.gradle @@ -1,7 +1,8 @@ -apply plugin: 'konan' +apply plugin: 'org.jetbrains.kotlin.platform.native' -konan.targets = ["macbook"] - -konanArtifacts { - program('OpenGlTeapot') +components.main { + targets = ['macos_x64'] + outputKinds = [EXECUTABLE] + baseName = 'OpenGlTeapot' } + diff --git a/samples/socket/README.md b/samples/socket/README.md index 12a72f1ffe0..147122c5cb8 100644 --- a/samples/socket/README.md +++ b/samples/socket/README.md @@ -2,16 +2,9 @@ To build use `../gradlew build` or `./build.sh`. -Run the server: +Now you can run the server - ../gradlew run - -To change run arguments, change property runArgs in gradle.propeties file -or pass `-PrunArgs="3000"` to gradle run. - -Alternatively you can run artifact directly - - ./build/konan/bin//EchoServer.kexe 3000 & + ./build/exe/main/release/EchoServer.kexe 3000 & Test the server by conecting to it, for example with telnet: diff --git a/samples/socket/build.gradle b/samples/socket/build.gradle index 7499064f7cd..4765e0bab26 100644 --- a/samples/socket/build.gradle +++ b/samples/socket/build.gradle @@ -1,5 +1,6 @@ -apply plugin: 'konan' +apply plugin: 'org.jetbrains.kotlin.platform.native' -konanArtifacts { - program('EchoServer') +components.main { + outputKinds = [EXECUTABLE] + baseName = 'EchoServer' } diff --git a/samples/socket/gradle.properties b/samples/socket/gradle.properties deleted file mode 100644 index f0f9e55f899..00000000000 --- a/samples/socket/gradle.properties +++ /dev/null @@ -1 +0,0 @@ -runArgs=3000 \ No newline at end of file diff --git a/samples/tetris/README.md b/samples/tetris/README.md index 44818c02a2e..38237d4a7b2 100644 --- a/samples/tetris/README.md +++ b/samples/tetris/README.md @@ -13,28 +13,18 @@ use `apt-get install libsdl2-dev`. For Windows - `pacman -S mingw-w64-x86_64-SDL2` in MinGW64 console, if you do not have MSYS2-MinGW64 installed - install it first as described in http://www.msys2.org -To build Tetris application for your host platform (Mac or Linux) use `../gradlew build`. +To build Tetris application for your host platform (Mac or Linux) use `../gradlew assemble`. Aleternatively for Mac and Linux `./build.sh`. For Windows use `build.bat`. -This task builds the sample for your host platform. Note that SDL2 must be installed on the host. +Note that SDL2 must be installed on the host. -To run it on the host use `../gradlew run` - -Alternatively you can run artifact directly - - ./build/konan/bin/Tetris${target}/Tetris${target}.kexe - -For cross-compilation to iOS (on Mac host) use gradle property - - konan.build.targets=iphone - -For cross-compilation to Raspberry Pi (on Linux host) use - - konan.build.targets=raspberrypi +Now you can run the game + ./build/exe/main/release//tetris.[kexe|exe] + During build process compilation script creates interoperability bindings to SDL2, using SDL C headers, and then compiles an application with the produced bindings. diff --git a/samples/tetris/build.gradle b/samples/tetris/build.gradle index 5ab775ab87f..8682ad5ffa0 100644 --- a/samples/tetris/build.gradle +++ b/samples/tetris/build.gradle @@ -1,59 +1,63 @@ -apply plugin: 'konan' - -konan.targets = ['macbook', 'linux', 'raspberrypi', 'mingw'] +apply plugin: 'org.jetbrains.kotlin.platform.native' def konanUserDir = System.getenv("KONAN_DATA_DIR") ?: "${System.getProperty("user.home")}/.konan" def resFile = file("$buildDir/konan/res/Tetris.res") -konanArtifacts { +components.main { + targets = ['macos_x64', 'linux_x64', 'raspberrypi', 'mingw_x64'] + outputKinds = [EXECUTABLE] + baseName = 'tetris' - interop ('sdl') { - defFile 'src/main/c_interop/sdl.def' - packageName 'sdl' - - target 'macbook', { - includeDirs '/Library/Frameworks/SDL2.framework/Headers', - "${System.getProperty("user.home")}/Library/Frameworks/SDL2.framework/Headers", - '/opt/local/include/SDL2', - '/usr/local/include/SDL2' - } - - target 'linux', { - includeDirs '/usr/include/SDL2' - } - - target 'raspberrypi', { - includeDirs "$konanUserDir/dependencies/target-sysroot-1-raspberrypi/usr/include/SDL2" - } - - target 'mingw', { - includeDirs "${System.getenv("MINGW64_DIR")?:"c:/msys64/mingw64"}/include/SDL2" - } + target 'macbook', { + linkerOpts "-F ${System.getProperty("user.home")}/Library/Frameworks -F /Library/Frameworks -framework SDL2" + // Use this line instead of the previous one if you've got a 'No SDL-framework' error. + //linkerOpts "-L/opt/local/lib -L/usr/local/lib -lSDL2" } - program ('tetris') { - libraries { - artifact 'sdl' - } + target 'linux', { + linkerOpts '-L/usr/lib64 -L/usr/lib/x86_64-linux-gnu -lSDL2' + } - target 'macbook', { - linkerOpts "-F ${System.getProperty("user.home")}/Library/Frameworks -F /Library/Frameworks -framework SDL2" - // Use this line instead of the previous one if you've got a 'No SDL-framework' error. - //linkerOpts "-L/opt/local/lib -L/usr/local/lib -lSDL2" - } + target 'raspberrypi', { + linkerOpts '-lSDL2' + } - target 'linux', { - linkerOpts '-L/usr/lib64 -L/usr/lib/x86_64-linux-gnu -lSDL2' - } + target 'mingw', { + linkerOpts "$resFile -L${System.getenv("MINGW64_DIR")?:"c:/msys64/mingw64"}/lib -Wl,-Bstatic -lstdc++ -static -lSDL2 -limm32 -lole32 -loleaut32 -lversion -lwinmm -mwindows" + } - target 'raspberrypi', { - linkerOpts '-lSDL2' - } + dependencies { + cinterop('sdl') { + packageName 'sdl' + target 'macos_x64', { + includeDirs '/Library/Frameworks/SDL2.framework/Headers', + "${System.getProperty("user.home")}/Library/Frameworks/SDL2.framework/Headers", + '/opt/local/include/SDL2', + '/usr/local/include/SDL2' + } - target 'mingw', { - linkerOpts "$resFile -L${System.getenv("MINGW64_DIR")?:"c:/msys64/mingw64"}/lib -Wl,-Bstatic -lstdc++ -static -lSDL2 -limm32 -lole32 -loleaut32 -lversion -lwinmm -mwindows" - dependsOn 'windowsResources' - inputs.file resFile + target 'linux_x64', { + includeDirs '/usr/include/SDL2' + } + + target 'raspberrypi', { + includeDirs "$konanUserDir/dependencies/target-sysroot-1-raspberrypi/usr/include/SDL2" + } + + target 'mingw_x64', { + includeDirs "${System.getenv("MINGW64_DIR") ?: "c:/msys64/mingw64"}/include/SDL2" + } + } + } +} + +assemble { + doLast { + components.withType(KotlinNativeExecutable.class).all { binary -> + copy { + from 'src/main/resources' + into binary.runtimeFile.asFile.get().parentFile + } } } } @@ -71,13 +75,11 @@ task windowsResources (type: Exec) { outputs.file resFile } -compileKonan { - doLast { - konanArtifacts.tetris.forEach() { task -> - copy { - from 'src/main/resources' - into task.artifact.parentFile - } - } - } +project.tasks.matching { + name == 'compileDebugMingw_x64KotlinNative' || + name == 'compileReleaseMingw_x64KotlinNative' +}.all { + dependsOn 'windowsResources' + inputs.file resFile } + diff --git a/samples/videoplayer/README.md b/samples/videoplayer/README.md index 5e0059f5948..6e4c771fd71 100644 --- a/samples/videoplayer/README.md +++ b/samples/videoplayer/README.md @@ -11,8 +11,8 @@ ffmpeg and SDL2 is needed for that to work, i.e. apt install libsdl2-dev pacman -S mingw-w64-x86_64-SDL2 mingw-w64-x86_64-ffmpeg -To build use `../gradlew build`. +To build use `../gradlew assemble`. -To run use `./build/konan/bin//Player.kexe file.mp4`. +To run use `./build/exe/main/release//Player.kexe file.mp4`. diff --git a/samples/videoplayer/build.gradle b/samples/videoplayer/build.gradle index 5124800871a..128b9ed601f 100644 --- a/samples/videoplayer/build.gradle +++ b/samples/videoplayer/build.gradle @@ -1,60 +1,54 @@ -apply plugin: 'konan' +apply plugin: 'org.jetbrains.kotlin.platform.native' -konan.targets = ['macbook', 'linux', 'mingw'] +components.main { + targets = ['macos_x64', 'linux_x64', 'mingw_x64'] + outputKinds = [EXECUTABLE] + baseName = 'Player' -konanArtifacts { - interop('ffmpeg') { - defFile 'src/main/c_interop/ffmpeg.def' + dependencies { + cinterop('ffmpeg') { + target 'macos_x64', { + includeDirs.headerFilterOnly '/opt/local/include', '/usr/local/include' + } - target 'linux', { - includeDirs.headerFilterOnly '/usr/include', '/usr/include/x86_64-linux-gnu', '/usr/include/ffmpeg' + target 'linux_x64', { + includeDirs.headerFilterOnly '/usr/include', '/usr/include/x86_64-linux-gnu', '/usr/include/ffmpeg' + } + + target 'mingw_x64', { + includeDirs 'C:/msys64/mingw64/include' + } } - target 'macbook', { - includeDirs.headerFilterOnly '/opt/local/include', '/usr/local/include' - } + cinterop ('sdl') { + target 'macos_x64', { + includeDirs '/Library/Frameworks/SDL2.framework/Headers', + "${System.getProperty("user.home")}/Library/Frameworks/SDL2.framework/Headers", + '/opt/local/include/SDL2', + '/usr/local/include/SDL2' + } - target 'mingw', { - includeDirs 'C:/msys64/mingw64/include' + target 'linux_x64', { + includeDirs '/usr/include/SDL2' + } + + target 'mingw_x64', { + includeDirs 'C:/msys64/mingw64/include/SDL2' + } } } - interop ('sdl') { - defFile 'src/main/c_interop/sdl.def' - - target 'macbook', { - includeDirs '/Library/Frameworks/SDL2.framework/Headers', - "${System.getProperty("user.home")}/Library/Frameworks/SDL2.framework/Headers", - '/opt/local/include/SDL2', - '/usr/local/include/SDL2' - } - - target 'linux', { - includeDirs '/usr/include/SDL2' - } - - target 'mingw', { - includeDirs 'C:/msys64/mingw64/include/SDL2' - } + target 'macos_x64', { + linkerOpts "-F ${System.getProperty("user.home")}/Library/Frameworks", "-F /Library/Frameworks", + "-L/opt/local/lib", "-L/usr/local/lib" } - program('Player') { - libraries { - artifact 'ffmpeg' - artifact 'sdl' - } + target 'linux_x64', { + linkerOpts '-L/usr/lib/x86_64-linux-gnu', '-L/usr/lib64' + } - target 'macbook', { - linkerOpts "-F ${System.getProperty("user.home")}/Library/Frameworks", "-F /Library/Frameworks", - "-L/opt/local/lib", "-L/usr/local/lib" - } - - target 'linux', { - linkerOpts '-L/usr/lib/x86_64-linux-gnu', '-L/usr/lib64' - } - - target 'mingw', { - linkerOpts '-LC:/msys64/mingw64/lib' - } + target 'mingw_x64', { + linkerOpts '-LC:/msys64/mingw64/lib' } } + diff --git a/samples/win32/README.md b/samples/win32/README.md index 3b8a29b9323..a7b86d6242f 100644 --- a/samples/win32/README.md +++ b/samples/win32/README.md @@ -1,5 +1,5 @@ # WIN32 Hello World -To build use `..\gradlew build` or `build.bat`. +To build use `..\gradlew assemble` or `build.bat`. -To run use `..\gradlew run` or `MessageBox.exe`. +To run use `.\build\exe\main\release\MessageBox.exe`. diff --git a/samples/win32/build.gradle b/samples/win32/build.gradle index 7a333c5762c..727b8c69b87 100644 --- a/samples/win32/build.gradle +++ b/samples/win32/build.gradle @@ -1,9 +1,11 @@ -apply plugin: 'konan' +apply plugin: 'org.jetbrains.kotlin.platform.native' -konan.targets = ['mingw'] +components.main { + targets = ['mingw_x64'] + outputKinds = [EXECUTABLE] + baseName = 'MessageBox' -konanArtifacts { - program('MessageBox') { + target('mingw_x64') { linkerOpts "-Wl,--subsystem,windows" } } diff --git a/samples/workers/README.md b/samples/workers/README.md index ab8ea65b515..85ab38fceee 100644 --- a/samples/workers/README.md +++ b/samples/workers/README.md @@ -34,6 +34,6 @@ Then it continues execution, and waits on future objects encapsulating the computation results. Afterwards, worker execution termination is requested with the `requestTermination()` operation. -To build use `./build.sh`. +To build use `./build.sh` or `./gradlew assemble` -To run use `./build/konan/bin/Worker.kexe` +To run use `./build/exe/main/release/workers.kexe` diff --git a/samples/workers/build.gradle b/samples/workers/build.gradle index 0cbbfa914ab..dc821bd5983 100644 --- a/samples/workers/build.gradle +++ b/samples/workers/build.gradle @@ -1,5 +1,5 @@ -apply plugin: 'konan' +apply plugin: 'org.jetbrains.kotlin.platform.native' -konanArtifacts { - program('Workers') +components.main { + outputKinds = [ EXECUTABLE ] } \ No newline at end of file