glueball
0.1.1indexedAnnotation-driven virtualisation of functions into WebAssembly binaries, enabling native or VM execution with unified interface, in-process updates, sandboxed execution and A/B testing.
Annotation-driven virtualisation of functions into WebAssembly binaries, enabling native or VM execution with unified interface, in-process updates, sandboxed execution and A/B testing.
Glueball is a Kotlin Multiplatform library for virtualising Kotlin code via WebAssembly.
It allows you to run the same Kotlin function either natively or virtually (via a WebAssembly VM), with a unified interface. This enables:
commonMain with @GlueballSee the example project for a complete working demonstration, including an Android app.
plugins {
kotlin("multiplatform") version "2.1.0"
id("io.github.charlietap.glueball") version "0.1.1"
}
kotlin {
jvm() // At least one non-WASM target required
wasmWasi {
nodejs()
}
}
glueball {
packageName.set("com.example.generated")
interfaceName.set("FibonacciService")
}
// src/commonMain/kotlin/com/example/Math.kt
package com.example
import io.github.charlietap.glueball.annotation.Glueball
@Glueball
: {
(n <= ) n
a =
b =
i =
(i < n) {
next = a + b
a = b
b = next
i++
}
b
}
The plugin generates an interface and two implementations:
import com.example.generated.FibonacciService
import com.example.generated.NativeFibonacciService
import com.example.generated.VirtualFibonacciService
// runs natively
val native: FibonacciService = NativeFibonacciService()
native.fibonacci(10)
// runs via a WebAssembly Virtual Machine
val wasmBytes: ByteArray = loadWasmBinary()
val virtual: FibonacciService = VirtualFibonacciService(wasmBytes)
virtual.fibonacci(10)
For testing, enable automatic WASM binary embedding:
glueball {
packageName.set("com.example.generated")
interfaceName.set("FibonacciService")
generateTestBinary.set(true) // Embeds WASM as ByteArray in commonTest
}
This generates FibonacciServiceTestBinary.BYTES for use in tests:
val service = VirtualFibonacciService(FibonacciServiceTestBinary.BYTES)
This project is dual-licensed under both the MIT and Apache 2.0 licenses.
| Property | Description | Default |
|---|
packageName | Package for generated code | Required |
interfaceName | Name of the generated service interface | Required |
generateTestBinary | Embed WASM binary in test sources | true |
binaryOutputDirectory | Output directory for compiled WASM | build/glueball-binary |
Boolean, Int, Long, Float, or Double. Complex types (strings, objects, arrays) are not yet supported.@Glueball annotation only works on top-level functions, not class methods.wasmWasi target alongside at least one native target (JVM, iOS, etc.).@Glueball functions must be in the same module; cross-module virtualisation is not supported.Surfaced from shared tags and platforms — no rankings paid for.