Kotlin/Native v0.3 is out

Posted on by Nikolay Igotti

We’re happy to announce the release of Kotlin/Native v0.3. We are going to the new lands! With the release of version v0.3 Windows is supported as both a compilation host and execution target, and Google Android devices as an execution target with native activities. So Windows API ‘Hello World’ may look as easy as:

import win32.*
fun main(args: Array<String>) {
  MessageBoxW(null, "Привет!","标题", MB_YESNOCANCEL or MB_ICONQUESTION)
}

Android native activity’s event processing:

if (AInputQueue_getEvent(queue, event.ptr) < 0) {
  logError("Failure reading input event")
  return
}
if (AInputEvent_getType(event.value) == AINPUT_EVENT_TYPE_MOTION) {
  when (AKeyEvent_getAction(event.value) and AMOTION_EVENT_ACTION_MASK) {
    AMOTION_EVENT_ACTION_DOWN -> {
      animating = false
      currentPoint = getEventPoint(event.value, 0)
      startTime = getEventTime(event.value)
      startPoint = currentPoint
    }
    AMOTION_EVENT_ACTION_UP -> {
      val endPoint = getEventPoint(event.value, 0)
      val endTime = getEventTime(event.value)
      ....
   }
   AMOTION_EVENT_ACTION_MOVE -> {
      val numberOfPointers = AMotionEvent_getPointerCount(event.value).toInt()
      for (i in 0 until numberOfPointers)
         move(getEventPoint(event.value, i))
   }
}
AInputQueue_finishEvent(queue, event.value, 1)

Debugging

With this release we support source level debugging (single-stepping only). For example, try

$ bin/konanc string0.kt  -g -o string0
$ lldb ./string0.kexe
(lldb) target create "string0.kexe"
Current executable set to 'string0.kexe' (x86_64).
(lldb) b string0.kt:1
Breakpoint 1: where = string0.kexe`kfun:main(kotlin.Array<kotlin.String>) + 4 at string0.kt:1, address = 0x0000000100001344
(lldb) r
Process 12288 launched: '/Users/jetbrains/kotlin/kotlin-native-release/kotlin-native/string0.kexe' (x86_64)
Process 12288 stopped
* thread #1, queue = 'com.apple.main-thread', stop reason = breakpoint 1.1
    frame #0: 0x0000000100001344 string0.kexe`kfun:main(kotlin.Array<kotlin.String>) at string0.kt:1
-> 1       fun main(args: Array<String>) {
   2           val str = "hello"
   3           println(str.equals("HElLo", true))
   4           val strI18n = "Привет"
   5           println(strI18n.equals("прИВет", true))
   6           println(strI18n.toUpperCase())
   7           println(strI18n.toLowerCase())
(lldb) s
Process 12288 stopped
* thread #1, queue = 'com.apple.main-thread', stop reason = step in
    frame #0: 0x0000000100001354 string0.kexe`kfun:main(kotlin.Array<kotlin.String>) at string0.kt:3
   1       fun main(args: Array<String>) {
   2           val str = "hello"
-> 3           println(str.equals("HElLo", true))
   4           val strI18n = "Привет"
   5           println(strI18n.equals("прИВет", true))
   6           println(strI18n.toUpperCase())
   7           println(strI18n.toLowerCase())

Libraries

Last, but surely, not the least, we introduced a new library format, called .klib, which is intended to be the default distribution format for Kotlin/Native libraries. Native libraries and frameworks could be easily interoperated with using .klib and used with Kotlin/Native compiler by just specifying -library library command line flag or library Gradle plugin option. Interop tool already produces .klib format files by default. For more details on library format see here.

Getting the bits

Binaries could be downloaded below:

Bugs and issues could be reported using Kotlin bug tracker.

Comments below can no longer be edited.

26 Responses to Kotlin/Native v0.3 is out

  1. Enrico Casini says:

    June 23, 2017

    Fantastic! Great work guys, keep it up!

  2. soywiz says:

    June 23, 2017

    Great news!

    BTW. Something seems to be wrong with downloadable dependencies:

    C:\dev\kotlin-native-windows-0.3\samples\win32>build
    Downloading native dependencies (LLVM, sysroot etc). This is a one-time action performed only on the first run of the compiler.
    Download dependency: http://download.jetbrains.com/kotlin/native/msys2-mingw-w64-x86_64-gcc-6.3.0-clang-llvm-3.9.1-windows-x86-64.zip (0 bytes/-). Done.
    Exception in thread "main" java.lang.IllegalStateException: Cannot download dependencies.
            at org.jetbrains.kotlin.cli.bc.K2NativeKt.maybeExecuteHelper(K2Native.kt:52)
            at org.jetbrains.kotlin.cli.bc.K2NativeKt.access$maybeExecuteHelper(K2Native.kt:1)
            at org.jetbrains.kotlin.cli.bc.K2Native.setupPlatformSpecificArgumentsAndServices(K2Native.kt:157)
            at org.jetbrains.kotlin.cli.bc.K2Native.setupPlatformSpecificArgumentsAndServices(K2Native.kt:56)
            at org.jetbrains.kotlin.cli.common.CLICompiler.execImpl(CLICompiler.java:69)
            at org.jetbrains.kotlin.cli.common.CLICompiler.execImpl(CLICompiler.java:46)
            at org.jetbrains.kotlin.cli.common.CLITool.exec(CLITool.kt:90)
            at org.jetbrains.kotlin.cli.common.CLITool.exec(CLITool.kt:68)
            at org.jetbrains.kotlin.cli.common.CLITool.exec(CLITool.kt:34)
            at org.jetbrains.kotlin.cli.common.CLITool$Companion.doMainNoExit(CLITool.kt:160)
            at org.jetbrains.kotlin.cli.common.CLITool$Companion.doMain(CLITool.kt:151)
            at org.jetbrains.kotlin.cli.bc.K2Native$Companion$main$1.invoke(K2Native.kt:169)
            at org.jetbrains.kotlin.cli.bc.K2Native$Companion$main$1.invoke(K2Native.kt:166)
            at org.jetbrains.kotlin.backend.konan.util.UtilKt.profileIf(util.kt:33)
            at org.jetbrains.kotlin.backend.konan.util.UtilKt.profile(util.kt:28)
            at org.jetbrains.kotlin.cli.bc.K2Native$Companion.main(K2Native.kt:168)
            at org.jetbrains.kotlin.cli.bc.K2NativeKt.main(K2Native.kt:174)
            at org.jetbrains.kotlin.cli.utilities.MainKt.main(main.kt:46)
    Caused by: java.lang.RuntimeException: Cannot download dependency: http://download.jetbrains.com/kotlin/native/msys2-mingw-w64-x86_64-gcc-6.3.0-clang-llvm-3.9.1-windows-x86-64.zip
            at org.jetbrains.kotlin.konan.DependencyDownloader.download(DependencyDownloader.kt:166)
            at org.jetbrains.kotlin.konan.DependencyDownloader.processDependency(DependencyDownloader.kt:86)
            at org.jetbrains.kotlin.konan.DependencyDownloader.run(DependencyDownloader.kt:178)
            at org.jetbrains.kotlin.konan.Helper0.run(Helper0.kt:31)
            at org.jetbrains.kotlin.cli.bc.K2NativeKt.maybeExecuteHelper(K2Native.kt:48)
            ... 17 more
    Caused by: java.io.IOException: Server returned HTTP response code: 403 for URL: http://download-cf.jetbrains.com/kotlin/native/msys2-mingw-w64-x86_64-gcc-6.3.0-clang-llvm-3.9.1-windows-x86-64.zip
            at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1876)
            at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1474)
            at java.net.URL.openStream(URL.java:1045)
            at org.jetbrains.kotlin.konan.DependencyDownloader$download$1.invoke(DependencyDownloader.kt:141)
            at org.jetbrains.kotlin.konan.DependencyDownloader$download$1.invoke(DependencyDownloader.kt:26)
            at kotlin.concurrent.ThreadsKt$thread$thread$1.run(Thread.kt:18)
    
  3. Zack says:

    June 23, 2017

    Where did ‘or’ and ‘and’ keywords come from? Did I miss an announcement? Are || and && being switched to bitwise comparisons?

    • João Vitor Verona Biazibetti says:

      June 23, 2017

      && and II are used for boolean logic, while ‘and’ and ‘or’ are used for bitwise comparisons (and, also, they can be overloaded).

      • Zack says:

        June 23, 2017

        Is this in Kotlin 1.1?

        • Andrei Mishchenko says:

          June 23, 2017

          No, it’s been in Kotlin even before 1.0

          • Zack says:

            June 23, 2017

            Wow, I don’t know how I’ve never seen this before, thanks.

        • Restioson says:

          June 23, 2017

          While I can’t speak for earlier versions, Kotlin 1.1 uses and and or for bitwise operations.

  4. Kotlin/Native v0.3 发布,将 Kotlin 编译成机器码 says:

    June 23, 2017

    […] 完整更新信息请查看发行说明。 […]

  5. Kotlin/Native läuft jetzt auch auf Windows - JAXenter says:

    June 23, 2017

    […] Plattformen einfach ergänzen. So sollen noch verschiedene Linuxderivate bald folgen. Mit der Version 0.3 kommt jetzt der Support für Windows sowohl als Compilation Host als auch als Zielplattform. Auch […]

  6. Benny says:

    June 23, 2017

    Wow, Apple ( Swift ) can learn a thing or two from jetbrains.

  7. Benny says:

    June 23, 2017

    From my understanding the klib does not support dynamic loading?

    • Nikolay Igotti says:

      June 23, 2017

      Yes, .klib is intended as mechanism of compile-time linking, not the runtime one.

      • Benny says:

        June 24, 2017

        Is there going to be a native run time version in the future?

        • Nikolay Igotti says:

          June 24, 2017

          Do not think so. For dynamic loading in runtime platform mechanisms, such as shared objects (.so) or dynamic libraries (.dll) could be used. In general, Kotlin/Native adopts closed world approach, so if you need truly pluggable architecture, maybe Kotlin/JVM could be a better fit. But surely, nothing prevents creating shared objects from Kotlin/Native and using platform mechanisms to do load them.

  8. Nikolay Igotti says:

    June 23, 2017

    Yes, sorry for inconvenience, fixed version was uploaded.

  9. Cyparu says:

    June 23, 2017

    @moderator: What happened with my win32 comments ?

    • Nikolay Igotti says:

      June 24, 2017

      I have removed this thread of discussion, to avoid unneeded clobber. It was a typo in distributive, which shall be fixed by now. Could you please check that it is no longer a problem? Thanks for reporting this issue!

      • Sean Flanigan says:

        June 25, 2017

        Well I’m glad Cyparu asked, because I had no idea it had been fixed.

        The win32 sample seems to work now, thanks!

  10. bxq says:

    July 9, 2017

    I try to build samples and the following error occurs:

    C:\prj\KotlinNativeWindows\samples>gradle build –stacktrace
    FAILURE: Build failed with an exception.

    What went wrong:
    Execution failed for task ‘:concurrent:compileCpp’.

    A problem occurred starting process ‘command ‘./buildCpp.sh”

    Try:
    Run with –info or –debug option to get more log output.
    Exception is:
    org.gradle.api.tasks.TaskExecutionException: Execution failed for task ‘:concurrent:compileCpp’.
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:100)
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(ExecuteActionsTaskExecuter.java:70)
    at org.gradle.api.internal.tasks.execution.SkipCachedTaskExecuter.execute(SkipCachedTaskExecuter.java:101)
    at org.gradle.api.internal.tasks.execution.SkipUpToDateTaskExecuter.execute(SkipUpToDateTaskExecuter.java:64)
    at org.gradle.api.internal.tasks.execution.ResolveTaskOutputCachingStateExecuter.execute(ResolveTaskOutputCachingStateExecuter.java:54)
    at org.gradle.api.internal.tasks.execution.ResolveBuildCacheKeyExecuter.execute(ResolveBuildCacheKeyExecuter.java:60)
    at org.gradle.api.internal.tasks.execution.ValidatingTaskExecuter.execute(ValidatingTaskExecuter.java:58)
    at org.gradle.api.internal.tasks.execution.SkipEmptySourceFilesTaskExecuter.execute(SkipEmptySourceFilesTaskExecuter.java:88)
    at org.gradle.api.internal.tasks.execution.ResolveTaskArtifactStateTaskExecuter.execute(ResolveTaskArtifactStateTaskExecuter.java:52)
    at org.gradle.api.internal.tasks.execution.SkipTaskWithNoActionsExecuter.execute(SkipTaskWithNoActionsExecuter.java:52)
    at org.gradle.api.internal.tasks.execution.SkipOnlyIfTaskExecuter.execute(SkipOnlyIfTaskExecuter.java:54)
    at org.gradle.api.internal.tasks.execution.ExecuteAtMostOnceTaskExecuter.execute(ExecuteAtMostOnceTaskExecuter.java:43)
    at org.gradle.api.internal.tasks.execution.CatchExceptionTaskExecuter.execute(CatchExceptionTaskExecuter.java:34)
    at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker$1.run(DefaultTaskGraphExecuter.java:242)
    at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:317)
    at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:309)
    at org.gradle.internal.progress.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:185)
    at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:95)
    at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker.execute(DefaultTaskGraphExecuter.java:235)
    at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker.execute(DefaultTaskGraphExecuter.java:224)
    at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker.processTask(DefaultTaskPlanExecutor.java:121)
    at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker.access$200(DefaultTaskPlanExecutor.java:77)
    at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker$1.execute(DefaultTaskPlanExecutor.java:102)
    at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker$1.execute(DefaultTaskPlanExecutor.java:96)
    at org.gradle.execution.taskgraph.DefaultTaskExecutionPlan.execute(DefaultTaskExecutionPlan.java:612)
    at org.gradle.execution.taskgraph.DefaultTaskExecutionPlan.executeWithTask(DefaultTaskExecutionPlan.java:567)
    at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker.run(DefaultTaskPlanExecutor.java:96)
    at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:63)
    at org.gradle.internal.concurrent.StoppableExecutorImpl$1.run(StoppableExecutorImpl.java:46)
    at org.gradle.internal.concurrent.ThreadFactoryImpl$ManagedThreadRunnable.run(ThreadFactoryImpl.java:55)
    Caused by: org.gradle.process.internal.ExecException: A problem occurred starting process ‘command ‘./buildCpp.sh”
    at org.gradle.process.internal.DefaultExecHandle.setEndStateInfo(DefaultExecHandle.java:199)
    at org.gradle.process.internal.DefaultExecHandle.failed(DefaultExecHandle.java:330)
    at org.gradle.process.internal.ExecHandleRunner.run(ExecHandleRunner.java:86)
    at org.gradle.internal.operations.BuildOperationIdentifierPreservingRunnable.run(BuildOperationIdentifierPreservingRunnable.java:39)
    … 3 more
    Caused by: net.rubygrapefruit.platform.NativeException: Could not start ‘./buildCpp.sh’
    at net.rubygrapefruit.platform.internal.DefaultProcessLauncher.start(DefaultProcessLauncher.java:27)
    at net.rubygrapefruit.platform.internal.WindowsProcessLauncher.start(WindowsProcessLauncher.java:22)
    at net.rubygrapefruit.platform.internal.WrapperProcessLauncher.start(WrapperProcessLauncher.java:36)
    at org.gradle.process.internal.ExecHandleRunner.run(ExecHandleRunner.java:68)
    … 4 more
    Caused by: java.io.IOException: Cannot run program “./buildCpp.sh” (in directory “C:\prj\root-experiment\KotlinNativeWindows\samples\concurrent”): CreateProcess error=2, The system cannot find the file specified
    at net.rubygrapefruit.platform.internal.DefaultProcessLauncher.start(DefaultProcessLauncher.java:25)
    … 7 more
    Caused by: java.io.IOException: CreateProcess error=2, The system cannot find the file specified
    … 8 more

    BUILD FAILED in 4s

  11. bxq says:

    July 9, 2017

    When I try to build in ‘sample\concurrent’ directory, I get the following error:

    C:\prj\root-experiment\KotlinNativeWindows\samples\concurrent>gradle build –stacktrace

    FAILURE: Build failed with an exception.

    What went wrong:
    Execution failed for task ‘:concurrent:compileCpp’.

    A problem occurred starting process ‘command ‘./buildCpp.sh”

    Try:
    Run with –info or –debug option to get more log output.
    Exception is:
    org.gradle.api.tasks.TaskExecutionException: Execution failed for task ‘:concurrent:compileCpp’.
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:100)
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(ExecuteActionsTaskExecuter.java:70)
    at org.gradle.api.internal.tasks.execution.SkipCachedTaskExecuter.execute(SkipCachedTaskExecuter.java:101)
    at org.gradle.api.internal.tasks.execution.SkipUpToDateTaskExecuter.execute(SkipUpToDateTaskExecuter.java:64)
    at org.gradle.api.internal.tasks.execution.ResolveTaskOutputCachingStateExecuter.execute(ResolveTaskOutputCachingStateExecuter.java:54)
    at org.gradle.api.internal.tasks.execution.ResolveBuildCacheKeyExecuter.execute(ResolveBuildCacheKeyExecuter.java:60)
    at org.gradle.api.internal.tasks.execution.ValidatingTaskExecuter.execute(ValidatingTaskExecuter.java:58)
    at org.gradle.api.internal.tasks.execution.SkipEmptySourceFilesTaskExecuter.execute(SkipEmptySourceFilesTaskExecuter.java:88)
    at org.gradle.api.internal.tasks.execution.ResolveTaskArtifactStateTaskExecuter.execute(ResolveTaskArtifactStateTaskExecuter.java:52)
    at org.gradle.api.internal.tasks.execution.SkipTaskWithNoActionsExecuter.execute(SkipTaskWithNoActionsExecuter.java:52)
    at org.gradle.api.internal.tasks.execution.SkipOnlyIfTaskExecuter.execute(SkipOnlyIfTaskExecuter.java:54)
    at org.gradle.api.internal.tasks.execution.ExecuteAtMostOnceTaskExecuter.execute(ExecuteAtMostOnceTaskExecuter.java:43)
    at org.gradle.api.internal.tasks.execution.CatchExceptionTaskExecuter.execute(CatchExceptionTaskExecuter.java:34)
    at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker$1.run(DefaultTaskGraphExecuter.java:242)
    at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:317)
    at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:309)
    at org.gradle.internal.progress.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:185)
    at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:95)
    at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker.execute(DefaultTaskGraphExecuter.java:235)
    at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker.execute(DefaultTaskGraphExecuter.java:224)
    at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker.processTask(DefaultTaskPlanExecutor.java:121)
    at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker.access$200(DefaultTaskPlanExecutor.java:77)
    at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker$1.execute(DefaultTaskPlanExecutor.java:102)
    at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker$1.execute(DefaultTaskPlanExecutor.java:96)
    at org.gradle.execution.taskgraph.DefaultTaskExecutionPlan.execute(DefaultTaskExecutionPlan.java:612)
    at org.gradle.execution.taskgraph.DefaultTaskExecutionPlan.executeWithTask(DefaultTaskExecutionPlan.java:567)
    at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker.run(DefaultTaskPlanExecutor.java:96)
    at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:63)
    at org.gradle.internal.concurrent.StoppableExecutorImpl$1.run(StoppableExecutorImpl.java:46)
    at org.gradle.internal.concurrent.ThreadFactoryImpl$ManagedThreadRunnable.run(ThreadFactoryImpl.java:55)
    Caused by: org.gradle.process.internal.ExecException: A problem occurred starting process ‘command ‘./buildCpp.sh”
    at org.gradle.process.internal.DefaultExecHandle.setEndStateInfo(DefaultExecHandle.java:199)
    at org.gradle.process.internal.DefaultExecHandle.failed(DefaultExecHandle.java:330)
    at org.gradle.process.internal.ExecHandleRunner.run(ExecHandleRunner.java:86)
    at org.gradle.internal.operations.BuildOperationIdentifierPreservingRunnable.run(BuildOperationIdentifierPreservingRunnable.java:39)
    … 3 more
    Caused by: net.rubygrapefruit.platform.NativeException: Could not start ‘./buildCpp.sh’
    at net.rubygrapefruit.platform.internal.DefaultProcessLauncher.start(DefaultProcessLauncher.java:27)
    at net.rubygrapefruit.platform.internal.WindowsProcessLauncher.start(WindowsProcessLauncher.java:22)
    at net.rubygrapefruit.platform.internal.WrapperProcessLauncher.start(WrapperProcessLauncher.java:36)
    at org.gradle.process.internal.ExecHandleRunner.run(ExecHandleRunner.java:68)
    … 4 more
    Caused by: java.io.IOException: Cannot run program “./buildCpp.sh” (in directory “C:\prj\root-experiment\KotlinNativeWindows\samples\concurrent”): CreateProcess error=193, %1 is not a valid Win32 application
    at net.rubygrapefruit.platform.internal.DefaultProcessLauncher.start(DefaultProcessLauncher.java:25)
    … 7 more
    Caused by: java.io.IOException: CreateProcess error=193, %1 is not a valid Win32 application
    … 8 more

    BUILD FAILED in 4s