runtime

package
v0.6.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: 14 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

Go WebAssembly runtime

This package implements pkg/ext-go/core/wasm.Runtime with wazero. It provides module inspection, bounded WASI Preview 1 command execution, persistent byte streams, raw reactors, and compilation caches. It assigns no Ext protocol to the bytes and imports no plugin package.

pkg/ext-go/wasm adds the Ext plugin backend. The WASM adapter uses this package for its embedded engine and owns selection of external executables.

Documentation

Overview

Package runtime implements the src/ctx/web WebAssembly host contract with wazero. It does not assign an Ext plugin protocol to guest byte streams.

Index

Constants

View Source
const (
	TargetNone      = contract.TargetNone
	TargetWASI      = contract.TargetWASI
	TargetHost      = contract.TargetHost
	TargetComponent = contract.TargetComponent
)
View Source
const DefaultMemoryPages = contract.DefaultMemoryPages
View Source
const MaxModuleBytes = contract.MaxModuleBytes

Variables

View Source
var (
	ErrInvalid     = contract.ErrInvalid
	ErrUnsupported = contract.ErrUnsupported
	ErrMismatch    = contract.ErrMismatch
	ErrClosed      = contract.ErrClosed
)

Functions

func RunCommand

func RunCommand(ctx context.Context, module []byte, opts CommandOptions) (int, error)

RunCommand compiles module and runs its _start function to completion. The result is the module's exit status; a non-zero status is not an error. Cancelling ctx terminates the module, including a compute loop that does no I/O, and returns the context's error.

Types

type Command

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

Command is one persistent WASI command. Read and Write exchange raw bytes with the command's stdout and stdin; this package assigns them no protocol.

func Open

func Open(ctx context.Context, module []byte, opts Options) (*Command, error)

Open compiles module and starts one persistent WASI Preview 1 command. The returned stream is protocol-neutral. ctx bounds compilation, not the running command; Close terminates it.

func (*Command) Close

func (c *Command) Close() error

func (*Command) Read

func (c *Command) Read(p []byte) (int, error)

func (*Command) Wait

func (c *Command) Wait(ctx context.Context) error

Wait observes command exit, including startup failures or traps. Close first when stopping a long-running command.

func (*Command) Write

func (c *Command) Write(p []byte) (int, error)

type CommandOptions

type CommandOptions = contract.CommandOptions

type CompilationCache

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

CompilationCache keeps the compiled form of the modules opened with it, so opening the same module again skips compilation, which is most of the cost of Open for a large module. A nil cache in Options, ReactorOptions or CommandOptions compiles every time.

Share one among the sessions of a process, and Close it after they have closed. It is safe for concurrent use. It holds every module it compiles until it is closed, so it is not a budget on the number of distinct modules: a host that loads many unrelated modules decides for itself which sessions share one.

func NewCompilationCache

func NewCompilationCache() *CompilationCache

NewCompilationCache returns an empty cache that lives in memory.

func (*CompilationCache) Close

func (c *CompilationCache) Close(ctx context.Context) error

Close releases the compiled modules. The cache must not be used afterwards.

type Engine

type Engine struct{}

Engine is a wazero implementation of the runtime-neutral web contract.

func (Engine) Inspect

func (Engine) Inspect(ctx context.Context, module []byte) (Inspection, error)

func (Engine) NewCompilationCache

func (Engine) NewCompilationCache() contract.CompilationCache

func (Engine) Open

func (Engine) Open(ctx context.Context, module []byte, options Options) (contract.Command, error)

func (Engine) OpenReactor

func (Engine) OpenReactor(ctx context.Context, module []byte, abi ReactorABI, options ReactorOptions) (contract.Reactor, error)

func (Engine) RunCommand

func (Engine) RunCommand(ctx context.Context, module []byte, options CommandOptions) (int, error)

type Inspection

type Inspection = contract.Inspection

func Inspect

func Inspect(ctx context.Context, module []byte) (Inspection, error)

Inspect compiles module and reports what it imports. It does not instantiate or run it.

type Options

type Options = contract.Options

type Reactor

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

Reactor hosts one request/response WebAssembly reactor. Calls are serialized because a module instance is single-threaded.

func OpenReactor

func OpenReactor(ctx context.Context, module []byte, abi ReactorABI, opts ReactorOptions) (*Reactor, error)

OpenReactor compiles module, validates the configured ABI exports, and opens one reactor handle. ctx bounds compilation and startup, not the instance.

func (*Reactor) Call

func (r *Reactor) Call(ctx context.Context, operation uint32, request []byte) (uint32, []byte, error)

Call invokes one application-defined operation and returns its raw status and response bytes. The caller owns all protocol encoding and status semantics.

func (*Reactor) Close

func (r *Reactor) Close() error

Close stops admission and releases the module once an outstanding call exits.

func (*Reactor) WaitClosed

func (r *Reactor) WaitClosed(ctx context.Context) error

WaitClosed waits for resources to be released after Close.

type ReactorABI

type ReactorABI = contract.ReactorABI

type ReactorOptions

type ReactorOptions = contract.ReactorOptions

type StubImport

type StubImport = contract.StubImport

type Target

type Target = contract.Target

Directories

Path Synopsis
cmd
wasirun command
wasirun checks a portable C guest core compiled to WASI Preview 1.
wasirun checks a portable C guest core compiled to WASI Preview 1.

Jump to

Keyboard shortcuts

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