Kotlin in WebAssembly
Kotlin, like .NET, has an interesting history with WebAssembly.
Kotlin Native (or Kotlin/Wasm)
A few years ago, the Kotlin Native team introduced WebAssembly support for the browser. 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 reached Beta, but requires the Wasm runtime support the experimental Wasm-GC proposal.
Kotlin on JRE
Kotlin compiled to Java bytecode can be executed by the Java-to-Webassembly tools.
In-browser support for Kotlin has been available for a few years. The new rewrite, though, is set to replace the older implementation. At the time of this writing, KoWasm (see below) has WASI support. But because it still requires the 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.
- Kotlin-Native can be compiled to WebAssembly, but this method is going away.
- The new compiler is in beta, but requires a version of the Wasm runtime that supports (experimental) Wasm Garbage Collection (Wasm-GC).
- Sebastian Deleuze is working on WASI Kotlin support as KoWasm.
Here are some great resources:
- 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 and WebAssembly announcement in Nov. 2021
- A great blog post on the older way of building Kotlin Wasm binaries.
- 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