Kotlin/Native is a LLVM backend for the Kotlin compiler. It consists of a machine code generation facility using the LLVM toolchain and a native runtime implementation.
Kotlin/Native is primarily designed to allow compilation for platforms where virtual machines are not desirable or possible (such as iOS or embedded targets), or where the developer needs to produce a reasonably-sized self-contained binary that doesn't require an additional execution runtime.
The Kotlin/Native compiler produces mostly portable (modulo pointer size and target triplet) LLVM bitcode, and as such can easily support any platform, as long as there's an LLVM code generator for the platform. However, as actualy producing native code requires a platform linker and some basic runtime shipped along with the translator, we only support a subset of all possible target platforms. Currently Kotlin/Native is being shipped and tested with support for the following platforms:
- Mac OS X 10.11 and later (x86-64), host and target
- Ubuntu Linux x86-64 (14.04, 16.04 and later), other Linux flavours may work as well, host and target
- Microsoft Windows x86-64 (tested on Windows 7 and Windows 10), host and target
- Apple iOS (arm64), cross-compiled on MacOS X host (
-target iphone
), target, hosted on OS X - Raspberry Pi, cross-compiled on Linux host (
-target raspberrypi
), target, hosted on Linux - Android arm32 and arm64 (
-target android_arm32
and-target android_arm64
), target, hosted on Linux or OS X
Adding support for other target platforms shouldn't be too hard, if LLVM support is available.
To run Kotlin/Native JDK8 for the host platform has to be installed. Note that Java 9 not yet supported.
The language and library version supported by this EAP release mostly match Kotlin 1.1.4. However, there are certain limitations, see section Known Limitations.
Currently Kotlin/Native uses reference counting based memory management scheme with a cycle collection algorithm. Multiple threads could be used, but objects must be explicitly transferred between threads, and same object couldn't be accessed by two threads concurrently.
Kotlin/Native provides efficient interoperability with libraries written in C, and supports automatic generation of Kotlin bindings from a C header file. See the samples coming with the distribution.
Download Kotlin/Native distribution and unpack it. You can run command line compiler with
bin/kotlinc <some_file>.kt <dir_with_kt_files> -o <program_name>
During the first run it will download all the external dependencies, such as LLVM.
To see the list of available flags, run kotlinc -h
.
For documentation on C interoperability stubs see INTEROP.md.
*** DO NOT USE THIS PREVIEW RELEASE FOR ANY PERFORMANCE ANALYSIS ***
This is purely a technology preview of Kotlin/Native technology, and is not yet tuned for benchmarking and competitive analysis of any kind.
The standard library in Kotlin/Native is known to be mostly complete, please report us
missing functionality. Note, that standard Java APIs, such as java.lang.Math
or java.io
is not available in current Kotlin standard library, but using C interoperability, one could
call similar APIs from the POSIX library, see this sample
.
Full reflection and class object references are not implemented. Notice that property delegation (including lazy properties) does work.
Only 64-bit Windows is currently supported as both compilation host and target.
Kotlin/Native supports preliminary source-level debugging on produced executables with lldb
debugger.
Produce your binary with debugging information by specifying -g
Kotlin/Native compiler switch.
Konan plugin accepts enableDebug
project's property, allowing two options for producing binaries with debug
information:
- gradle DSL.
- argument
-PenableDebug=true
in gradle command line.
Start your application with
lldb my_program.kexe
and then
b kfun:main(kotlin.Array<kotlin.String>)
to set breakpoint in main function of your application. Single stepping and step into shall work,
variable inspection partially works (not on val's, var's only).
See DEBUGGING.md