tree: 460e7c05bfb1f5fc0eed7cdd5b62d64e965d6de4 [path history] [tgz]
  1. .idea/
  2. backend.native/
  3. build-tools/
  4. cmd/
  5. codestyle/
  6. common/
  7. dependencies/
  8. endorsedLibraries/
  9. gradle/
  10. Interop/
  11. klib/
  12. konan/
  13. libclangext/
  14. libllvmext/
  15. licenses/
  16. llvmDebugInfoC/
  17. performance/
  18. platformLibs/
  19. prepare/
  20. runtime/
  21. samples/
  22. shared/
  23. tools/
  24. utilities/
  25. .clang-format
  26. .editorconfig
  27. .gitignore
  28. _nav_reference.yml
  29. build.gradle
  30. BUILDING_LLVM.md
  31. CHANGELOG.md
  32. CODE_COVERAGE.md
  33. gradle.properties
  34. HACKING.md
  35. NEW_MM.md
  36. README.md
  37. RELEASE_NOTES.md
kotlin-native/README.md

Kotlin/Native

Kotlin/Native is an LLVM backend for the Kotlin compiler, runtime implementation, and native code generation facility using the LLVM toolchain.

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 a developer is willing to produce a reasonably-sized self-contained program without the need to ship an additional execution runtime.

Using published Kotlin/Native versions

The most complete experience with Kotlin/Native can be achieved by using Gradle, IntelliJ IDEA or Android Studio with KMM plugin if you target iOS.

If you are interested in using Kotlin/Native for iOS, then Kotlin Multiplatform Mobile portal might be useful for you.

Command line compiler is also available.

More information can be found in the overviews of Kotlin/Native and Kotlin Multiplatform.

On macOS Kotlin/Native requires Xcode 12.5 or newer.

Building from source

Prerequisites:

  • configure Kotlin build as specified in main readme
  • at the root directory of the repository, create local.properties file with kotlin.native.enabled=true line
  • macOS: Xcode 13.1 or newer
  • Linux: glibc 2.23 or newer
  • Windows:
    • Microsoft C++ build tools for Visual Studio 2019 14.29 or newer
    • Windows SDK 10.0.18362.0 or newer

The commands below should be run from either repository root or this (kotlin-native/) directory. For the latter, :kotlin-native: task name prefix can be omitted.

To compile the basic compiler distribution from sources, run following command:

./gradlew :kotlin-native:dist

It will build compiler and stdlib for host target, without platform libraries.

To get platform libraries, add distPlatformLibs task, e.g.

./gradlew :kotlin-native:dist :kotlin-native:distPlatformLibs

To run the full build:

./gradlew :kotlin-native:bundle

This will produce compiler and libraries for all supported targets. The full build can take about an hour on a Macbook Pro.

After any of the commands above, ./dist will contain Kotlin/Native distribution. You can use it like a distribution of command-line compiler.

Or configure Gradle to use it -- just add the following line to gradle.properties in your Gradle project:

kotlin.native.home=/path/to/kotlin/kotlin-native/dist

To compile your programs with command-line compiler, use:

./dist/bin/kotlinc-native hello.kt -o hello

For an optimized compilation, use -opt:

./dist/bin/kotlinc-native hello.kt -o hello -opt

Interoperability

To import a C or Objective-C library, use ./dist/bin/cinterop tool. See the documentation for more details.

Running tests

For tests, use ./gradlew :native:native.tests:codegenBoxTest and ./gradlew :kotlin-native:backend.native:tests:run.

For more details see Testing.