Skip to content

Fix Kotlin/Wasm bindgen runtime compilation on Kotlin 2.3.21 - #8

Merged
IRus merged 1 commit into
mainfrom
fix/kotlin-2.3.21-bindgen-runtime
Jul 18, 2026
Merged

Fix Kotlin/Wasm bindgen runtime compilation on Kotlin 2.3.21#8
IRus merged 1 commit into
mainfrom
fix/kotlin-2.3.21-bindgen-runtime

Conversation

@IRus

@IRus IRus commented Jul 18, 2026

Copy link
Copy Markdown
Member

Problem

The Kotlin/Wasm 2 compilers × 2 EH encodings CI job fails when building the wasmWasi compatibility fixture pinned to Kotlin 2.3.21:

```
e: KwasmWasmGuestRuntime.kt:5:24 Unresolved reference 'ComponentModelInternalApi'
e: KwasmWasmGuestRuntime.kt:20:27 Unresolved reference 'componentModelRealloc'
e: KwasmWasmGuestRuntime.kt:21:27 Unresolved reference 'freeAllComponentModelReallocAllocatedMemory'

Task :bindgen-api:compileTestKotlinWasmWasi FAILED
```

Root cause

WasmGuestRuntimeRenderer emits a generated guest runtime that referenced kotlin.wasm.unsafe.componentModelRealloc, freeAllComponentModelReallocAllocatedMemory, and the ComponentModelInternalApi opt-in. These symbols only exist in Kotlin 2.4.0+, so the compatibility gate — which deliberately builds the fixture on the previous stable compiler (2.3.21) — could not compile it.

Fix

Replace the Component Model realloc allocator with an equivalent bump allocator built on withScopedMemoryAllocator (present in both 2.4.0 and 2.3.21). The guest allocator now tracks live regions in a map and replays the live prefix before each new allocation so returned pointers stay disjoint from regions the host still owns. The free path drops the freeAllComponentModelReallocAllocatedMemory reset.

Adds a regression assertion that the rendered runtime uses withScopedMemoryAllocator and no longer references componentModelRealloc.

Verification

  • scripts/verify-kotlin-wasm-compiler-compatibility.shBUILD SUCCESSFUL on both rows: Verified Kotlin/Wasm compiler rows: 2.4.0, 2.3.21
  • :bindgen-ksp:test (incl. BindingSourceRendererTest) — green

Note

This addresses only the compiler-compatibility failure. A separate, independent CI failure (Unknown host target: linux aarch64 on the Linux arm64 tests matrix entry) will be handled in a follow-up PR — Konan does not support linux aarch64 as a host, so that matrix entry needs restructuring regardless of this fix.

The KSP-generated guest runtime emitted references to
kotlin.wasm.unsafe.componentModelRealloc,
freeAllComponentModelReallocAllocatedMemory, and the
ComponentModelInternalApi opt-in. These symbols only exist in
Kotlin 2.4.0+, so the compiler-compatibility gate failed to build
the wasmWasi fixture pinned to Kotlin 2.3.21:

  e: KwasmWasmGuestRuntime.kt:5:24 Unresolved reference 'ComponentModelInternalApi'
  e: KwasmWasmGuestRuntime.kt:20:27 Unresolved reference 'componentModelRealloc'
  e: KwasmWasmGuestRuntime.kt:21:27 Unresolved reference 'freeAllComponentModelReallocAllocatedMemory'
  > Task :bindgen-api:compileTestKotlinWasmWasi FAILED

Replace the Component Model realloc allocator with an equivalent
bump allocator built on withScopedMemoryAllocator, which is present
in both Kotlin 2.4.0 and 2.3.21. The guest allocator now tracks
live regions in a map and replays the live prefix before each new
allocation so returned pointers stay disjoint from regions the
host still owns. The free path drops the
freeAllComponentModelReallocAllocatedMemory reset accordingly.

Add a regression assertion that the rendered runtime uses
withScopedMemoryAllocator and no longer references
componentModelRealloc.

Verified locally with scripts/verify-kotlin-wasm-compiler-compatibility.sh
on both Kotlin 2.4.0 and 2.3.21 rows, plus :bindgen-ksp:test.
@IRus
IRus merged commit f15a9c0 into main Jul 18, 2026
12 of 14 checks passed
@IRus
IRus deleted the fix/kotlin-2.3.21-bindgen-runtime branch July 18, 2026 14:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant