Kotlin/Native samples ported to MPP Gradle DSL (#2261)
@@ -4,6 +4,7 @@
|
||||
/dependencies/all
|
||||
dist
|
||||
kotlin-native-*.tar.gz
|
||||
kotlin-native-*.zip
|
||||
translator/src/test/kotlin/tests/*/linked
|
||||
out
|
||||
tmp
|
||||
|
||||
@@ -8,32 +8,9 @@ virtual machines are not desirable or possible (such as iOS, embedded targets),
|
||||
or where developer is willing to produce reasonably-sized self-contained program
|
||||
without need to ship an additional execution runtime.
|
||||
|
||||
To get started with _Kotlin/Native_ take a look at the attached samples.
|
||||
|
||||
* `androidNativeActivity` - Android Native Activity rendering 3D graphics using OpenGLES
|
||||
* `calculator` - iOS Swift application, using Kotlin/Native code compiled into the framework
|
||||
* `csvparser` - simple CSV file parser and analyzer
|
||||
* `gitchurn` - program interoperating with `libgit2` for GIT repository analysis
|
||||
* `gtk` - GTK2 interoperability example
|
||||
* `html5Canvas` - WebAssembly example
|
||||
* `libcurl` - using of FTP/HTTP/HTTPS client library `libcurl`
|
||||
* `nonBlockingEchoServer` - multi-client TCP/IP echo server using co-routines
|
||||
* `objc` - AppKit Objective-C interoperability example for macOS
|
||||
* `opengl` - OpenGL/GLUT teapot example
|
||||
* `python_extension` - Python extension written in Kotlin/Native
|
||||
* `socket` - TCP/IP echo server
|
||||
* `tensorflow` - simple client for TensorFlow Machine Intelligence library
|
||||
* `tetris` - Tetris game implementation (using SDL2 for rendering)
|
||||
* `uikit` - UIKit Objective-C interoperability example for iOS
|
||||
* `videoplayer` - SDL and FFMPEG-based video and audio player
|
||||
* `win32` - trivial Win32 GUI application
|
||||
* `workers` - example of using workers API
|
||||
|
||||
|
||||
See `README.md` in each sample directory for more information and build instructions.
|
||||
|
||||
_Kotlin/Native_ could be used either as standalone compiler toolchain or as Gradle
|
||||
plugin. See [`GRADLE_PLUGIN.md`](https://github.com/JetBrains/kotlin-native/blob/master/GRADLE_PLUGIN.md) for more details on how to use this plugin.
|
||||
plugin. See [documentation](https://kotlinlang.org/docs/reference/native/gradle_plugin.html)
|
||||
for more details on how to use this plugin.
|
||||
|
||||
Compile your programs like that:
|
||||
|
||||
@@ -45,10 +22,12 @@ For an optimized compilation use -opt:
|
||||
kotlinc hello.kt -o hello -opt
|
||||
|
||||
To generate interoperability stubs create library definition file
|
||||
(take a look on `samples/tetris/tetris.sdl`) and run `cinterop` tool like this:
|
||||
(take a look on [Tetris sample](samples/tetris))
|
||||
and run `cinterop` tool like this:
|
||||
|
||||
cinterop -def lib.def
|
||||
|
||||
See [`INTEROP.md`](https://github.com/JetBrains/kotlin-native/blob/master/INTEROP.md) for more information on how to use C libraries from _Kotlin/Native_.
|
||||
|
||||
See [C interop documentation](https://kotlinlang.org/docs/reference/native/c_interop.html)
|
||||
for more information on how to use C libraries from _Kotlin/Native_.
|
||||
|
||||
See [`RELEASE_NOTES.md`](https://github.com/JetBrains/kotlin-native/blob/master/RELEASE_NOTES.md) for information on supported platforms and current limitations.
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
### IMPORTANT NOTICE
|
||||
|
||||
This document describes Kotlin/Native experimental Gradle plugin, which is not the plugin yet supported by IDE
|
||||
or in multiplatform projects. See MPP Gradle plugin [documentation](https://kotlinlang.org/docs/reference/building-mpp-with-gradle.html
|
||||
or in multiplatform projects. See MPP Gradle plugin [documentation](https://kotlinlang.org/docs/reference/building-mpp-with-gradle.html)
|
||||
for more information.
|
||||
|
||||
### Overview
|
||||
|
||||
@@ -17,6 +17,7 @@ import groovy.io.FileType
|
||||
import org.jetbrains.kotlin.konan.target.*
|
||||
import org.jetbrains.kotlin.konan.properties.*
|
||||
import org.jetbrains.kotlin.konan.util.*
|
||||
import org.jetbrains.kotlin.CopySamples
|
||||
|
||||
buildscript {
|
||||
apply from: "gradle/kotlinGradlePlugin.gradle"
|
||||
@@ -390,35 +391,9 @@ task bundle(type: (isWindows()) ? Zip : Tar) {
|
||||
}
|
||||
from(project.rootDir) {
|
||||
include 'RELEASE_NOTES.md'
|
||||
include 'samples/**'
|
||||
exclude '**/gradle.properties'
|
||||
exclude '**/settings.gradle'
|
||||
exclude '**/build'
|
||||
exclude '**/.gradle'
|
||||
exclude 'samples/**/*.kt.bc-build'
|
||||
into baseName
|
||||
}
|
||||
|
||||
from(project.file("samples")) {
|
||||
include '**/settings.gradle'
|
||||
into "$baseName/samples"
|
||||
filter { it.startsWith("includeBuild") ? null : it }
|
||||
}
|
||||
|
||||
from(project.file("samples")) {
|
||||
include '**/gradle.properties'
|
||||
into "$baseName/samples"
|
||||
filter {
|
||||
if (it.startsWith("konan.home=")) {
|
||||
return it.replace("/dist", "")
|
||||
}
|
||||
if (it.startsWith("konan.plugin.version=")) {
|
||||
return "konan.plugin.version=$gradlePluginVersion"
|
||||
}
|
||||
return it
|
||||
}
|
||||
}
|
||||
|
||||
destinationDir = file('.')
|
||||
if (!isWindows()) {
|
||||
extension = 'tar.gz'
|
||||
@@ -426,6 +401,45 @@ task bundle(type: (isWindows()) ? Zip : Tar) {
|
||||
}
|
||||
}
|
||||
|
||||
task samples {
|
||||
dependsOn 'samplesZip', 'samplesTar'
|
||||
}
|
||||
|
||||
task samplesZip(type: Zip)
|
||||
task samplesTar(type: Tar) {
|
||||
extension = 'tar.gz'
|
||||
compression = Compression.GZIP
|
||||
}
|
||||
|
||||
configure([samplesZip, samplesTar]) {
|
||||
baseName "kotlin-native-samples-$konanVersionFull"
|
||||
destinationDir = projectDir
|
||||
into(baseName)
|
||||
|
||||
from(file('samples')) {
|
||||
// Process properties files separately.
|
||||
exclude '**/gradle.properties'
|
||||
}
|
||||
|
||||
from(file('samples')) {
|
||||
include '**/gradle.properties'
|
||||
filter {
|
||||
it.startsWith('org.jetbrains.kotlin.native.home=') || it.startsWith('# Use custom Kotlin/Native home:') ? null : it
|
||||
}
|
||||
}
|
||||
|
||||
// Exclude build artifacts.
|
||||
exclude '**/build'
|
||||
exclude '**/.gradle'
|
||||
exclude '**/.idea'
|
||||
exclude '**/*.kt.bc-build/'
|
||||
}
|
||||
|
||||
task copy_samples(dependsOn: 'copySamples')
|
||||
task copySamples(type: CopySamples) {
|
||||
destinationDir file('build/samples-under-test')
|
||||
}
|
||||
|
||||
task uploadBundle {
|
||||
dependsOn ':bundle'
|
||||
doLast {
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
package org.jetbrains.kotlin
|
||||
|
||||
import groovy.lang.Closure
|
||||
import org.gradle.api.Task
|
||||
import org.gradle.api.tasks.Copy
|
||||
|
||||
/**
|
||||
* A task that copies samples and replaces direct repository URLs with ones provided by the cache-redirector service.
|
||||
*/
|
||||
open class CopySamples: Copy() {
|
||||
|
||||
var samplesDir = project.file("samples")
|
||||
|
||||
init {
|
||||
configureReplacements()
|
||||
}
|
||||
|
||||
fun samplesDir(path: Any) {
|
||||
samplesDir = project.file(path)
|
||||
}
|
||||
|
||||
private fun configureReplacements() {
|
||||
from(samplesDir) {
|
||||
it.exclude("**/*.gradle")
|
||||
}
|
||||
from(samplesDir) {
|
||||
it.include("**/*.gradle")
|
||||
it.filter { line ->
|
||||
replacements.forEach { (repo, replacement) ->
|
||||
if (line.contains(repo)) {
|
||||
return@filter line.replace(repo, replacement)
|
||||
}
|
||||
}
|
||||
return@filter line
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun configure(closure: Closure<Any>): Task {
|
||||
super.configure(closure)
|
||||
configureReplacements()
|
||||
return this
|
||||
}
|
||||
|
||||
companion object {
|
||||
val replacements = listOf(
|
||||
"mavenCentral()" to "maven { url 'https://cache-redirector.jetbrains.com/maven-central' }",
|
||||
"jcenter()" to "maven { url 'https://cache-redirector.jetbrains.com/jcenter' }",
|
||||
"https://dl.bintray.com/kotlin/kotlin-dev" to "https://cache-redirector.jetbrains.com/dl.bintray.com/kotlin/kotlin-dev",
|
||||
"https://dl.bintray.com/kotlin/kotlin-eap" to "https://cache-redirector.jetbrains.com/dl.bintray.com/kotlin/kotlin-eap",
|
||||
"https://dl.bintray.com/kotlin/ktor" to "https://cache-redirector.jetbrains.com/dl.bintray.com/kotlin/ktor",
|
||||
"https://plugins.gradle.org/m2" to "https://cache-redirector.jetbrains.com/plugins.gradle.org/m2"
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -1,22 +1,34 @@
|
||||
# Samples
|
||||
|
||||
This directory contains a set of samples demonstrating how one can work with Kotlin/Native. The samples can be
|
||||
built using either command line tools (via `build.sh` script presented in each sample directory) or using a gradle build.
|
||||
See `README.md` in sample directories to learn more about specific samples and the building process.
|
||||
built using Gradle build tool. See `README.md` in sample directories to learn more about specific samples and
|
||||
the building process.
|
||||
|
||||
**Note**: If the samples are built from a source tree (not from a distribution archive) the compiler and the gradle
|
||||
plugin built from the sources are used. So one must build the compiler by running `./gradlew cross_dist` from the
|
||||
Kotlin/Native root directory before building samples (see
|
||||
* `androidNativeActivity` - Android Native Activity rendering 3D graphics using OpenGLES
|
||||
* `calculator` - iOS Swift application, using Kotlin/Native code compiled into the framework
|
||||
* `csvparser` - simple CSV file parser and analyzer
|
||||
* `echoServer` - TCP/IP echo server
|
||||
* `gitchurn` - program interoperating with `libgit2` for GIT repository analysis
|
||||
* `gtk` - GTK2 interoperability example
|
||||
* `html5Canvas` - WebAssembly example
|
||||
* `libcurl` - using of FTP/HTTP/HTTPS client library `libcurl`
|
||||
* `nonBlockingEchoServer` - multi-client TCP/IP echo server using co-routines
|
||||
* `objc` - AppKit Objective-C interoperability example for macOS
|
||||
* `opengl` - OpenGL/GLUT teapot example
|
||||
* `python_extension` - Python extension written in Kotlin/Native
|
||||
* `tensorflow` - simple client for TensorFlow Machine Intelligence library
|
||||
* `tetris` - Tetris game implementation (using SDL2 for rendering)
|
||||
* `uikit` - UIKit Objective-C interoperability example for iOS
|
||||
* `videoplayer` - SDL and FFMPEG-based video and audio player
|
||||
* `win32` - trivial Win32 GUI application
|
||||
* `workers` - example of using workers API
|
||||
|
||||
|
||||
**Note**: If the samples are built from a source tree (not from a distribution archive) the compiler built from
|
||||
the sources is used. So one must build the compiler and the necessary platform libraries by running
|
||||
`./gradlew bundle` from the Kotlin/Native root directory before building samples (see
|
||||
[README.md](https://github.com/JetBrains/kotlin-native/blob/master/README.md) for details).
|
||||
|
||||
One may also build all the samples with one command. To build them using the command line tools run:
|
||||
One may also build all the samples with one command. To build them using Gradle run:
|
||||
|
||||
./build.sh
|
||||
|
||||
To build all the samples using the gradle build:
|
||||
|
||||
./gradlew build
|
||||
|
||||
One also may launch the command line build via a gradle task `buildSh` (equivalent of `./build.sh` executing):
|
||||
|
||||
./gradlew buildSh
|
||||
./gradlew buildAllSamples
|
||||
|
||||
@@ -1,15 +1,20 @@
|
||||
# Android Native Activity
|
||||
This example shows how to build an Android Native Activity. Also, we provide an example
|
||||
|
||||
This example shows how to build an Android Native Activity. Also, we provide an example
|
||||
bridging mechanism for the Java APIs, callable from Native side.
|
||||
|
||||
The example will render a textured dodecahedron using OpenGL ES library. It can be rotated with fingers.
|
||||
Please make sure that Android SDK version 25 is installed, using Android SDK manager in Android Studio.
|
||||
Please make sure that Android SDK version 28 is installed, using Android SDK manager in Android Studio.
|
||||
See https://developer.android.com/studio/index.html for more details on Android Studio or
|
||||
`$ANDROID_HOME/tools/bin/sdkmanager "platforms;android-25" "build-tools;25.0.2"` from command line.
|
||||
`$ANDROID_HOME/tools/bin/sdkmanager "platforms;android-28" "build-tools;28.0.3"` from command line.
|
||||
We use JniBridge to call vibration service on the Java side for short tremble on startup.
|
||||
|
||||
To build use `ANDROID_HOME=<your path to android sdk> ../gradlew build`.
|
||||
To build use `ANDROID_HOME=<your path to android sdk> ../gradlew assemble`.
|
||||
|
||||
Run `$ANDROID_HOME/platform-tools/adb install -r build/outputs/apk/debug/androidNativeActivity-debug.apk`
|
||||
to deploy the apk on the Android device or emulator (note that only ARM-based devices are currently supported).
|
||||
|
||||
Note: If you are importing project to IDEA for the first time, you might need to put `local.properties` file
|
||||
with the following content:
|
||||
|
||||
sdk.dir=<your path to Android SDK>
|
||||
|
||||
@@ -1,85 +1,100 @@
|
||||
buildscript {
|
||||
repositories {
|
||||
google()
|
||||
jcenter()
|
||||
mavenCentral()
|
||||
google()
|
||||
maven {
|
||||
url "https://dl.bintray.com/jetbrains/kotlin-native-dependencies"
|
||||
}
|
||||
maven { url 'https://dl.bintray.com/kotlin/kotlin-dev' }
|
||||
maven { url 'https://dl.bintray.com/kotlin/kotlin-eap' }
|
||||
}
|
||||
|
||||
dependencies {
|
||||
classpath "org.jetbrains.kotlin:kotlin-native-gradle-plugin:${project.property('konan.plugin.version')}"
|
||||
classpath 'com.android.tools.build:gradle:3.1.2'
|
||||
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
|
||||
classpath 'com.android.tools.build:gradle:3.2.1'
|
||||
}
|
||||
}
|
||||
|
||||
repositories {
|
||||
jcenter()
|
||||
google()
|
||||
jcenter()
|
||||
mavenCentral()
|
||||
maven { url 'https://dl.bintray.com/kotlin/kotlin-dev' }
|
||||
maven { url 'https://dl.bintray.com/kotlin/kotlin-eap' }
|
||||
}
|
||||
|
||||
apply plugin: 'konan'
|
||||
apply plugin: 'org.jetbrains.kotlin.multiplatform'
|
||||
apply plugin: 'com.android.application'
|
||||
|
||||
konan.targets = ['android_arm32', 'android_arm64']
|
||||
|
||||
def outDir = file('Polyhedron')
|
||||
def libsDir = file("$outDir/libs")
|
||||
def platforms = [
|
||||
"armeabi-v7a": [konanTarget: "android_arm32"],
|
||||
"arm64-v8a" : [konanTarget: "android_arm64"]
|
||||
def appDir = file("$buildDir/Polyhedron")
|
||||
def libsDir = file("$appDir/libs")
|
||||
Map<String, String> libsDirMapping = [
|
||||
'arm32' : "$libsDir/armeabi-v7a",
|
||||
'arm64' : "$libsDir/arm64-v8a"
|
||||
]
|
||||
|
||||
konanArtifacts {
|
||||
program('Polyhedron') {
|
||||
artifactName 'libpoly'
|
||||
}
|
||||
}
|
||||
|
||||
task copyLibs(type: Copy) {
|
||||
dependsOn konanArtifacts.Polyhedron
|
||||
destinationDir libsDir
|
||||
|
||||
platforms.each { name, platform ->
|
||||
into(name) {
|
||||
from konanArtifacts.Polyhedron."${platform.konanTarget}".artifact
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
task deleteOut(type: Delete) {
|
||||
delete outDir
|
||||
}
|
||||
|
||||
clean.dependsOn deleteOut
|
||||
|
||||
tasks.matching { it.name == 'preBuild' }.all {
|
||||
it.dependsOn copyLibs
|
||||
}
|
||||
|
||||
android {
|
||||
compileSdkVersion 25
|
||||
compileSdkVersion 28
|
||||
|
||||
defaultConfig {
|
||||
applicationId 'com.jetbrains.konan_activity2'
|
||||
minSdkVersion 9
|
||||
targetSdkVersion 25
|
||||
targetSdkVersion 28
|
||||
|
||||
ndk {
|
||||
abiFilters "armeabi-v7a", "arm64-v8a"
|
||||
abiFilters 'armeabi-v7a', 'arm64-v8a'
|
||||
}
|
||||
}
|
||||
|
||||
sourceSets {
|
||||
main {
|
||||
root 'src/arm32Main'
|
||||
jniLibs.srcDir libsDir
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
task buildApk(type: Copy) {
|
||||
dependsOn "assembleDebug"
|
||||
destinationDir outDir
|
||||
from 'build/outputs/apk'
|
||||
kotlin {
|
||||
targets {
|
||||
fromPreset(presets.androidNativeArm32, 'arm32')
|
||||
fromPreset(presets.androidNativeArm64, 'arm64')
|
||||
|
||||
configure([arm32, arm64]) {
|
||||
compilations.main.outputKinds 'EXECUTABLE'
|
||||
compilations.main.entryPoint 'sample.androidnative.main'
|
||||
compilations.main.cinterops {
|
||||
bmpformat
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
sourceSets {
|
||||
arm64Main.dependsOn arm32Main
|
||||
}
|
||||
}
|
||||
|
||||
// Disable generating Kotlin metadata.
|
||||
tasks.compileKotlinMetadata.enabled = false
|
||||
|
||||
afterEvaluate {
|
||||
kotlin.targets { targets ->
|
||||
[arm32, arm64].collect { target ->
|
||||
target.compilations.main { mainCompilation ->
|
||||
String buildType = 'RELEASE' // Change to 'DEBUG' to include debug symbols.
|
||||
Object linkTask = mainCompilation.getLinkTask('EXECUTABLE', buildType)
|
||||
|
||||
// Rename binary files to 'libpoly.so' and put them to the appropriate location.
|
||||
File binaryFile = linkTask.outputFile.get()
|
||||
linkTask.doLast {
|
||||
copy {
|
||||
from binaryFile
|
||||
into libsDirMapping[target.targetName]
|
||||
rename {
|
||||
'libpoly.so'
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
tasks.preBuild.dependsOn linkTask
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
DIR=$(cd "$(dirname "${BASH_SOURCE[0]}" )" && pwd )
|
||||
|
||||
$DIR/../gradlew -p $DIR assemble
|
||||
@@ -1,2 +1 @@
|
||||
konan.home=../../dist
|
||||
konan.plugin.version=+
|
||||
kotlin.code.style=official
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.2-all.zip
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-4.7-all.zip
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
||||
|
||||
@@ -1,2 +1,20 @@
|
||||
includeBuild '../../shared'
|
||||
includeBuild '../../tools/kotlin-native-gradle-plugin'
|
||||
// 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
|
||||
}
|
||||
}
|
||||
|
||||
|
Before Width: | Height: | Size: 48 KiB After Width: | Height: | Size: 48 KiB |
@@ -0,0 +1,7 @@
|
||||
package sample.androidnative
|
||||
|
||||
import kotlinx.cinterop.*
|
||||
import sample.androidnative.bmpformat.BMPHeader
|
||||
|
||||
val BMPHeader.data
|
||||
get() = (ptr.reinterpret<ByteVar>() + sizeOf<BMPHeader>()) as CArrayPointer<ByteVar>
|
||||
@@ -1,20 +1,9 @@
|
||||
/*
|
||||
* Copyright 2010-2018 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package NativeApplication
|
||||
package sample.androidnative
|
||||
|
||||
import kotlinx.cinterop.*
|
||||
|
||||
@@ -1,19 +1,9 @@
|
||||
/*
|
||||
* Copyright 2010-2018 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* 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.
|
||||
*/
|
||||
package NativeApplication
|
||||
|
||||
package sample.androidnative
|
||||
|
||||
import kotlinx.cinterop.*
|
||||
import platform.android.*
|
||||
@@ -1,19 +1,9 @@
|
||||
/*
|
||||
* Copyright 2010-2018 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* 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.
|
||||
*/
|
||||
package NativeApplication
|
||||
|
||||
package sample.androidnative
|
||||
|
||||
import kotlinx.cinterop.*
|
||||
import platform.android.*
|
||||
@@ -1,19 +1,9 @@
|
||||
/*
|
||||
* Copyright 2010-2018 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* 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.
|
||||
*/
|
||||
package NativeApplication
|
||||
|
||||
package sample.androidnative
|
||||
|
||||
const val Zero = 0.0f
|
||||
const val DodeA = 0.93417235896f // (Sqrt(5) + 1) / (2 * Sqrt(3))
|
||||
@@ -1,20 +1,9 @@
|
||||
/*
|
||||
* Copyright 2010-2018 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package NativeApplication
|
||||
package sample.androidnative
|
||||
|
||||
import kotlinx.cinterop.*
|
||||
import platform.android.*
|
||||
@@ -56,6 +45,7 @@ import platform.gles.glVertexPointer
|
||||
import platform.gles.glTexCoordPointer
|
||||
import platform.gles.glNormalPointer
|
||||
import platform.gles.GL_TEXTURE_ENV_COLOR
|
||||
import sample.androidnative.bmpformat.BMPHeader
|
||||
|
||||
class Renderer(val container: DisposableContainer,
|
||||
val nativeActivity: ANativeActivity,
|
||||
@@ -207,8 +197,9 @@ class Renderer(val container: DisposableContainer,
|
||||
if (AAsset_read(asset, buffer, length.convert()) != length.toInt()) {
|
||||
throw Error("Error reading asset")
|
||||
}
|
||||
with(BMPHeader(buffer.rawValue)) {
|
||||
if (magic != 0x4d42 || zero != 0 || size != length.toInt() || bits != 24) {
|
||||
|
||||
with(buffer.reinterpret<BMPHeader>().pointed) {
|
||||
if (magic != 0x4d42.toUShort() || zero != 0u || size != length.toUInt() || bits != 24.toUShort()) {
|
||||
throw Error("Error parsing texture file")
|
||||
}
|
||||
val numberOfBytes = width * height * 3
|
||||
@@ -1,19 +1,9 @@
|
||||
/*
|
||||
* Copyright 2010-2018 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* 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.
|
||||
*/
|
||||
package NativeApplication
|
||||
|
||||
package sample.androidnative
|
||||
|
||||
import kotlinx.cinterop.*
|
||||
import platform.android.*
|
||||
@@ -0,0 +1,24 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package sample.androidnative
|
||||
|
||||
import kotlinx.cinterop.*
|
||||
import platform.android.*
|
||||
|
||||
fun main() {
|
||||
logInfo("Entering main().")
|
||||
memScoped {
|
||||
val state = alloc<NativeActivityState>()
|
||||
getNativeActivityState(state.ptr)
|
||||
val engine = Engine(state)
|
||||
try {
|
||||
engine.mainLoop()
|
||||
} finally {
|
||||
engine.dispose()
|
||||
}
|
||||
}
|
||||
kotlin.system.exitProcess(0)
|
||||
}
|
||||
|
Before Width: | Height: | Size: 4.5 KiB After Width: | Height: | Size: 4.5 KiB |
|
Before Width: | Height: | Size: 2.4 KiB After Width: | Height: | Size: 2.4 KiB |
|
Before Width: | Height: | Size: 6.0 KiB After Width: | Height: | Size: 6.0 KiB |
|
Before Width: | Height: | Size: 12 KiB After Width: | Height: | Size: 12 KiB |
@@ -1,33 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2018 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package NativeApplication
|
||||
|
||||
import kotlinx.cinterop.*
|
||||
|
||||
internal class BMPHeader(val rawPtr: NativePtr) {
|
||||
inline fun <reified T : CPointed> memberAt(offset: Long): T {
|
||||
return interpretPointed<T>(this.rawPtr + offset)
|
||||
}
|
||||
|
||||
val magic get() = memberAt<ShortVar>(0).value.toInt()
|
||||
val size get() = memberAt<IntVar>(2).value
|
||||
val zero get() = memberAt<IntVar>(6).value
|
||||
val width get() = memberAt<IntVar>(18).value
|
||||
val height get() = memberAt<IntVar>(22).value
|
||||
val bits get() = memberAt<ShortVar>(28).value.toInt()
|
||||
val data get() = interpretCPointer<ByteVar>(rawPtr + 54) as CArrayPointer<ByteVar>
|
||||
}
|
||||
@@ -1,34 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2018 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import kotlinx.cinterop.*
|
||||
import platform.android.*
|
||||
import NativeApplication.*
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
logInfo("Entering main().")
|
||||
memScoped {
|
||||
val state = alloc<NativeActivityState>()
|
||||
getNativeActivityState(state.ptr)
|
||||
val engine = Engine(state)
|
||||
try {
|
||||
engine.mainLoop()
|
||||
} finally {
|
||||
engine.dispose()
|
||||
}
|
||||
}
|
||||
kotlin.system.exitProcess(0)
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package = sample.androidnative.bmpformat
|
||||
|
||||
---
|
||||
#include <stdint.h>
|
||||
|
||||
typedef struct __attribute__((packed)) {
|
||||
uint16_t magic;
|
||||
uint32_t size;
|
||||
uint32_t zero;
|
||||
uint8_t padding1[8];
|
||||
int32_t width;
|
||||
int32_t height;
|
||||
uint8_t padding2[2];
|
||||
uint16_t bits;
|
||||
uint8_t padding3[24];
|
||||
} BMPHeader;
|
||||
@@ -1,39 +1,59 @@
|
||||
subprojects {
|
||||
buildscript {
|
||||
repositories {
|
||||
maven {
|
||||
url 'https://cache-redirector.jetbrains.com/maven-central'
|
||||
}
|
||||
maven {
|
||||
url "https://dl.bintray.com/jetbrains/kotlin-native-dependencies"
|
||||
}
|
||||
}
|
||||
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-native-gradle-plugin:${project.property('konan.plugin.version')}"
|
||||
}
|
||||
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' }
|
||||
}
|
||||
}
|
||||
|
||||
task buildSh(type: Exec) {
|
||||
commandLine "${projectDir.canonicalPath}/build.sh"
|
||||
workingDir projectDir.canonicalPath
|
||||
errorOutput = System.out
|
||||
ignoreExitValue = true
|
||||
workingDir projectDir
|
||||
enabled = !MPPTools.isWindows()
|
||||
if (MPPTools.isLinux() || MPPTools.isMacos()) {
|
||||
commandLine "$projectDir/build.sh"
|
||||
}
|
||||
}
|
||||
|
||||
task buildSamplesWithPlatformLibs() {
|
||||
dependsOn ':csvparser:build'
|
||||
dependsOn ':nonBlockingEchoServer:build'
|
||||
dependsOn ':objc:build'
|
||||
dependsOn ':opengl:build'
|
||||
dependsOn ':socket:build'
|
||||
dependsOn ':uikit:build'
|
||||
dependsOn ':win32:build'
|
||||
dependsOn ':workers:build'
|
||||
dependsOn ':globalState:build'
|
||||
dependsOn ':csvparser: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'
|
||||
}
|
||||
|
||||
if (MPPTools.isWindows()) {
|
||||
dependsOn ':win32:assemble'
|
||||
}
|
||||
}
|
||||
|
||||
task buildAllSamples() {
|
||||
dependsOn buildSh
|
||||
subprojects.each {
|
||||
dependsOn("${it.path}:build")
|
||||
dependsOn("${it.path}:assemble")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
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'
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
// 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
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
* 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.gradle.api.plugins.ExtraPropertiesExtension
|
||||
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
|
||||
|
||||
/*
|
||||
* 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 Project.ext: ExtraPropertiesExtension
|
||||
get() = extensions.getByName("ext") as ExtraPropertiesExtension
|
||||
|
||||
internal val Project.kotlin: KotlinMultiplatformExtension
|
||||
get() = extensions.getByName("kotlin") as KotlinMultiplatformExtension
|
||||
|
||||
internal val NamedDomainObjectCollection<KotlinTargetPreset<*>>.macosX64: KotlinTargetPreset<*>
|
||||
get() = getByName(::macosX64.name) as KotlinTargetPreset<*>
|
||||
|
||||
internal val NamedDomainObjectCollection<KotlinTargetPreset<*>>.linuxX64: KotlinTargetPreset<*>
|
||||
get() = getByName(::linuxX64.name) as KotlinTargetPreset<*>
|
||||
|
||||
internal val NamedDomainObjectCollection<KotlinTargetPreset<*>>.mingwX64: KotlinTargetPreset<*>
|
||||
get() = getByName(::mingwX64.name) as KotlinTargetPreset<*>
|
||||
|
||||
internal val NamedDomainObjectContainer<out KotlinCompilation>.main: KotlinNativeCompilation
|
||||
get() = getByName(::main.name) as KotlinNativeCompilation
|
||||
@@ -0,0 +1,76 @@
|
||||
/*
|
||||
* 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.KotlinTarget
|
||||
import org.jetbrains.kotlin.gradle.plugin.KotlinTargetPreset
|
||||
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.
|
||||
@get:JvmName("mingwPath")
|
||||
val mingwPath by lazy { System.getenv("MINGW64_DIR") ?: "c:/msys64/mingw64" }
|
||||
|
||||
@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<KotlinTargetPreset<*>> = listOf(subproject.kotlin.presets.macosX64, subproject.kotlin.presets.linuxX64, subproject.kotlin.presets.mingwX64)
|
||||
): KotlinTargetPreset<*> {
|
||||
|
||||
if (whitelist.isEmpty())
|
||||
throw Exception("Preset whitelist must not be empty in Kotlin/Native ${subproject.displayName}.")
|
||||
|
||||
val presetCandidate = when {
|
||||
isMacos -> subproject.kotlin.presets.macosX64
|
||||
isLinux -> subproject.kotlin.presets.linuxX64
|
||||
isWindows -> subproject.kotlin.presets.mingwX64
|
||||
else -> null
|
||||
}
|
||||
|
||||
val preset = if (presetCandidate != null && presetCandidate in whitelist)
|
||||
presetCandidate
|
||||
else
|
||||
throw Exception("Host OS '$hostOs' is not supported in Kotlin/Native ${subproject.displayName}.")
|
||||
|
||||
subproject.ext.set("hostPreset", preset)
|
||||
|
||||
return preset
|
||||
}
|
||||
|
||||
// A short-cut to add a Kotlin/Native run task.
|
||||
@JvmOverloads
|
||||
fun createRunTask(
|
||||
subproject: Project,
|
||||
name: String,
|
||||
target: KotlinTarget,
|
||||
configureClosure: Closure<Any>? = null
|
||||
): Task {
|
||||
val task = subproject.tasks.create(name, RunKotlinNativeTask::class.java, target)
|
||||
task.configure(configureClosure ?: task.emptyConfigureClosure())
|
||||
return task
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
/*
|
||||
* 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 groovy.lang.Closure
|
||||
import org.gradle.api.DefaultTask
|
||||
import org.gradle.api.Task
|
||||
import org.gradle.api.tasks.TaskAction
|
||||
import org.jetbrains.kotlin.gradle.plugin.KotlinTarget
|
||||
import javax.inject.Inject
|
||||
|
||||
open class RunKotlinNativeTask @Inject constructor(
|
||||
private val myTarget: KotlinTarget
|
||||
): DefaultTask() {
|
||||
|
||||
var buildType = "RELEASE"
|
||||
var workingDir: Any = project.projectDir
|
||||
private var myArgs: List<String> = emptyList()
|
||||
private val myEnvironment: MutableMap<String, Any> = mutableMapOf()
|
||||
|
||||
fun args(vararg args: Any) {
|
||||
myArgs = args.map { it.toString() }
|
||||
}
|
||||
|
||||
fun environment(map: Map<String, Any>) {
|
||||
myEnvironment += map
|
||||
}
|
||||
|
||||
override fun configure(configureClosure: Closure<Any>): Task {
|
||||
val task = super.configure(configureClosure)
|
||||
this.dependsOn += myTarget.compilations.main.linkTaskName("EXECUTABLE", buildType)
|
||||
return task
|
||||
}
|
||||
|
||||
@TaskAction
|
||||
fun run() {
|
||||
project.exec {
|
||||
it.executable = myTarget.compilations.main.getBinary("EXECUTABLE", buildType).toString()
|
||||
it.args = myArgs
|
||||
it.environment = myEnvironment
|
||||
it.workingDir(workingDir)
|
||||
}
|
||||
}
|
||||
|
||||
internal fun emptyConfigureClosure() = object : Closure<Any>(this) {
|
||||
override fun call(): RunKotlinNativeTask {
|
||||
return this@RunKotlinNativeTask
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
xcuserdata
|
||||
@@ -1,10 +1,10 @@
|
||||
# Calculator sample
|
||||
|
||||
This example shows how to use Kotlin common module (located in [common/](common/)) in different environments.
|
||||
This example shows how to use Kotlin common module (located in [arithmeticParser](arithmeticParser/)) in different environments.
|
||||
Currently for
|
||||
* Android (see [android](android/))
|
||||
* iOS (see [ios/calculator](ios/calculator/))
|
||||
* plain JVM (cli) (see [jvm](jvm/))
|
||||
* Android (see [androidApp](androidApp/))
|
||||
* iOS (see [iosApp](iosApp/))
|
||||
* plain JVM (cli) (see [cliApp](cliApp/))
|
||||
|
||||
## Common
|
||||
|
||||
@@ -13,18 +13,26 @@ Common Kotlin module contains arithmetic expressions parser.
|
||||
## Android App
|
||||
The common module may be used in an Android application.
|
||||
|
||||
To build and run the Android sample do the following:
|
||||
Please make sure that Android SDK version 28 is installed, using Android SDK manager in Android Studio.
|
||||
See https://developer.android.com/studio/index.html for more details on Android Studio or
|
||||
`$ANDROID_HOME/tools/bin/sdkmanager "platforms;android-28" "build-tools;28.0.3"` from command line.
|
||||
|
||||
1. Open the project in Android Studio 3.1
|
||||
2. Create a new Android App configuration. Choose module `android`.
|
||||
3. Now build and run the configuration created.
|
||||
To build use `ANDROID_HOME=<your path to android sdk> ../gradlew assemble`.
|
||||
|
||||
Run `$ANDROID_HOME/platform-tools/adb install -r androidApp/build/outputs/apk/debug/androidApp-debug.apk`
|
||||
to deploy the apk on the Android device or emulator.
|
||||
|
||||
Note: If you are importing project to IDEA for the first time, you might need to put `local.properties` file
|
||||
with the following content:
|
||||
|
||||
sdk.dir=<your path to Android SDK>
|
||||
|
||||
## iOS
|
||||
The iOS project compiles Kotlin module to a framework (see [ios](ios/)). The framework can be easily included in an existing iOS project (e.g. written in Swift or Objective-C)
|
||||
The iOS project compiles Kotlin module to a framework (see [iosApp](iosApp/)). The framework can be easily included in an existing iOS project (e.g. written in Swift or Objective-C)
|
||||
|
||||
To build and run the iOS sample do the following:
|
||||
|
||||
1. Open `ios/calculator.xcodeproj` with Xcode.
|
||||
1. Open `iosApp/calculator.xcodeproj` with Xcode.
|
||||
2. Open the project's target through project navigator, go to tab 'General'.
|
||||
In 'Identity' section change the bundle ID to the unique string in
|
||||
reverse-DNS format. Then select the team in 'Signing' section.
|
||||
@@ -41,14 +49,7 @@ the Xcode project.
|
||||
|
||||
## Plain JVM
|
||||
The common module can also be used in JVM application built by Kotlin/JVM compiler with Gradle.
|
||||
To build and run it, go to [jvm](jvm/) directory and use
|
||||
To build and run it, go to [cliApp](cliApp/) directory and use
|
||||
```
|
||||
../gradlew run
|
||||
../gradlew runProgram
|
||||
```
|
||||
|
||||
To build the distribution:
|
||||
```
|
||||
../gradlew distZip
|
||||
```
|
||||
(the result will be available as
|
||||
`jvm/build/distributions/KotlinCalculator.zip`)
|
||||
|
||||
@@ -1,44 +0,0 @@
|
||||
buildscript {
|
||||
ext.kotlin_version = '1.3.0-rc-6'
|
||||
|
||||
repositories {
|
||||
google()
|
||||
jcenter()
|
||||
}
|
||||
|
||||
dependencies {
|
||||
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
|
||||
classpath 'com.android.tools.build:gradle:3.1.4'
|
||||
}
|
||||
}
|
||||
|
||||
apply plugin: 'com.android.application'
|
||||
apply plugin: 'kotlin-platform-android'
|
||||
|
||||
android {
|
||||
compileSdkVersion 27
|
||||
defaultConfig {
|
||||
applicationId "org.konan.calculator"
|
||||
minSdkVersion 21
|
||||
targetSdkVersion 27
|
||||
versionCode 1
|
||||
versionName "1.0.0"
|
||||
}
|
||||
sourceSets {
|
||||
main.java.srcDirs += 'src/main/kotlin'
|
||||
main.java.srcDirs += '../common/src/main/kotlin'
|
||||
}
|
||||
}
|
||||
|
||||
repositories {
|
||||
google()
|
||||
jcenter()
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
|
||||
expectedBy project(':common')
|
||||
|
||||
implementation "com.android.support:appcompat-v7:27.0.2"
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
apply plugin: 'org.jetbrains.kotlin.multiplatform'
|
||||
apply plugin: 'com.android.application'
|
||||
apply plugin: 'kotlin-android-extensions'
|
||||
|
||||
android {
|
||||
compileSdkVersion 28
|
||||
|
||||
defaultConfig {
|
||||
applicationId 'org.konan.calculator'
|
||||
minSdkVersion 21
|
||||
targetSdkVersion 28
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
api 'com.android.support:appcompat-v7:28.0.0'
|
||||
api 'com.android.support.constraint:constraint-layout:1.1.3'
|
||||
implementation fileTree(dir: 'libs', include: ['*.jar'])
|
||||
implementation project(':arithmeticParser')
|
||||
}
|
||||
|
||||
kotlin {
|
||||
targets {
|
||||
fromPreset(presets.android, 'android')
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
kotlin.code.style=official
|
||||
kotlin.import.noCommonSourceSets=true
|
||||
@@ -1,5 +1,8 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="org.konan.calculator">
|
||||
package="sample.calculator.android"
|
||||
android:versionCode="1"
|
||||
android:versionName="1.0">
|
||||
|
||||
<application
|
||||
android:allowBackup="true"
|
||||
@@ -10,7 +13,7 @@
|
||||
android:theme="@style/AppTheme">
|
||||
|
||||
<activity
|
||||
android:name="org.konan.calculator.MainActivity"
|
||||
android:name="sample.calculator.android.MainActivity"
|
||||
android:theme="@style/AppTheme">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
@@ -1,10 +1,15 @@
|
||||
package org.konan.calculator
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package sample.calculator.android
|
||||
|
||||
import android.os.Bundle
|
||||
import android.support.v7.app.AppCompatActivity
|
||||
import android.widget.EditText
|
||||
import android.widget.TextView
|
||||
import org.konan.arithmeticparser.parseAndCompute
|
||||
import sample.calculator.arithmeticparser.parseAndCompute
|
||||
|
||||
class MainActivity : AppCompatActivity() {
|
||||
|
||||
@@ -19,7 +24,7 @@ class MainActivity : AppCompatActivity() {
|
||||
val inputText = input.text.toString()
|
||||
val result = parseAndCompute(inputText).expression
|
||||
with(resultView) {
|
||||
text = if (result != null) inputText + " = " + result.toString() else "Unable to parse " + inputText
|
||||
text = if (result != null) inputText + " = " + result.toString() else "Unable to parse $inputText"
|
||||
}
|
||||
true
|
||||
}
|
||||
|
Before Width: | Height: | Size: 3.0 KiB After Width: | Height: | Size: 3.0 KiB |
|
Before Width: | Height: | Size: 4.9 KiB After Width: | Height: | Size: 4.9 KiB |
|
Before Width: | Height: | Size: 2.0 KiB After Width: | Height: | Size: 2.0 KiB |
|
Before Width: | Height: | Size: 2.8 KiB After Width: | Height: | Size: 2.8 KiB |
|
Before Width: | Height: | Size: 4.5 KiB After Width: | Height: | Size: 4.5 KiB |
|
Before Width: | Height: | Size: 6.9 KiB After Width: | Height: | Size: 6.9 KiB |
|
Before Width: | Height: | Size: 6.3 KiB After Width: | Height: | Size: 6.3 KiB |
|
Before Width: | Height: | Size: 10 KiB After Width: | Height: | Size: 10 KiB |
|
Before Width: | Height: | Size: 9.0 KiB After Width: | Height: | Size: 9.0 KiB |
|
Before Width: | Height: | Size: 15 KiB After Width: | Height: | Size: 15 KiB |
@@ -0,0 +1,80 @@
|
||||
apply plugin: 'org.jetbrains.kotlin.multiplatform'
|
||||
|
||||
kotlin {
|
||||
targets {
|
||||
fromPreset(determineIosPreset(), 'ios') {
|
||||
compilations.main.outputKinds 'FRAMEWORK'
|
||||
}
|
||||
|
||||
fromPreset(presets.jvm, 'jvm')
|
||||
}
|
||||
|
||||
sourceSets {
|
||||
commonMain {
|
||||
dependencies {
|
||||
api 'org.jetbrains.kotlin:kotlin-stdlib-common'
|
||||
}
|
||||
}
|
||||
jvmMain {
|
||||
dependencies {
|
||||
api 'org.jetbrains.kotlin:kotlin-stdlib-jdk8'
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Workaround for https://youtrack.jetbrains.com/issue/KT-27170
|
||||
configurations {
|
||||
compileClasspath
|
||||
}
|
||||
|
||||
// If custom preset specified in 'calculator.preset.name' property, then use it for building.
|
||||
// Otherwise build for iPhone simulator (by default).
|
||||
def determineIosPreset() {
|
||||
String presetName = project.hasProperty('calculator.preset.name') ? project.properties['calculator.preset.name'] : 'iosX64'
|
||||
def preset = project.kotlin.presets[presetName]
|
||||
println("$project has been configured for $presetName platform.")
|
||||
preset
|
||||
}
|
||||
|
||||
// Special Gradle task that is called from Xcode.
|
||||
// Two Gradle properties must be specified for this task:
|
||||
// - calculator.configuration.name=[Release|Debug]
|
||||
// - calculator.framework.location
|
||||
task buildFrameworkForXcode {
|
||||
doLast {
|
||||
if (!isCalledFromXcode()) {
|
||||
throw new Exception("Please run 'buildFrameworkForXcode' task with all necessary properties!")
|
||||
}
|
||||
|
||||
println("from: ${kotlin.targets.ios.compilations.main.getBinary('FRAMEWORK', getBuildTypeForXcode()).parentFile}")
|
||||
println("into: ${getXcodeConfigurationBuildDir()}")
|
||||
|
||||
File frameworkDir = kotlin.targets.ios.compilations.main.getBinary('FRAMEWORK', getBuildTypeForXcode())
|
||||
|
||||
copy {
|
||||
from frameworkDir.parentFile
|
||||
into getXcodeConfigurationBuildDir()
|
||||
include "${frameworkDir.name}/**"
|
||||
include "${frameworkDir.name}.dSYM/**"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
afterEvaluate {
|
||||
if (isCalledFromXcode()) {
|
||||
buildFrameworkForXcode.dependsOn kotlin.targets.ios.compilations.main.linkTaskName('FRAMEWORK', getBuildTypeForXcode())
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isCalledFromXcode() {
|
||||
project.hasProperty('calculator.configuration.name') && project.hasProperty('calculator.framework.location')
|
||||
}
|
||||
|
||||
private String getBuildTypeForXcode() {
|
||||
project.properties['calculator.configuration.name'] as String
|
||||
}
|
||||
|
||||
private String getXcodeConfigurationBuildDir() {
|
||||
project.properties['calculator.framework.location'] as String
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
kotlin.code.style=official
|
||||
@@ -1,23 +1,12 @@
|
||||
/*
|
||||
* Copyright 2010-2017 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package org.konan.arithmeticparser
|
||||
package sample.calculator.arithmeticparser
|
||||
|
||||
fun parseAndCompute(expression: String): PartialParser.Result<Double, String> =
|
||||
PartialParser<Double, String>(Calculator(), PartialRenderer()).parseWithPartial(expression)
|
||||
PartialParser(Calculator(), PartialRenderer()).parseWithPartial(expression)
|
||||
|
||||
class Calculator : ExpressionComposer<Double> {
|
||||
override fun number(value: Double) = value
|
||||
@@ -47,7 +36,7 @@ interface ExpressionComposer<E : Any> {
|
||||
fun div(left: E, right: E): E
|
||||
}
|
||||
|
||||
open class Parser<E : Any>(protected val composer: ExpressionComposer<E>) {
|
||||
open class Parser<E : Any>(private val composer: ExpressionComposer<E>) {
|
||||
fun parse(expression: String): E? {
|
||||
val tokenizer = Tokenizer(expression)
|
||||
val prefix = parseAsPrefix(tokenizer)
|
||||
@@ -70,12 +59,10 @@ open class Parser<E : Any>(protected val composer: ExpressionComposer<E>) {
|
||||
private fun ExpressionPrefix<E>.tryExtend(tokenizer: Tokenizer): ExpressionPrefix<E>? = when (this) {
|
||||
is ContinuableWithExpression -> {
|
||||
val number = tokenizer.tryReadNumber()
|
||||
if (number != null) {
|
||||
this.with(composer.number(number))
|
||||
} else if (tokenizer.tryReadLeftParenthesis()) {
|
||||
this.withLeftParenthesis()
|
||||
} else {
|
||||
null
|
||||
when {
|
||||
number != null -> this.with(composer.number(number))
|
||||
tokenizer.tryReadLeftParenthesis() -> this.withLeftParenthesis()
|
||||
else -> null
|
||||
}
|
||||
}
|
||||
|
||||
@@ -221,7 +208,7 @@ internal data class EndedWithExpression<E>(
|
||||
internal sealed class ContinuableWithExpression<out E> : ExpressionPrefix<E>()
|
||||
|
||||
private fun <E> ContinuableWithExpression<E>.with(expression: E) =
|
||||
EndedWithExpression<E>(this, expression)
|
||||
EndedWithExpression(this, expression)
|
||||
|
||||
private object Empty : ContinuableWithExpression<Nothing>()
|
||||
|
||||
@@ -230,7 +217,7 @@ private data class EndedWithLeftParenthesis<out E>(
|
||||
) : ContinuableWithExpression<E>()
|
||||
|
||||
private fun <E> ContinuableWithExpression<E>.withLeftParenthesis() =
|
||||
EndedWithLeftParenthesis<E>(this)
|
||||
EndedWithLeftParenthesis(this)
|
||||
|
||||
private data class EndedWithOperator<out E>(
|
||||
val prefix: ContinuableWithExpression<E>,
|
||||
@@ -1,23 +1,24 @@
|
||||
allprojects {
|
||||
buildscript {
|
||||
repositories {
|
||||
maven { url "https://dl.bintray.com/kotlin/kotlin-dev" }
|
||||
}
|
||||
}
|
||||
|
||||
buildscript {
|
||||
repositories {
|
||||
maven { url "https://dl.bintray.com/kotlin/kotlin-dev" }
|
||||
google()
|
||||
jcenter()
|
||||
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"
|
||||
classpath 'com.android.tools.build:gradle:3.2.1'
|
||||
}
|
||||
}
|
||||
|
||||
task build {
|
||||
subprojects.each {
|
||||
dependsOn("${it.path}:build")
|
||||
}
|
||||
}
|
||||
|
||||
task clean {
|
||||
subprojects.each {
|
||||
dependsOn("${it.path}:clean")
|
||||
allprojects {
|
||||
repositories {
|
||||
google()
|
||||
jcenter()
|
||||
mavenCentral()
|
||||
maven { url 'https://dl.bintray.com/kotlin/kotlin-dev' }
|
||||
maven { url 'https://dl.bintray.com/kotlin/kotlin-eap' }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
DIR=$(cd "$(dirname "${BASH_SOURCE[0]}" )" && pwd )
|
||||
|
||||
$DIR/../gradlew -p $DIR assemble
|
||||
@@ -0,0 +1,22 @@
|
||||
apply plugin: 'org.jetbrains.kotlin.multiplatform'
|
||||
|
||||
kotlin {
|
||||
targets {
|
||||
fromPreset(presets.jvm, 'jvm')
|
||||
}
|
||||
|
||||
sourceSets {
|
||||
jvmMain {
|
||||
dependencies {
|
||||
implementation project(':arithmeticParser')
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
task runProgram(type: JavaExec) {
|
||||
dependsOn assemble
|
||||
main = 'sample.calculator.jvm.JvmCli'
|
||||
classpath = files(kotlin.targets.jvm.compilations.main.output) + kotlin.targets.jvm.compilations.main.runtimeDependencyFiles
|
||||
args '2 + 3'
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
kotlin.code.style=official
|
||||
kotlin.import.noCommonSourceSets=true
|
||||
@@ -1,11 +1,17 @@
|
||||
package org.konan.calculator
|
||||
/*
|
||||
* 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("JvmCli")
|
||||
|
||||
import org.konan.arithmeticparser.*
|
||||
package sample.calculator.jvm
|
||||
|
||||
import sample.calculator.arithmeticparser.parseAndCompute
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
val expression = if (args.isNotEmpty()) {
|
||||
args.first().also {
|
||||
println(it)
|
||||
print(it)
|
||||
}
|
||||
} else {
|
||||
println("Enter an expression:")
|
||||
@@ -1,23 +0,0 @@
|
||||
buildscript {
|
||||
ext.kotlin_version = '1.3.0-rc-6'
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
dependencies {
|
||||
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
|
||||
}
|
||||
}
|
||||
|
||||
apply plugin: 'kotlin-platform-common'
|
||||
|
||||
group = 'org.jetbrains.kotlin.konan.samples'
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compile "org.jetbrains.kotlin:kotlin-stdlib-common:$kotlin_version"
|
||||
}
|
||||
@@ -1,2 +1,4 @@
|
||||
konan.home=../../../dist
|
||||
konan.plugin.version=+
|
||||
kotlin.code.style=official
|
||||
|
||||
# Use custom Kotlin/Native home:
|
||||
org.jetbrains.kotlin.native.home=../../../dist
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.2-all.zip
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-4.7-all.zip
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
||||
|
||||
@@ -1,25 +0,0 @@
|
||||
buildscript {
|
||||
repositories {
|
||||
mavenCentral()
|
||||
maven { url "https://dl.bintray.com/jetbrains/kotlin-native-dependencies" }
|
||||
}
|
||||
|
||||
dependencies {
|
||||
classpath "org.jetbrains.kotlin:kotlin-native-gradle-plugin:${project.property('konan.plugin.version')}"
|
||||
}
|
||||
}
|
||||
|
||||
apply plugin: 'konan'
|
||||
|
||||
konan.targets = ['iphone', 'iphone_sim']
|
||||
|
||||
konanArtifacts {
|
||||
framework('KotlinArithmeticParser') {
|
||||
enableMultiplatform true
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
expectedBy project(':common')
|
||||
}
|
||||
|
||||
@@ -12,8 +12,8 @@
|
||||
2C3F384A1FD1738300151601 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 2C3F38481FD1738300151601 /* Main.storyboard */; };
|
||||
2C3F384C1FD1738300151601 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 2C3F384B1FD1738300151601 /* Assets.xcassets */; };
|
||||
2C3F384F1FD1738300151601 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 2C3F384D1FD1738300151601 /* LaunchScreen.storyboard */; };
|
||||
7FE128BF205854BA0064CE74 /* KotlinArithmeticParser.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 7FF94AD92058464C00590D0D /* KotlinArithmeticParser.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
|
||||
7FF94AE32058483900590D0D /* KotlinArithmeticParser.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 7FF94AD92058464C00590D0D /* KotlinArithmeticParser.framework */; };
|
||||
7FE128BF205854BA0064CE74 /* arithmeticParser.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 7FF94AD92058464C00590D0D /* arithmeticParser.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
|
||||
7FF94AE32058483900590D0D /* arithmeticParser.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 7FF94AD92058464C00590D0D /* arithmeticParser.framework */; };
|
||||
/* End PBXBuildFile section */
|
||||
|
||||
/* Begin PBXCopyFilesBuildPhase section */
|
||||
@@ -23,7 +23,7 @@
|
||||
dstPath = "";
|
||||
dstSubfolderSpec = 10;
|
||||
files = (
|
||||
7FE128BF205854BA0064CE74 /* KotlinArithmeticParser.framework in Embed Frameworks */,
|
||||
7FE128BF205854BA0064CE74 /* arithmeticParser.framework in Embed Frameworks */,
|
||||
);
|
||||
name = "Embed Frameworks";
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
@@ -38,7 +38,7 @@
|
||||
2C3F384B1FD1738300151601 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
|
||||
2C3F384E1FD1738300151601 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = "<group>"; };
|
||||
2C3F38501FD1738300151601 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
|
||||
7FF94AD92058464C00590D0D /* KotlinArithmeticParser.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = KotlinArithmeticParser.framework; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||
7FF94AD92058464C00590D0D /* arithmeticParser.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = arithmeticParser.framework; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||
7FF94AEA2058485300590D0D /* Parser.kt */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = Parser.kt; sourceTree = "<group>"; };
|
||||
/* End PBXFileReference section */
|
||||
|
||||
@@ -47,7 +47,7 @@
|
||||
isa = PBXFrameworksBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
7FF94AE32058483900590D0D /* KotlinArithmeticParser.framework in Frameworks */,
|
||||
7FF94AE32058483900590D0D /* arithmeticParser.framework in Frameworks */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
@@ -58,7 +58,7 @@
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
2C3F38431FD1738300151601 /* calculator */,
|
||||
7FF94ADA2058464C00590D0D /* KotlinArithmeticParser */,
|
||||
7FF94ADA2058464C00590D0D /* arithmeticParser */,
|
||||
2C3F38421FD1738300151601 /* Products */,
|
||||
7FF94AE22058483900590D0D /* Frameworks */,
|
||||
);
|
||||
@@ -68,7 +68,7 @@
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
2C3F38411FD1738300151601 /* KotlinCalculator.app */,
|
||||
7FF94AD92058464C00590D0D /* KotlinArithmeticParser.framework */,
|
||||
7FF94AD92058464C00590D0D /* arithmeticParser.framework */,
|
||||
);
|
||||
name = Products;
|
||||
sourceTree = "<group>";
|
||||
@@ -86,12 +86,12 @@
|
||||
path = calculator;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
7FF94ADA2058464C00590D0D /* KotlinArithmeticParser */ = {
|
||||
7FF94ADA2058464C00590D0D /* arithmeticParser */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
7FF94AE42058485300590D0D /* src */,
|
||||
);
|
||||
name = KotlinArithmeticParser;
|
||||
name = arithmeticParser;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
7FF94AE22058483900590D0D /* Frameworks */ = {
|
||||
@@ -104,50 +104,26 @@
|
||||
7FF94AE42058485300590D0D /* src */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
7FF94AE52058485300590D0D /* main */,
|
||||
7FF94AE52058485300590D0D /* commonMain */,
|
||||
);
|
||||
name = src;
|
||||
path = ../common/src;
|
||||
path = ../arithmeticParser/src;
|
||||
sourceTree = SOURCE_ROOT;
|
||||
};
|
||||
7FF94AE52058485300590D0D /* main */ = {
|
||||
7FF94AE52058485300590D0D /* commonMain */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
7FF94AE62058485300590D0D /* kotlin */,
|
||||
);
|
||||
path = main;
|
||||
path = commonMain;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
7FF94AE62058485300590D0D /* kotlin */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
7FF94AE72058485300590D0D /* org */,
|
||||
);
|
||||
path = kotlin;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
7FF94AE72058485300590D0D /* org */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
7FF94AE82058485300590D0D /* konan */,
|
||||
);
|
||||
path = org;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
7FF94AE82058485300590D0D /* konan */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
7FF94AE92058485300590D0D /* arithmeticparser */,
|
||||
);
|
||||
path = konan;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
7FF94AE92058485300590D0D /* arithmeticparser */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
7FF94AEA2058485300590D0D /* Parser.kt */,
|
||||
);
|
||||
path = arithmeticparser;
|
||||
path = kotlin;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
/* End PBXGroup section */
|
||||
@@ -171,9 +147,9 @@
|
||||
productReference = 2C3F38411FD1738300151601 /* KotlinCalculator.app */;
|
||||
productType = "com.apple.product-type.application";
|
||||
};
|
||||
7FF94AD82058464C00590D0D /* KotlinArithmeticParser */ = {
|
||||
7FF94AD82058464C00590D0D /* arithmeticParser */ = {
|
||||
isa = PBXNativeTarget;
|
||||
buildConfigurationList = 7FF94ADE2058464C00590D0D /* Build configuration list for PBXNativeTarget "KotlinArithmeticParser" */;
|
||||
buildConfigurationList = 7FF94ADE2058464C00590D0D /* Build configuration list for PBXNativeTarget "arithmeticParser" */;
|
||||
buildPhases = (
|
||||
7FF94AE12058466D00590D0D /* Compile Kotlin/Native */,
|
||||
);
|
||||
@@ -181,9 +157,9 @@
|
||||
);
|
||||
dependencies = (
|
||||
);
|
||||
name = KotlinArithmeticParser;
|
||||
productName = KotlinArithmeticParser;
|
||||
productReference = 7FF94AD92058464C00590D0D /* KotlinArithmeticParser.framework */;
|
||||
name = arithmeticParser;
|
||||
productName = arithmeticParser;
|
||||
productReference = 7FF94AD92058464C00590D0D /* arithmeticParser.framework */;
|
||||
productType = "com.apple.product-type.framework";
|
||||
};
|
||||
/* End PBXNativeTarget section */
|
||||
@@ -220,7 +196,7 @@
|
||||
projectRoot = "";
|
||||
targets = (
|
||||
2C3F38401FD1738300151601 /* KotlinCalculator */,
|
||||
7FF94AD82058464C00590D0D /* KotlinArithmeticParser */,
|
||||
7FF94AD82058464C00590D0D /* arithmeticParser */,
|
||||
);
|
||||
};
|
||||
/* End PBXProject section */
|
||||
@@ -251,7 +227,7 @@
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
shellPath = /bin/sh;
|
||||
shellScript = "\"$SRCROOT/../gradlew\" -p \"$SRCROOT\" \"$KONAN_TASK\" \\\n-Pkonan.configuration.build.dir=\"$CONFIGURATION_BUILD_DIR\" \\\n-Pkonan.debugging.symbols=\"$DEBUGGING_SYMBOLS\" \\\n-Pkonan.optimizations.enable=\"$KONAN_ENABLE_OPTIMIZATIONS\"";
|
||||
shellScript = "\"$SRCROOT/../gradlew\" -p \"$SRCROOT/..\" buildFrameworkForXcode \\\n-Pcalculator.preset.name=\"$KOTLIN_NATIVE_PRESET\" \\\n-Pcalculator.configuration.name=\"$CONFIGURATION\" \\\n-Pcalculator.framework.location=\"$CONFIGURATION_BUILD_DIR\"\n";
|
||||
};
|
||||
/* End PBXShellScriptBuildPhase section */
|
||||
|
||||
@@ -445,12 +421,10 @@
|
||||
DYLIB_INSTALL_NAME_BASE = "@rpath";
|
||||
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
|
||||
IPHONEOS_DEPLOYMENT_TARGET = 11.2;
|
||||
KONAN_ENABLE_OPTIMIZATIONS = NO;
|
||||
KONAN_TASK = "";
|
||||
"KONAN_TASK[sdk=iphoneos*]" = compileKonanKotlinArithmeticParserIos_arm64;
|
||||
"KONAN_TASK[sdk=iphonesimulator*]" = compileKonanKotlinArithmeticParserIos_x64;
|
||||
"KOTLIN_NATIVE_PRESET[sdk=iphoneos*]" = iosArm64;
|
||||
"KOTLIN_NATIVE_PRESET[sdk=iphonesimulator*]" = iosX64;
|
||||
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
|
||||
PRODUCT_BUNDLE_IDENTIFIER = JetBrains.KotlinArithmeticParser;
|
||||
PRODUCT_BUNDLE_IDENTIFIER = JetBrains.arithmeticParser;
|
||||
PRODUCT_MODULE_NAME = "_$(PRODUCT_NAME:c99extidentifier)";
|
||||
PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)";
|
||||
PROVISIONING_PROFILE_SPECIFIER = "";
|
||||
@@ -475,12 +449,10 @@
|
||||
DYLIB_INSTALL_NAME_BASE = "@rpath";
|
||||
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
|
||||
IPHONEOS_DEPLOYMENT_TARGET = 11.2;
|
||||
KONAN_ENABLE_OPTIMIZATIONS = YES;
|
||||
KONAN_TASK = "";
|
||||
"KONAN_TASK[sdk=iphoneos*]" = compileKonanKotlinArithmeticParserIos_arm64;
|
||||
"KONAN_TASK[sdk=iphonesimulator*]" = compileKonanKotlinArithmeticParserIos_x64;
|
||||
"KOTLIN_NATIVE_PRESET[sdk=iphoneos*]" = iosArm64;
|
||||
"KOTLIN_NATIVE_PRESET[sdk=iphonesimulator*]" = iosX64;
|
||||
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
|
||||
PRODUCT_BUNDLE_IDENTIFIER = JetBrains.KotlinArithmeticParser;
|
||||
PRODUCT_BUNDLE_IDENTIFIER = JetBrains.arithmeticParser;
|
||||
PRODUCT_MODULE_NAME = "_$(PRODUCT_NAME:c99extidentifier)";
|
||||
PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)";
|
||||
PROVISIONING_PROFILE_SPECIFIER = "";
|
||||
@@ -513,7 +485,7 @@
|
||||
defaultConfigurationIsVisible = 0;
|
||||
defaultConfigurationName = Release;
|
||||
};
|
||||
7FF94ADE2058464C00590D0D /* Build configuration list for PBXNativeTarget "KotlinArithmeticParser" */ = {
|
||||
7FF94ADE2058464C00590D0D /* Build configuration list for PBXNativeTarget "arithmeticParser" */ = {
|
||||
isa = XCConfigurationList;
|
||||
buildConfigurations = (
|
||||
7FF94ADF2058464C00590D0D /* Debug */,
|
||||
@@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>IDEDidComputeMac32BitWarning</key>
|
||||
<true/>
|
||||
</dict>
|
||||
</plist>
|
||||
@@ -1,9 +1,6 @@
|
||||
//
|
||||
// AppDelegate.swift
|
||||
// calculator
|
||||
//
|
||||
// Created by jetbrains on 01/12/2017.
|
||||
// Copyright © 2017 JetBrains. All rights reserved.
|
||||
// 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 UIKit
|
||||
@@ -84,6 +84,11 @@
|
||||
"idiom" : "ipad",
|
||||
"size" : "83.5x83.5",
|
||||
"scale" : "2x"
|
||||
},
|
||||
{
|
||||
"idiom" : "ios-marketing",
|
||||
"size" : "1024x1024",
|
||||
"scale" : "1x"
|
||||
}
|
||||
],
|
||||
"info" : {
|
||||
@@ -1,13 +1,10 @@
|
||||
//
|
||||
// ViewController.swift
|
||||
// calculator
|
||||
//
|
||||
// Created by jetbrains on 01/12/2017.
|
||||
// Copyright © 2017 JetBrains. All rights reserved.
|
||||
// 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 UIKit
|
||||
import KotlinArithmeticParser
|
||||
import arithmeticParser
|
||||
|
||||
class ViewController: UIViewController, UITextViewDelegate, UICollectionViewDataSource {
|
||||
|
||||
@@ -1,30 +0,0 @@
|
||||
buildscript {
|
||||
ext.kotlin_version = '1.3.0-rc-6'
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
dependencies {
|
||||
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
|
||||
}
|
||||
}
|
||||
|
||||
apply plugin: 'kotlin-platform-jvm'
|
||||
apply plugin: 'application'
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
|
||||
expectedBy project(":common")
|
||||
}
|
||||
|
||||
applicationName = "KotlinCalculator"
|
||||
|
||||
mainClassName = 'org.konan.calculator.JvmCliKt'
|
||||
run {
|
||||
args "2 + 2"
|
||||
}
|
||||
@@ -1,17 +1,37 @@
|
||||
include ':common'
|
||||
include ':jvm'
|
||||
include ':ios'
|
||||
|
||||
def localProperties = new Properties()
|
||||
def localPropertiesFile = file('local.properties')
|
||||
if (localPropertiesFile.exists()) {
|
||||
localPropertiesFile.withReader { localProperties.load(it) }
|
||||
// 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
|
||||
}
|
||||
}
|
||||
|
||||
include ':arithmeticParser'
|
||||
include ':cliApp'
|
||||
|
||||
boolean sdkDirPropertySpecified = false
|
||||
File localPropertiesFile = file("${rootProject.projectDir}/local.properties")
|
||||
if (localPropertiesFile.isFile()) {
|
||||
Properties properties = new Properties()
|
||||
localPropertiesFile.withInputStream { inputStream -> properties.load(inputStream) }
|
||||
sdkDirPropertySpecified = properties.containsKey('sdk.dir')
|
||||
}
|
||||
|
||||
|
||||
// Don't create Android tasks if a user has no Android SDK.
|
||||
if (localProperties.containsKey("sdk.dir") || System.getenv('ANDROID_HOME') != null) {
|
||||
include ':android'
|
||||
if (sdkDirPropertySpecified || System.getenv('ANDROID_HOME') != null) {
|
||||
include ':androidApp'
|
||||
}
|
||||
|
||||
includeBuild '../../shared'
|
||||
includeBuild '../../tools/kotlin-native-gradle-plugin'
|
||||
|
||||
|
Can't render this file because it is too large.
|
@@ -1,14 +1,14 @@
|
||||
# CSV parser
|
||||
|
||||
This example shows how one could implement simple comma separated values reader and parser in Kotlin.
|
||||
This example shows how one could implement simple comma separated values reader and parser in Kotlin.
|
||||
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 assemble` or `./build.sh`.
|
||||
To build use `../gradlew assemble`.
|
||||
|
||||
Now you can run artifact directly
|
||||
To run use `../gradlew runProgram` or execute the program directly:
|
||||
|
||||
./build/exe/main/release/csvparser.kexe ./European_Mammals_Red_List_Nov_2009.csv 4 100
|
||||
./build/bin/csvParser/main/release/executable/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.
|
||||
|
||||
@@ -1,16 +0,0 @@
|
||||
@echo off
|
||||
|
||||
setlocal
|
||||
|
||||
set DIR=.
|
||||
|
||||
if defined KONAN_HOME (
|
||||
set "PATH=%KONAN_HOME%\bin;%PATH%"
|
||||
) else (
|
||||
set "PATH=..\..\dist\bin;..\..\bin;%PATH%"
|
||||
)
|
||||
|
||||
if "%TARGET%" == "" set TARGET=mingw
|
||||
|
||||
call konanc -target "%TARGET%" "%DIR%\src\main\kotlin\CsvParser.kt" -o CsvParser
|
||||
exit /b %ERRORLEVEL%
|
||||
@@ -1,5 +1,16 @@
|
||||
apply plugin: 'org.jetbrains.kotlin.platform.native'
|
||||
plugins {
|
||||
id 'kotlin-multiplatform'
|
||||
}
|
||||
|
||||
components.main {
|
||||
outputKinds = [ EXECUTABLE ]
|
||||
}
|
||||
kotlin {
|
||||
targets {
|
||||
fromPreset(MPPTools.defaultHostPreset(project), 'csvParser') {
|
||||
compilations.main.outputKinds 'EXECUTABLE'
|
||||
compilations.main.entryPoint 'sample.csvparser.main'
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
MPPTools.createRunTask(project, 'runProgram', kotlin.targets.csvParser) {
|
||||
args './European_Mammals_Red_List_Nov_2009.csv', 4, 100
|
||||
}
|
||||
|
||||
@@ -1,29 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
DIR=$(cd "$(dirname "${BASH_SOURCE[0]}" )" && pwd )
|
||||
|
||||
source "$DIR/../konan.sh"
|
||||
|
||||
if [ x$TARGET == x ]; then
|
||||
case "$OSTYPE" in
|
||||
darwin*) TARGET=macbook ;;
|
||||
linux*) TARGET=linux ;;
|
||||
msys*) TARGET=mingw ;;
|
||||
*) echo "unknown: $OSTYPE" && exit 1;;
|
||||
esac
|
||||
fi
|
||||
|
||||
var=CFLAGS_${TARGET}
|
||||
CFLAGS=${!var}
|
||||
var=LINKER_ARGS_${TARGET}
|
||||
LINKER_ARGS=${!var}
|
||||
var=COMPILER_ARGS_${TARGET}
|
||||
COMPILER_ARGS=${!var} # add -opt for an optimized build.
|
||||
|
||||
mkdir -p $DIR/build/c_interop/
|
||||
mkdir -p $DIR/build/bin/
|
||||
|
||||
konanc $COMPILER_ARGS -target $TARGET $DIR/src/main/kotlin/CsvParser.kt \
|
||||
-o $DIR/build/bin/CsvParser || exit 1
|
||||
|
||||
echo "Artifact path is $DIR/build/bin/CsvParser.kexe"
|
||||
@@ -1 +1,2 @@
|
||||
runArgs=./European_Mammals_Red_List_Nov_2009.csv 4 100
|
||||
kotlin.code.style=official
|
||||
kotlin.import.noCommonSourceSets=true
|
||||
|
||||
@@ -1,19 +1,10 @@
|
||||
/*
|
||||
* Copyright 2010-2017 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package sample.csvparser
|
||||
|
||||
import kotlinx.cinterop.*
|
||||
import platform.posix.*
|
||||
|
||||
@@ -40,7 +31,7 @@ fun parseLine(line: String, separator: Char) : List<String> {
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
if (args.size != 3) {
|
||||
println("usage: csvparser.kexe file.csv column count")
|
||||
println("Usage: csvparser.kexe <file.csv> <column> <count>")
|
||||
return
|
||||
}
|
||||
val fileName = args[0]
|
||||
@@ -3,11 +3,11 @@
|
||||
This example shows how to communicate with libcurl, HTTP/HTTPS/FTP/etc client library and how to
|
||||
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 assemble`.
|
||||
|
||||
Now you can run the client directly
|
||||
To run use `../gradlew runProgram` or execute the program directly:
|
||||
|
||||
./build/exe/main/release/<platform>/curl.kexe https://www.jetbrains.com
|
||||
./build/bin/curl/main/release/executable/curl.kexe 'https://www.jetbrains.com/'
|
||||
|
||||
It will perform HTTP get and print out the data obtained.
|
||||
|
||||
@@ -1,33 +1,58 @@
|
||||
buildscript {
|
||||
repositories {
|
||||
maven {
|
||||
url 'https://cache-redirector.jetbrains.com/maven-central'
|
||||
}
|
||||
maven {
|
||||
url "https://dl.bintray.com/jetbrains/kotlin-native-dependencies"
|
||||
}
|
||||
}
|
||||
import java.nio.file.Paths
|
||||
|
||||
dependencies {
|
||||
classpath "org.jetbrains.kotlin:kotlin-native-gradle-plugin:${project.property('konan.plugin.version')}"
|
||||
}
|
||||
plugins {
|
||||
id 'kotlin-multiplatform'
|
||||
}
|
||||
|
||||
apply plugin: 'org.jetbrains.kotlin.platform.native'
|
||||
|
||||
def localMavenRepo="file://${new File(System.properties['user.home'] as String)}/.m2-kotlin-native"
|
||||
def localRepo = rootProject.file('build/.m2-repo')
|
||||
|
||||
repositories {
|
||||
maven {
|
||||
url = localMavenRepo
|
||||
maven { url = "file://$localRepo" }
|
||||
}
|
||||
|
||||
kotlin {
|
||||
presets {
|
||||
// Determine host preset.
|
||||
MPPTools.defaultHostPreset(project, [macosX64, linuxX64])
|
||||
}
|
||||
|
||||
targets {
|
||||
fromPreset(hostPreset, 'curl') {
|
||||
compilations.main.outputKinds 'EXECUTABLE'
|
||||
compilations.main.entryPoint 'sample.curl.main'
|
||||
}
|
||||
}
|
||||
|
||||
sourceSets {
|
||||
curlMain {
|
||||
dependencies {
|
||||
implementation 'org.jetbrains.kotlin.sample.native:libcurl:1.0'
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
components.main {
|
||||
targets = ['macos_x64', 'linux_x64']
|
||||
outputKinds = [ EXECUTABLE ]
|
||||
MPPTools.createRunTask(project, 'runProgram', kotlin.targets.curl) {
|
||||
args 'https://www.jetbrains.com/'
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation 'org.jetbrains.kotlin.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"
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,2 +1,2 @@
|
||||
konan.home=../../dist
|
||||
konan.plugin.version=+
|
||||
kotlin.code.style=official
|
||||
kotlin.import.noCommonSourceSets=true
|
||||
|
||||
@@ -1,5 +0,0 @@
|
||||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.2-all.zip
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
||||
@@ -1,172 +0,0 @@
|
||||
#!/usr/bin/env sh
|
||||
|
||||
##############################################################################
|
||||
##
|
||||
## Gradle start up script for UN*X
|
||||
##
|
||||
##############################################################################
|
||||
|
||||
# Attempt to set APP_HOME
|
||||
# Resolve links: $0 may be a link
|
||||
PRG="$0"
|
||||
# Need this for relative symlinks.
|
||||
while [ -h "$PRG" ] ; do
|
||||
ls=`ls -ld "$PRG"`
|
||||
link=`expr "$ls" : '.*-> \(.*\)$'`
|
||||
if expr "$link" : '/.*' > /dev/null; then
|
||||
PRG="$link"
|
||||
else
|
||||
PRG=`dirname "$PRG"`"/$link"
|
||||
fi
|
||||
done
|
||||
SAVED="`pwd`"
|
||||
cd "`dirname \"$PRG\"`/" >/dev/null
|
||||
APP_HOME="`pwd -P`"
|
||||
cd "$SAVED" >/dev/null
|
||||
|
||||
APP_NAME="Gradle"
|
||||
APP_BASE_NAME=`basename "$0"`
|
||||
|
||||
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||
DEFAULT_JVM_OPTS=""
|
||||
|
||||
# Use the maximum available, or set MAX_FD != -1 to use that value.
|
||||
MAX_FD="maximum"
|
||||
|
||||
warn () {
|
||||
echo "$*"
|
||||
}
|
||||
|
||||
die () {
|
||||
echo
|
||||
echo "$*"
|
||||
echo
|
||||
exit 1
|
||||
}
|
||||
|
||||
# OS specific support (must be 'true' or 'false').
|
||||
cygwin=false
|
||||
msys=false
|
||||
darwin=false
|
||||
nonstop=false
|
||||
case "`uname`" in
|
||||
CYGWIN* )
|
||||
cygwin=true
|
||||
;;
|
||||
Darwin* )
|
||||
darwin=true
|
||||
;;
|
||||
MINGW* )
|
||||
msys=true
|
||||
;;
|
||||
NONSTOP* )
|
||||
nonstop=true
|
||||
;;
|
||||
esac
|
||||
|
||||
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
|
||||
|
||||
# Determine the Java command to use to start the JVM.
|
||||
if [ -n "$JAVA_HOME" ] ; then
|
||||
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
|
||||
# IBM's JDK on AIX uses strange locations for the executables
|
||||
JAVACMD="$JAVA_HOME/jre/sh/java"
|
||||
else
|
||||
JAVACMD="$JAVA_HOME/bin/java"
|
||||
fi
|
||||
if [ ! -x "$JAVACMD" ] ; then
|
||||
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
|
||||
|
||||
Please set the JAVA_HOME variable in your environment to match the
|
||||
location of your Java installation."
|
||||
fi
|
||||
else
|
||||
JAVACMD="java"
|
||||
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
||||
|
||||
Please set the JAVA_HOME variable in your environment to match the
|
||||
location of your Java installation."
|
||||
fi
|
||||
|
||||
# Increase the maximum file descriptors if we can.
|
||||
if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
|
||||
MAX_FD_LIMIT=`ulimit -H -n`
|
||||
if [ $? -eq 0 ] ; then
|
||||
if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
|
||||
MAX_FD="$MAX_FD_LIMIT"
|
||||
fi
|
||||
ulimit -n $MAX_FD
|
||||
if [ $? -ne 0 ] ; then
|
||||
warn "Could not set maximum file descriptor limit: $MAX_FD"
|
||||
fi
|
||||
else
|
||||
warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
|
||||
fi
|
||||
fi
|
||||
|
||||
# For Darwin, add options to specify how the application appears in the dock
|
||||
if $darwin; then
|
||||
GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
|
||||
fi
|
||||
|
||||
# For Cygwin, switch paths to Windows format before running java
|
||||
if $cygwin ; then
|
||||
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
|
||||
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
|
||||
JAVACMD=`cygpath --unix "$JAVACMD"`
|
||||
|
||||
# We build the pattern for arguments to be converted via cygpath
|
||||
ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
|
||||
SEP=""
|
||||
for dir in $ROOTDIRSRAW ; do
|
||||
ROOTDIRS="$ROOTDIRS$SEP$dir"
|
||||
SEP="|"
|
||||
done
|
||||
OURCYGPATTERN="(^($ROOTDIRS))"
|
||||
# Add a user-defined pattern to the cygpath arguments
|
||||
if [ "$GRADLE_CYGPATTERN" != "" ] ; then
|
||||
OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
|
||||
fi
|
||||
# Now convert the arguments - kludge to limit ourselves to /bin/sh
|
||||
i=0
|
||||
for arg in "$@" ; do
|
||||
CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
|
||||
CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
|
||||
|
||||
if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
|
||||
eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
|
||||
else
|
||||
eval `echo args$i`="\"$arg\""
|
||||
fi
|
||||
i=$((i+1))
|
||||
done
|
||||
case $i in
|
||||
(0) set -- ;;
|
||||
(1) set -- "$args0" ;;
|
||||
(2) set -- "$args0" "$args1" ;;
|
||||
(3) set -- "$args0" "$args1" "$args2" ;;
|
||||
(4) set -- "$args0" "$args1" "$args2" "$args3" ;;
|
||||
(5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
|
||||
(6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
|
||||
(7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
|
||||
(8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
|
||||
(9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
|
||||
esac
|
||||
fi
|
||||
|
||||
# Escape application args
|
||||
save () {
|
||||
for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
|
||||
echo " "
|
||||
}
|
||||
APP_ARGS=$(save "$@")
|
||||
|
||||
# Collect all arguments for the java command, following the shell quoting and substitution rules
|
||||
eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
|
||||
|
||||
# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
|
||||
if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
|
||||
cd "$(dirname "$0")"
|
||||
fi
|
||||
|
||||
exec "$JAVACMD" "$@"
|
||||
@@ -1,84 +0,0 @@
|
||||
@if "%DEBUG%" == "" @echo off
|
||||
@rem ##########################################################################
|
||||
@rem
|
||||
@rem Gradle startup script for Windows
|
||||
@rem
|
||||
@rem ##########################################################################
|
||||
|
||||
@rem Set local scope for the variables with windows NT shell
|
||||
if "%OS%"=="Windows_NT" setlocal
|
||||
|
||||
set DIRNAME=%~dp0
|
||||
if "%DIRNAME%" == "" set DIRNAME=.
|
||||
set APP_BASE_NAME=%~n0
|
||||
set APP_HOME=%DIRNAME%
|
||||
|
||||
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||
set DEFAULT_JVM_OPTS=
|
||||
|
||||
@rem Find java.exe
|
||||
if defined JAVA_HOME goto findJavaFromJavaHome
|
||||
|
||||
set JAVA_EXE=java.exe
|
||||
%JAVA_EXE% -version >NUL 2>&1
|
||||
if "%ERRORLEVEL%" == "0" goto init
|
||||
|
||||
echo.
|
||||
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
||||
echo.
|
||||
echo Please set the JAVA_HOME variable in your environment to match the
|
||||
echo location of your Java installation.
|
||||
|
||||
goto fail
|
||||
|
||||
:findJavaFromJavaHome
|
||||
set JAVA_HOME=%JAVA_HOME:"=%
|
||||
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
|
||||
|
||||
if exist "%JAVA_EXE%" goto init
|
||||
|
||||
echo.
|
||||
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
|
||||
echo.
|
||||
echo Please set the JAVA_HOME variable in your environment to match the
|
||||
echo location of your Java installation.
|
||||
|
||||
goto fail
|
||||
|
||||
:init
|
||||
@rem Get command-line arguments, handling Windows variants
|
||||
|
||||
if not "%OS%" == "Windows_NT" goto win9xME_args
|
||||
|
||||
:win9xME_args
|
||||
@rem Slurp the command line arguments.
|
||||
set CMD_LINE_ARGS=
|
||||
set _SKIP=2
|
||||
|
||||
:win9xME_args_slurp
|
||||
if "x%~1" == "x" goto execute
|
||||
|
||||
set CMD_LINE_ARGS=%*
|
||||
|
||||
:execute
|
||||
@rem Setup the command line
|
||||
|
||||
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
|
||||
|
||||
@rem Execute Gradle
|
||||
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
|
||||
|
||||
:end
|
||||
@rem End local scope for the variables with windows NT shell
|
||||
if "%ERRORLEVEL%"=="0" goto mainEnd
|
||||
|
||||
:fail
|
||||
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
|
||||
rem the _cmd.exe /c_ return code!
|
||||
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
|
||||
exit /b 1
|
||||
|
||||
:mainEnd
|
||||
if "%OS%"=="Windows_NT" endlocal
|
||||
|
||||
:omega
|
||||