Cross-compile linuxArm64 tests on x86_64 (was: failing on arm64 host) - #9
Merged
Conversation
The "Linux arm64 tests" matrix entries ran on ubuntu-24.04-arm and
failed at Gradle configuration time with
"Unknown host target: linux aarch64": Kotlin/Native (Konan) does not
publish a linux-aarch64 host toolchain in any version, so HostManager
cannot determine the host and Gradle cannot configure :benchmarks or
any project that declares a Kotlin/Native target.
> A problem occurred configuring project ':benchmarks'.
> Caused by: org.jetbrains.kotlin.konan.target.TargetSupportException:
> Unknown host target: linux aarch64
Running the aarch64 test binaries is also not possible from the KGP
DSL: KotlinMultiplatformTargetPresetSetupAction only registers a host
test-run task (linuxArm64Test) for {LINUX_X64, MACOS_X64, MACOS_ARM64,
MINGW_X64}. LINUX_ARM64 instantiates a plain KotlinNativeTarget with no
test-run, so the linuxArm64Test task never exists on any host — the CI
invocation :core:linuxArm64Test would fail with "task not found" even
with the Konan host problem worked around.
Move the matrix entries onto ubuntu-24.04 (x86_64), where Konan's host
is supported, and cross-compile the linuxArm64 test compilation instead
of running it: :core:compileTestKotlinLinuxArm64 (and the five sibling
modules), plus :tck:compileTestKotlinLinuxArm64 in pinned conformance.
This validates that every module's commonTest/linuxArm64 source
compiles against the aarch64 Kotlin/Native toolchain on every PR,
catching target-specific signature and API errors, without depending on
a host that does not exist.
Runtime execution of aarch64 test binaries (and linuxArm64 benchmarks,
which kotlinx-benchmark likewise does not register on a non-matching
host) is out of scope; tracked upstream as KT-36871.
Verified locally:
./gradlew :core:compileTestKotlinLinuxArm64 :tck:compileTestKotlinLinuxArm64
-> BUILD SUCCESSFUL (cross-compiles against the linuxArm64 klib toolchain)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The `Linux arm64 tests` matrix entries (in `ci.yml`) and `Linux arm64 Native` (in `pinned-conformance.yml`) fail at Gradle configuration time:
```
Root cause: Kotlin/Native (Konan) does not publish a linux-aarch64 host toolchain in any version. `HostManager` cannot determine the host on `ubuntu-24.04-arm`, so Gradle cannot configure `:benchmarks` (or any project declaring a K/N target). This blocks every gradle command on that runner, not just the arm64 tests.
Why "just run linuxArm64Test" is not possible
Even if the Konan host problem were worked around (QEMU on x86_64, etc.), the `linuxArm64Test` task does not exist on any host. `KotlinMultiplatformTargetPresetSetupAction` only registers a host test-run task for `{LINUX_X64, MACOS_X64, MACOS_ARM64, MINGW_X64}`. `LINUX_ARM64` instantiates a plain `KotlinNativeTarget` with no test-run, so `tasks.register("linuxArm64Test", ...)` is never called. The CI invocation `:core:linuxArm64Test` would fail with "task not found" regardless of host. (kotlinx-benchmark has the same limitation for `linuxArm64Benchmark`.)
Fix
Move the matrix entries onto `ubuntu-24.04` (x86_64, where Konan's host is supported) and cross-compile the linuxArm64 test compilation instead of running it:
```
:core:compileTestKotlinLinuxArm64 (was :core:linuxArm64Test)
:snapshot:compileTestKotlinLinuxArm64
:wasi:compileTestKotlinLinuxArm64
:bindgen-api:compileTestKotlinLinuxArm64
:bindgen-runtime:compileTestKotlinLinuxArm64
:tck:compileTestKotlinLinuxArm64
```
This validates that every module's `commonTest`/`linuxArm64` source compiles against the aarch64 Kotlin/Native toolchain on every PR — catching target-specific signature/API errors — without depending on a host that does not exist.
What this does NOT cover
Both are tracked upstream as KT-36871 (linux aarch64 host support).
Verification
```
./gradlew :core:compileTestKotlinLinuxArm64 :tck:compileTestKotlinLinuxArm64
-> BUILD SUCCESSFUL
```
All six `compileTestKotlinLinuxArm64` tasks resolve and cross-compile against the linuxArm64 klib toolchain. YAML for both workflows validated.