Skip to content

Commit f4ad60a

Browse files
authored
feat: platform libraries update (#4694)
1 parent c85df6b commit f4ad60a

File tree

5 files changed

+75
-33
lines changed

5 files changed

+75
-33
lines changed

docs/topics/compiler-reference.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@ Include the native bitcode library.
341341

342342
### -no-default-libs
343343

344-
Disable linking user code with the [default platform libraries](native-platform-libs.md) distributed with the compiler.
344+
Disable linking user code with the prebuilt [platform libraries](native-platform-libs.md) distributed with the compiler.
345345

346346
### -nomain
347347

docs/topics/multiplatform/multiplatform-share-on-platforms.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,8 @@ it and call `runBlocking` from a source set that is shared between the JVM and n
6262

6363
## Connect platform-specific libraries
6464

65-
To share more native code without being limited by platform-specific dependencies, connect [platform-specific libraries](native-platform-libs.md).
66-
Libraries shipped with Kotlin/Native (like Foundation, UIKit, and POSIX) are available in shared source sets by default.
65+
To share more native code without being limited by platform-specific dependencies, use [platform libraries](native-platform-libs.md),
66+
like Foundation, UIKit, and POSIX. These libraries are shipped with Kotlin/Native and available in shared source sets by default.
6767

6868
In addition, if you use the [Kotlin CocoaPods Gradle](native-cocoapods.md) plugin in your projects,
6969
you can work with third-party native libraries consumed with the [`cinterop` mechanism](native-c-interop.md).

docs/topics/native/native-definition-file.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ Note that the generated bindings are generally platform-specific, so if you are
258258
the bindings need to be regenerated.
259259

260260
* For host libraries that are not included in the sysroot search paths, headers may be needed.
261-
* For a typical Unix library with a configuration script, the `compilerOpts` will likely contain the output of a
261+
* For a typical UNIX library with a configuration script, the `compilerOpts` will likely contain the output of a
262262
configuration script with the `--cflags` option (maybe without exact paths).
263263
* The output of a configuration script with `--libs` can be passed to the `linkerOpts` property.
264264

docs/topics/native/native-overview.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ static or dynamic [C libraries](native-c-interop.md),
4747
Swift/Objective-C [frameworks](native-objc-interop.md),
4848
graphical engines, and anything else directly from Kotlin/Native.
4949

50-
Kotlin/Native [libraries](native-platform-libs.md) help share Kotlin
50+
Kotlin/Native [platform libraries](native-platform-libs.md) help share Kotlin
5151
code between projects.
5252
POSIX, gzip, OpenGL, Metal, Foundation, and many other popular libraries and Apple frameworks
5353
are pre-imported and included as Kotlin/Native libraries in the compiler package.
Lines changed: 70 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,88 @@
11
[//]: # (title: Platform libraries)
22

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_.
65

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.
88

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.
1211

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:
1418

1519
```kotlin
1620
import platform.posix.*
1721
```
1822

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">
2062

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+
```
2466
25-
### Popular native libraries
67+
</tab>
68+
<tab title="Windows">
2669
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+
```
3173
32-
On Apple platforms, `objc` library is provided for interoperability with [Objective-C](https://en.wikipedia.org/wiki/Objective-C).
74+
</tab>
75+
</tabs>
3376
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.
3580
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"}
3785
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
4287
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

Comments
 (0)