跳到主要内容

Kotlin/Native 目标平台支持

Kotlin/Native 编译器支持大量的不同目标平台,尽管很难为所有目标平台提供相同级别的支持。本文档描述了 Kotlin/Native 支持的目标平台,并根据编译器对它们的支持程度将其分为几个等级。

备注

我们可以根据实际情况调整等级数量、支持的目标平台列表及其特性。

请注意等级表格中使用的以下术语:

  • Gradle target name 是 Kotlin 多平台 Gradle 插件中用于启用目标平台的目标名称

  • Target triple 是一个目标名称,其结构符合 <architecture>-<vendor>-<system>-<abi> 规范,通常被编译器使用。

  • Running tests 指示在 Gradle 和 IDE 中对运行测试的开箱即用支持。

    这仅在特定目标平台的原生主机上可用。 例如,您只能在 macOS x86-64 主机上运行 macosX64iosX64 测试。

Tier 1

  • 该目标平台在 CI 上会定期进行编译和运行测试。
  • 我们在编译器版本之间提供源代码和二进制兼容性
Gradle target nameTarget tripleRunning testsDescription
Apple macOS hosts only:
macosX64x86_64-apple-macosApple macOS on x86_64 platforms
macosArm64aarch64-apple-macosApple macOS on Apple Silicon platforms
iosSimulatorArm64aarch64-apple-ios-simulatorApple iOS simulator on Apple Silicon platforms
iosX64x86_64-apple-ios-simulatorApple iOS simulator on x86-64 platforms
iosArm64aarch64-apple-iosApple iOS and iPadOS on ARM64 platforms

Tier 2

  • 该目标平台在 CI 上会定期进行编译测试,但可能不会自动测试其运行能力。
  • 我们会尽最大努力在编译器版本之间提供源代码和二进制兼容性
Gradle target nameTarget tripleRunning testsDescription
linuxX64x86_64-unknown-linux-gnuLinux on x86_64 platforms
linuxArm64aarch64-unknown-linux-gnuLinux on ARM64 platforms
Apple macOS hosts only:
watchosSimulatorArm64aarch64-apple-watchos-simulatorApple watchOS simulator on Apple Silicon platforms
watchosX64x86_64-apple-watchos-simulatorApple watchOS 64-bit simulator on x86_64 platforms
watchosArm32armv7k-apple-watchosApple watchOS on ARM32 platforms
watchosArm64arm64_32-apple-watchosApple watchOS on ARM64 platforms with ILP32
tvosSimulatorArm64aarch64-apple-tvos-simulatorApple tvOS simulator on Apple Silicon platforms
tvosX64x86_64-apple-tvos-simulatorApple tvOS simulator on x86_64 platforms
tvosArm64aarch64-apple-tvosApple tvOS on ARM64 platforms

Tier 3

  • 不保证该目标平台会在 CI 上进行测试。
  • 我们不能保证不同编译器版本之间的源代码和二进制兼容性,尽管这些目标平台的此类更改非常罕见。
Gradle target nameTarget tripleRunning testsDescription
androidNativeArm32arm-unknown-linux-androideabiAndroid NDK on ARM32 platforms
androidNativeArm64aarch64-unknown-linux-androidAndroid NDK on ARM64 platforms
androidNativeX86i686-unknown-linux-androidAndroid NDK on x86 platforms
androidNativeX64x86_64-unknown-linux-androidAndroid NDK on x86_64 platforms
mingwX64x86_64-pc-windows-gnu64-bit Windows 7 and later using MinGW compatibility layer
Apple macOS hosts only:
watchosDeviceArm64aarch64-apple-watchosApple watchOS on ARM64 platforms

linuxArm32Hfp 目标平台已被弃用,将在未来的版本中删除。

对于库作者

我们不建议库作者测试比 Kotlin/Native 编译器更多的目标平台或提供更严格的保证。在考虑对原生目标平台的支持时,可以使用以下方法:

  • 支持第 1、2 和 3 级中的所有目标平台。
  • 定期测试第 1 级和第 2 级中支持开箱即用运行测试的目标平台。

Kotlin 团队在官方 Kotlin 库中使用了这种方法,例如 kotlinx.coroutineskotlinx.serialization