|
1 | 1 | [//]: # (title: Platform libraries)
|
2 | 2 |
|
3 |
| -To provide access to user's native operating system services, |
4 |
| -Kotlin/Native distribution includes a set of prebuilt libraries specific to |
5 |
| -each target. We call them **Platform Libraries**. |
| 3 | +To provide access to native services of operating systems, the Kotlin/Native distribution includes a set of prebuilt |
| 4 | +libraries specific to each target. These are called _platform libraries_. |
6 | 5 |
|
7 |
| -### POSIX bindings |
| 6 | +The packages from platform libraries are available by default. You don't need to specify additional link options to use |
| 7 | +them. The Kotlin/Native compiler automatically detects which platform libraries are accessed and links the necessary ones. |
8 | 8 |
|
9 |
| -For all Unix- or Windows-based targets (including Android and |
10 |
| -iOS targets) we provide the POSIX platform lib. It contains bindings |
11 |
| -to platform's implementation of the [POSIX standard](https://en.wikipedia.org/wiki/POSIX). |
| 9 | +However, platform libraries in the compiler distribution are merely wrappers and bindings to the native libraries. That |
| 10 | +means you need to install native libraries themselves (`.so`, `.a`, `.dylib`, `.dll`, and so on) on your local machine. |
12 | 11 |
|
13 |
| -To use the library, just import it: |
| 12 | +## POSIX bindings |
| 13 | + |
| 14 | +Kotlin provides the POSIX platform library for all UNIX- and Windows-based targets, including Android and iOS. |
| 15 | +These platform libraries contain bindings to the platform's implementation, which follows the [POSIX standard](https://en.wikipedia.org/wiki/POSIX). |
| 16 | + |
| 17 | +To use the library, import it into your project: |
14 | 18 |
|
15 | 19 | ```kotlin
|
16 | 20 | import platform.posix.*
|
17 | 21 | ```
|
18 | 22 |
|
19 |
| -The only target for which it is not available is [WebAssembly](https://en.wikipedia.org/wiki/WebAssembly). |
| 23 | +> The `platform.posix` contents differ across platforms because of variations in POSIX implementations. |
| 24 | +> |
| 25 | +{style="note"} |
| 26 | + |
| 27 | +You can explore the contents of the `posix.def` file for each supported platform here: |
| 28 | + |
| 29 | +* [iOS](https://github.com/JetBrains/kotlin/tree/master/kotlin-native/platformLibs/src/platform/ios/posix.def) |
| 30 | +* [macOS](https://github.com/JetBrains/kotlin/tree/master/kotlin-native/platformLibs/src/platform/osx/posix.def) |
| 31 | +* [tvOS](https://github.com/JetBrains/kotlin/tree/master/kotlin-native/platformLibs/src/platform/tvos/posix.def) |
| 32 | +* [watchOS](https://github.com/JetBrains/kotlin/tree/master/kotlin-native/platformLibs/src/platform/watchos/posix.def) |
| 33 | +* [Linux](https://github.com/JetBrains/kotlin/tree/master/kotlin-native/platformLibs/src/platform/linux/posix.def) |
| 34 | +* [Windows (MinGW)](https://github.com/JetBrains/kotlin/tree/master/kotlin-native/platformLibs/src/platform/mingw/posix.def) |
| 35 | +* [Android](https://github.com/JetBrains/kotlin/tree/master/kotlin-native/platformLibs/src/platform/android/posix.def) |
| 36 | + |
| 37 | +The POSIX platform library is not available for the [WebAssembly](wasm-overview.md) target. |
| 38 | + |
| 39 | +## Popular native libraries |
| 40 | + |
| 41 | +Kotlin/Native provides bindings for various popular native libraries that are commonly used on different platforms, |
| 42 | +such as OpenGL, zlib, and Foundation. |
| 43 | + |
| 44 | +On Apple platforms, the `objc` library is included to enable [interoperability with Objective-C](native-objc-interop.md) |
| 45 | +APIs. |
| 46 | + |
| 47 | +You can explore the native libraries available for Kotlin/Native targets in your compiler distribution, |
| 48 | +depending on your setup: |
| 49 | + |
| 50 | +* If you [installed a standalone Kotlin/Native compiler](native-get-started.md#download-and-install-the-compiler): |
| 51 | + |
| 52 | + 1. Go to the unpacked archive with the compiler distribution, for example, `kotlin-native-prebuilt-macos-aarch64-2.1.0`. |
| 53 | + 2. Navigate to the `klib/platform` directory. |
| 54 | + 3. Choose the folder with the corresponding target. |
| 55 | + |
| 56 | +* If you use the Kotlin plugin in your IDE (bundled with IntelliJ IDEA and Android Studio): |
| 57 | + |
| 58 | + 1. In your command line tool, run the following to navigate to the `.konan` folder: |
| 59 | + |
| 60 | + <tabs> |
| 61 | + <tab title="macOS and Linux"> |
20 | 62 |
|
21 |
| -Note that the content of `platform.posix` is NOT identical on |
22 |
| -different platforms, in the same way as different POSIX implementations |
23 |
| -are a little different. |
| 63 | + ```none |
| 64 | + ~/.konan/ |
| 65 | + ``` |
24 | 66 |
|
25 |
| -### Popular native libraries |
| 67 | + </tab> |
| 68 | + <tab title="Windows"> |
26 | 69 |
|
27 |
| -There are many more platform libraries available for host and |
28 |
| -cross-compilation targets. Kotlin/Native distribution provides access to |
29 |
| -OpenGL, zlib and other popular native libraries on |
30 |
| -applicable platforms. |
| 70 | + ```none |
| 71 | + %\USERPROFILE%\.konan |
| 72 | + ``` |
31 | 73 |
|
32 |
| -On Apple platforms, `objc` library is provided for interoperability with [Objective-C](https://en.wikipedia.org/wiki/Objective-C). |
| 74 | + </tab> |
| 75 | + </tabs> |
33 | 76 |
|
34 |
| -Inspect the contents of `dist/klib/platform/$target` of the distribution for the details. |
| 77 | + 2. Open the Kotlin/Native compiler distribution, for example, `kotlin-native-prebuilt-macos-aarch64-2.1.0`. |
| 78 | + 3. Navigate to the `klib/platform` directory. |
| 79 | + 4. Choose the folder with the corresponding target. |
35 | 80 |
|
36 |
| -## Availability by default |
| 81 | +> If you'd like to explore the definition file for each supported platform library: in the compiler distribution folder, |
| 82 | +> navigate to the `konan/platformDef` directory and choose the necessary target. |
| 83 | +> |
| 84 | +{style="tip"} |
37 | 85 |
|
38 |
| -The packages from platform libraries are available by default. No |
39 |
| -special link flags need to be specified to use them. Kotlin/Native |
40 |
| -compiler automatically detects which of the platform libraries have |
41 |
| -been accessed and automatically links the needed libraries. |
| 86 | +## What's next |
42 | 87 |
|
43 |
| -On the other hand, the platform libs in the distribution are merely |
44 |
| -just wrappers and bindings to the native libraries. That means the |
45 |
| -native libraries themselves (`.so`, `.a`, `.dylib`, `.dll` etc) |
46 |
| -should be installed on the machine. |
| 88 | +[Learn more about interoperability with Swift/Objective-C](native-objc-interop.md) |
0 commit comments