wasm

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2026 License: MIT Imports: 4 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

WebAssembly host contract

github.com/webong/ext/pkg/ext-go/core/wasm defines a runtime-neutral WebAssembly host API. It owns limits, errors, inspection results, WASI command options, byte-stream and reactor interfaces, and the Runtime interface. It does not import wazero or the Ext plugin engine and does not select a runtime.

The Go wazero implementation lives in pkg/ext-go/wasm/runtime. It supports core modules and WASI Preview 1. The sibling pkg/ext-go/wasm package adapts it to Ext plugin sessions. The installed-executable Wasmtime path remains in xallet.app/zip/wasm; that adapter does not implement the in-process Runtime interface.

reactor.js stays here as page-side glue for the iOS and Android WebView hosts.

Cross-language conformance

tests/crosslang holds the interoperability tests that build real foreign artifacts: Rust, Zig, and Go guests and hosts, native C ABI guests, and WASI modules. Run them with scripts/plugin-crosslang.sh from the repository root; they build artifacts the tests then execute, so a plain go test ./... does not exercise them.

pkg/ext-go/wasm/runtime/cmd/wasirun checks a portable C guest core compiled to WASI. Use it through scripts/plugin-wasi-core.sh.

See the interoperability guide and the runtime authoring guide.

Documentation

Overview

Package wasm defines the protocol-neutral WebAssembly host contract. A host chooses an implementation; this package does not select or load a runtime.

Index

Constants

View Source
const DefaultMemoryPages = 4096 // 256 MiB of guest linear memory.
View Source
const MaxModuleBytes = 64 << 20

Variables

View Source
var (
	ErrInvalid     = errors.New("wasm: invalid")
	ErrUnsupported = errors.New("wasm: unsupported")
	ErrMismatch    = errors.New("wasm: ABI mismatch")
	ErrClosed      = errors.New("wasm: closed")
)

Functions

This section is empty.

Types

type Command

type Command interface {
	io.ReadWriteCloser
	Wait(context.Context) error
}

Command is one persistent command. Its bytes carry no assigned protocol.

type CommandOptions

type CommandOptions struct {
	Name             string
	Args             []string
	Env              map[string]string
	Dirs             map[string]string
	ReadOnlyDirs     map[string]string
	Stdin            io.Reader
	Stdout           io.Writer
	Stderr           io.Writer
	MemoryLimitPages uint32
	CompilationCache CompilationCache
	// BeforeInstantiate runs after compilation and configuration, before any
	// guest instruction. An error discards the prepared runtime.
	BeforeInstantiate func() error
}

CommandOptions describes one run of a WASI command. Nothing is inherited from the host unless the caller supplies it here.

type CompilationCache

type CompilationCache interface {
	Close(context.Context) error
}

CompilationCache is owned by the selected runtime. Share one only among sessions of that runtime, then close it after those sessions have closed.

type Inspection

type Inspection struct {
	Target      Target   `json:"target"`
	Imports     []string `json:"imports"`
	Unsupported []string `json:"unsupported,omitempty"`
	Web         bool     `json:"web"`
}

Inspection summarizes a module's imports without running it.

type Options

type Options struct {
	// MemoryLimitPages bounds guest linear memory. Zero uses DefaultMemoryPages.
	MemoryLimitPages uint32
	// FS is mounted at /. The caller must supply a confined implementation;
	// os.DirFS follows symlinks. Nil grants no filesystem.
	FS   fs.FS
	Args []string
	Env  map[string]string
	// Stderr receives guest diagnostics. Nil discards them.
	Stderr io.Writer
	// MaxStderrBytes caps forwarded diagnostics. Zero defaults to 64 KiB.
	MaxStderrBytes   int64
	CompilationCache CompilationCache
	// StubImports answer a fixed status for declared host functions.
	StubImports []StubImport
}

Options configures a persistent WASI command connected through raw bytes.

type Reactor

type Reactor interface {
	Call(context.Context, uint32, []byte) (uint32, []byte, error)
	Close() error
	WaitClosed(context.Context) error
}

Reactor hosts raw request/response calls. The implementation serializes calls to an instance and owns its lifetime.

type ReactorABI

type ReactorABI struct {
	Version          uint32
	MaxMessageBytes  uint32
	SuccessStatus    uint32
	VersionExport    string
	OpenExport       string
	CallExport       string
	CloseExport      string
	AllocateExport   string
	FreeExport       string
	InitializeExport string
	DisallowedExport string
	StubImports      []StubImport
}

ReactorABI names the exports of an application-defined request/response reactor. Operation and status values belong to the caller's protocol.

type ReactorOptions

type ReactorOptions struct {
	MemoryLimitPages uint32
	Stderr           io.Writer
	MaxStderrBytes   int64
	CompilationCache CompilationCache
}

ReactorOptions configures one reactor instance.

type Runtime

type Runtime interface {
	NewCompilationCache() CompilationCache
	Open(context.Context, []byte, Options) (Command, error)
	RunCommand(context.Context, []byte, CommandOptions) (int, error)
	Inspect(context.Context, []byte) (Inspection, error)
	OpenReactor(context.Context, []byte, ReactorABI, ReactorOptions) (Reactor, error)
}

Runtime is the platform implementation a host selects. Inspection may report an unsupported module even when a different runtime can execute it.

type StubImport

type StubImport struct {
	Module, Name string
	Params       int
	Result       uint32
}

StubImport is a host function with Params i32 arguments and one i32 result.

type Target

type Target string

Target classifies what a module needs from its host.

const (
	TargetNone      Target = "none"
	TargetWASI      Target = "wasi"
	TargetHost      Target = "host"
	TargetComponent Target = "component"
)

Jump to

Keyboard shortcuts

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