Skip to content

crowforkotlin/wasmline

Repository files navigation

wasmline

Kotlin Multiplatform WebAssembly Plugin Framework · Cross-Platform WASI Execution Runtime

License Kotlin wasmtime AGP Platform WebAssembly

中文文档 · English · Documentation


Wasmline is a Kotlin Multiplatform framework for loading and calling WASI-compliant WebAssembly plugins in Android, iOS, Desktop, and Web applications.

macOS — Apps Arch Linux — Apps
macOS sample apps
Desktop · iOS · Android · Terminal · Web (Wasm)
Arch Linux sample apps
Desktop · Android · Terminal · Web (JS)
macOS — Build Terminals Arch Linux — Build Terminals
macOS build terminals
Build commands: Desktop · iOS · Android · Web (Wasm)
Arch Linux build terminals
Build commands: Desktop · Android · Web (JS)

Sample

Define the service contract (commonMain):

// shared/src/commonMain/kotlin/com/example/EchoService.kt
import crow.wasmline.WasmlineService

interface EchoService : WasmlineService {
    fun echo(message: String): String
}

Register the implementation in the plugin (wasmWasiMain):

// plugin/src/wasmWasiMain/kotlin/Main.kt
import crow.wasmline.Wasmline
import crow.wasmline.bind

fun main() {
    Wasmline.current.bind(object : EchoService {
        override fun echo(message: String): String {
            return "Response from WASI plugin: $message"
        }
    })
}

Load the plugin and invoke services from the host:

import crow.wasmline.WasmlineConfig
import crow.wasmline.WasmlineLoadResult
import crow.wasmline.link
import crow.wasmline.loader.WasmlineLoader
import crow.wasmline.network.ktor.KtorNetworkClient

WasmlineLoader.bootstrap()

// Local paths and remote URLs are both supported — http(s):// loads the remote manifest
val module = when (val result = WasmlineLoader.load(
    source = "https://example.com/plugin/manifest.wlm",
    config = WasmlineConfig(networkClient = KtorNetworkClient()),
)) {
    is WasmlineLoadResult.Success -> result.wasmline
    is WasmlineLoadResult.Failure -> error(result.cause)
}

val response = module.link<EchoService>().echo("ping")
module.close()

Note

link<T>() and bind(impl) are rewrite targets of the Kotlin IR compiler plugin. If wasmline-kotlin-plugin is not applied to the compilation unit, these calls throw UnsupportedOperationException at runtime.

Platform Support

Platform Architecture Artifact Support Loading
Android v8a, x86_64 .cwasm / .pwasm wasmtime
Android v7a, x86 .pwasm only wasmtime
iOS arm64 .pwasm wasmtime
macOS arm64 .cwasm / .pwasm wasmtime
Linux x86_64 .cwasm / .pwasm wasmtime
Windows x86_64 .cwasm / .pwasm wasmtime
Web (Kotlin/JS · Kotlin/WasmJS) Browser JS engine Raw .wasm only web

Installation

Note

Wasmline is under active development. Detailed installation and integration documentation will be available at wuya.click/wasmline.

Warning

The minimum required Kotlin version is 2.3.0-RC2.

Kotlin/Wasm runtime support matrix

Architecture Mind Map

Wasmline Architecture Mind Map

License

Wasmline is distributed under the Apache License, Version 2.0. See LICENSE for the complete license text.

About

A Kotlin Multiplatform framework for WASI/WebAssembly plugin execution, powered by Wasmtime via C++/JNI interop with integrated RPC support.

Topics

Resources

License

Stars

16 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors