wasm

package
v0.0.0-...-4afd048 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 8, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package wasm implements a Backend that hosts capability runtimes as WebAssembly modules using wazero, the pure-Go WASI runtime. It speaks the same stdin/stdout JSON protocol as process capability runtimes: a WASI command that reads a JSON Request from stdin and writes a JSON Response to stdout works identically when run as a native process or as a WASM module.

Why not gRPC: WASI preview1 has no socket interface, so a gRPC server cannot run inside a WASI module. The stdin/stdout JSON protocol is the natural transport for WASM capability runtimes. The Backend interface abstracts this difference: callers see the same Execute/Health/Close contract regardless of whether the backend is gRPC (process) or JSON (wasm).

Each execution instantiates a fresh sandboxed module from a shared, precompiled module cached per entrypoint. Concurrent executions are safe and never serialize on the compile cache: instantiating from a compiled module is guarded by the wazero runtime, and each execution owns its own module instance with its own stdin/stdout buffers.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Backend

type Backend struct {
	// contains filtered or unexported fields
}

Backend hosts WASM capability runtime modules. It implements capabilityrt.Backend and is registered with the runtime registry for the "wasm" kind.

func New

func New() (*Backend, error)

New returns a WASM Backend using the process-global wazero runtime.

func (*Backend) BackendName

func (r *Backend) BackendName() string

RuntimeName returns "wasm", matching RuntimeKindWasm.

func (*Backend) Close

func (r *Backend) Close(ctx context.Context) error

Close releases the shared compiled-module cache and the process-global wazero runtime.

This is process-wide and irreversible: the runtime is created once via sync.OnceValues, so closing it permanently disables the WASM backend for every instance in the process, and any later Start or Execute fails with "runtime closed". It is therefore only safe at process shutdown, once all instances have been closed and no execution will follow. It is not a per-instance teardown, and callers must not use it to release one instance.

func (*Backend) Start

Start validates the frozen capability runtime and returns an Instance ready for execution. The module is compiled lazily on first Execute (warm start), but the entrypoint existence is checked here so Start fails fast when the artifact is missing or invalid.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL