Kotlin in WebAssembly
Kotlin, like .NET, has an interesting history with WebAssembly.
Kotlin Wasm
A few years ago, the Kotlin team introduced experimental WebAssembly support for the browser: A Kotlin Native wasm32
LLVM-based compiler target.
However, in 2019 they began a rewrite of the feature.
In late 2020, they demoed the upcoming version, called “Kotlin/Wasm”.
In early 2023, the new version was released as experimental, and required the Wasm runtime to support the then-experimental Wasm-GC proposal. Kotlin Native wasm32
target was deprecated.
In late 2023, Wasm-GC was enabled by default in Chrome and Firefox, and Kotlin/Wasm went Alpha.
Kotlin on JRE
Kotlin compiled to Java bytecode can be executed by the Java-to-Webassembly tools.
Uses
Kotlin/Wasm can be used in browsers. At the time of this writing, KoWasm (see below) has WASI support. But because it requires the new Wasm-GC extension, Spin will not support it until Wasmtime supports Wasm-GC. Therefore, we do not know whether Kotlin can be used to create Fermyon Cloud applications.
Available Implementations
- Kotlin/Wasm is in Alpha, but requires a version of the Wasm runtime that supports Wasm Garbage Collection (Wasm-GC).
- Sebastian Deleuze is working on WASI Kotlin support as KoWasm.
Learn More
Here are some great resources:
- Official Kotlin/Wasm page
- Official GitHub repository, containing a collection of examples demonstrating how to use Kotlin with WebAssembly.
- Sebastian Deleuze’s excellent article on the potential for Wasm GC and Kotlin (covering Kotlin 1.8.20 Beta)
- A Feb. 2023 Devclass blog post covering the new Kotlin Wasm compiler
- JetBrains’ Kotlin for WebAssembly Goes Alpha announcement.
- The official preview video of the next-gen Wasm compiler.
- For the latest feature plan, the Kotlin Roadmap is a good source of information.
- Wasmtime tracking issue for Wasm GC