README.md 3.3 KB
Newer Older
N
Nikolay Igotti 已提交
1
# Kotlin/Native  #
N
Nikolay Igotti 已提交
2

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

N
Nikolay Igotti 已提交
6
 _Kotlin/Native_ is primarily designed to allow compilation for platforms where
7
virtual machines are not desirable or possible (such as iOS or embedded targets),
M
Marcin Kraszewski 已提交
8 9
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 已提交
10

11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
## Using published Kotlin/Native versions

The most complete experience with Kotlin/Native can be achieved by using
[Gradle](https://kotlinlang.org/docs/native-gradle.html),
[IntelliJ IDEA](https://kotlinlang.org/docs/native-get-started.html) or
[Android Studio with KMM plugin](https://kotlinlang.org/docs/mobile/create-first-app.html)
if you target iOS.

If you are interested in using Kotlin/Native for iOS, then
[Kotlin Multiplatform Mobile portal](https://kotlinlang.org/lp/mobile/)
might be useful for you.

Command line compiler is also
[available](https://kotlinlang.org/docs/native-command-line-compiler.html).

More information can be found in the overviews of
[Kotlin/Native](https://kotlinlang.org/docs/native-overview.html)
and [Kotlin Multiplatform](https://kotlinlang.org/docs/multiplatform.html).

On macOS Kotlin/Native requires Xcode 11 or newer.

## Building from source

34
Prerequisites:
35 36 37 38
*   configure Kotlin build as [specified in main readme](../ReadMe.md#build-environment-requirements)
*   at the root directory of the repository,
    create `local.properties` file with `kotlin.native.enabled=true` line
*   on macOS install Xcode 12 or newer
N
Nikolay Igotti 已提交
39
*   on Fedora 26+ ```yum install ncurses-compat-libs``` may be needed
N
Nekoyue 已提交
40
*   on recent Ubuntu ```apt install libncurses5``` is needed
41

42 43 44 45
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:
N
Nikolay Igotti 已提交
46

47
    ./gradlew :kotlin-native:dist
S
SvyatoslavScherbina 已提交
48

49 50
It will build compiler and stdlib for host target, without
[platform libraries](https://kotlinlang.org/docs/native-platform-libs.html).
51

52
To get platform libraries, add `distPlatformLibs` task, e.g.
53

54
    ./gradlew :kotlin-native:dist :kotlin-native:distPlatformLibs
S
SvyatoslavScherbina 已提交
55

56
To run the full build:
57

58
    ./gradlew :kotlin-native:bundle
N
Nikolay Igotti 已提交
59

60 61
This will produce compiler and libraries for all supported targets.
The full build can take about an hour on a Macbook Pro.
N
Nikolay Igotti 已提交
62

63 64 65
After any of the commands above, `./dist` will contain Kotlin/Native distribution.
You can use it like a distribution of
[command-line compiler](https://kotlinlang.org/docs/native-command-line-compiler.html).
66

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

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

72
To compile your programs with command-line compiler, use:
S
SvyatoslavScherbina 已提交
73

74
	./dist/bin/kotlinc-native hello.kt -o hello
N
Nikolay Igotti 已提交
75

76
For an optimized compilation, use `-opt`:
77

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

80
### Interoperability
81

82 83
To import a C or Objective-C library, use `./dist/bin/cinterop` tool.
See the [documentation](https://kotlinlang.org/docs/native-c-interop.html) for more details.
84

85
### Running tests
I
Ilya Matveev 已提交
86

87
For tests, use:
N
Nikolay Igotti 已提交
88

89
	./gradlew :kotlin-native:backend.native:tests:run