ChasmEmscriptenHostBuilder
Emscripten / WASI Preview 1 host function installer.
Sets up WebAssembly host imports that provide the Emscripten env and WASI Preview 1 implementations.
To create a new instance, use ChasmEmscriptenHostBuilder(store).
Usage example:
val store: Store = store()
val chasmHostBuilder = ChasmEmscriptenHostBuilder(store) {
this.host = embedderHost
}
val wasiHostFunctions = chasmHostBuilder.setupWasiPreview1HostFunctions()
val emscriptenFinalizer = chasmHostBuilder.setupEmscriptenFunctions()
val hostImports: List<Import> = buildList {
addAll(emscriptenInstaller.emscriptenFunctions)
addAll(wasiHostFunctions)
}
// Instantiate the WebAssembly module
val instance = module(helloWorldBytes).flatMap { module ->
instance(store, module, hostImports)
}.fold(
onSuccess = { it },
onError = { error("Can node instantiate WebAssembly binary: $it") },
)
// Finalize initialization after module instantiation
val emscriptenRuntime = emscriptenInstaller.finalize(instance)
// Initialize Emscripten runtime environment
emscriptenRuntime.initMainThread()
// Execute code
Content copied to clipboard
Functions
Link copied to clipboard
fun setupEmscriptenFunctions(moduleName: String = ENV_MODULE_NAME): ChasmEmscriptenHostBuilder.ChasmEmscriptenSetupFinalizer
Link copied to clipboard
fun setupWasiPreview1HostFunctions(moduleName: String = WASI_SNAPSHOT_PREVIEW1_MODULE_NAME): List<Import>