README.md 2.9 KB
Newer Older
H
Hadi Hariri 已提交
1
[![official project](http://jb.gg/badges/official.svg)](https://confluence.jetbrains.com/display/ALL/JetBrains+on+GitHub)
2
[![version](https://img.shields.io/badge/dynamic/json.svg?color=orange&label=latest%20version&query=%24.tag_name&url=https%3A%2F%2Fgithub.com%2FJetBrains%2Fkotlin-native%2Freleases%2Flatest)](https://github.com/JetBrains/kotlin-native/releases/latest)
N
Nikolay Igotti 已提交
3
# Kotlin/Native  #
N
Nikolay Igotti 已提交
4

5 6
_Kotlin/Native_ is an LLVM backend for the Kotlin compiler, runtime
implementation, and native code generation facility using the LLVM toolchain.
N
Nikolay Igotti 已提交
7

N
Nikolay Igotti 已提交
8
 _Kotlin/Native_ is primarily designed to allow compilation for platforms where
9
virtual machines are not desirable or possible (such as iOS or embedded targets),
M
Marcin Kraszewski 已提交
10 11
or where a developer is willing to produce a reasonably-sized self-contained program
without the need to ship an additional execution runtime.
N
Nikolay Igotti 已提交
12

13
Prerequisites:
14
*   install JDK for your platform, instead of JRE. The build requires ```tools.jar```, which is not included in JRE;
S
Sergey Bogolepov 已提交
15
*   on macOS install Xcode 11 (Xcode 12.0 is required to compile Kotlin/Native from sources)
N
Nikolay Igotti 已提交
16
*   on Fedora 26+ ```yum install ncurses-compat-libs``` may be needed
N
Nekoyue 已提交
17
*   on recent Ubuntu ```apt install libncurses5``` is needed
18

19
To compile from sources use following steps:
N
Nikolay Igotti 已提交
20

21
First, download dependencies:
S
SvyatoslavScherbina 已提交
22

23 24
	./gradlew dependencies:update

25
Then, build the compiler and libraries:
26

27
	./gradlew bundle
S
SvyatoslavScherbina 已提交
28

29 30
To build with experimental targets support compile with `-Porg.jetbrains.kotlin.native.experimentalTargets`.

31
The build can take about an hour on a Macbook Pro.
32
To run a shorter build with only the host compiler and libraries, run:
N
Nikolay Igotti 已提交
33

34
    ./gradlew dist distPlatformLibs
N
Nikolay Igotti 已提交
35

36 37 38 39 40
To include Kotlin compiler in [composite build](https://docs.gradle.org/current/userguide/composite_builds.html) and build
against it, use the `kotlinProjectPath` project property:

    ./gradlew dist -PkotlinProjectPath=path/to/kotlin/project

41 42
It's possible to include in a composite build both Kotlin compiler and Kotlin/Native Shared simultaneously.

43
After that, you should be able to compile your programs like this:
S
SvyatoslavScherbina 已提交
44

N
Nikolay Igotti 已提交
45 46
    export PATH=./dist/bin:$PATH
	kotlinc hello.kt -o hello
N
Nikolay Igotti 已提交
47

48
For an optimized compilation, use `-opt`:
49

N
Nikolay Igotti 已提交
50
	kotlinc hello.kt -o hello -opt
51

52
For tests, use:
53

54
	./gradlew backend.native:tests:run
55

56
To generate interoperability stubs, create a library definition file
57
(refer to [`samples/tetris/.../sdl.def`](https://github.com/JetBrains/kotlin-native/blob/master/samples/tetris/src/nativeInterop/cinterop/sdl.def)), and run the `cinterop` tool like this:
I
Ilya Matveev 已提交
58

59
    cinterop -def lib.def
I
Ilya Matveev 已提交
60

61
See the provided [samples](https://github.com/JetBrains/kotlin-native/tree/master/samples) and [`INTEROP.md`](https://github.com/JetBrains/kotlin-native/blob/master/INTEROP.md) for more details.
N
Nikolay Igotti 已提交
62

63 64
The Interop tool generates a library in the `.klib` library format. See [`LIBRARIES.md`](https://github.com/JetBrains/kotlin-native/blob/master/LIBRARIES.md)
for more details on this file format.