Documentation
¶
Overview ¶
Package component runs WebAssembly Component Model binaries through Wago.
The package owns Component Model decoding, graph linking, Canonical ABI lift/lower, resources, and typed host imports. Core Wasm compilation and execution stay behind three reviewed Wago authorities. WASI and other world policy belong in plugins that consume Contract.
A consuming plugin declares Contract in its PluginDefinition and acquires a typed reference during registration:
components, err := plugin.Require(reg, component.Contract)
Calls stay inside both the contract lease and the component instance's lifetime:
err := components.With(func(service component.Service) error {
return service.WithInstance(ctx, componentWasm, func(in *component.Instance) error {
_, err := in.Call(ctx, "wasi:cli/run@0.2.3#run")
return err
})
})
The service closes the instance before WithInstance returns. Neither the service nor the instance may be retained outside its callback.
Index ¶
- Constants
- Variables
- func Definition() wago.PluginDefinition
- func Provider() wago.PluginProvider
- type AsyncCall
- type AsyncHostFunc
- type BorrowDesc
- type CompileCache
- type EnumDesc
- type FlagsDesc
- type FuncDesc
- type FuncParam
- type FuncResult
- type FuncResults
- type FutureDesc
- type HandleTable
- type HostFunc
- type Instance
- type ListDesc
- type Option
- func WithAsyncImport(iface, name string, fn AsyncHostFunc, params, results []TypeDesc) Option
- func WithCompileCache(cache *CompileCache) Option
- func WithHostResourceDtor(tag uint32, fn func(ctx context.Context, rep uint32) error) Option
- func WithHostState(key, value any) Option
- func WithHostStateFactory(key any, newState func() any) Option
- func WithImport(iface, name string, fn HostFunc, params, results []TypeDesc) Option
- func WithImportCustom(iface, name string, fn HostFunc, fd FuncDesc, resolve Resolver) Option
- func WithOptionsFactory(newOptions func() []Option) Option
- func WithResourceTag(iface, name string, tag uint32) Option
- func WithResourcesHook(hook func(*HandleTable)) Option
- type OptionDesc
- type OwnDesc
- type PendingCall
- type PrimitiveDesc
- type RecordDesc
- type RecordField
- type Resolver
- type ResultDesc
- type ResultValue
- type Service
- type StreamDesc
- type TupleDesc
- type TypeDesc
- type TypeRef
- type TypeTable
- func (t *TypeTable) Add(td TypeDesc) TypeRef
- func (t *TypeTable) Borrow(tag uint32) TypeRef
- func (t *TypeTable) Enum(cases ...string) TypeRef
- func (t *TypeTable) Flags(names ...string) TypeRef
- func (t *TypeTable) Func(params []TypeRef, result TypeRef) FuncDesc
- func (t *TypeTable) List(elem TypeRef) TypeRef
- func (t *TypeTable) Option(elem TypeRef) TypeRef
- func (t *TypeTable) Own(tag uint32) TypeRef
- func (t *TypeTable) Record(nameTypePairs ...any) TypeRef
- func (t *TypeTable) Resolver() Resolver
- func (t *TypeTable) Result(ok, err TypeRef) TypeRef
- func (t *TypeTable) Tuple(elems ...TypeRef) TypeRef
- func (t *TypeTable) Variant(cases ...VariantCaseSpec) TypeRef
- type Value
- type VariantCase
- type VariantCaseSpec
- type VariantDesc
- type VariantValue
Constants ¶
const PluginID = "github.com/wago-org/component-model"
PluginID is the canonical Component Model plugin ID.
Variables ¶
var Contract = wagoplugin.NewContract[Service](PluginID+"/runtime", 1)
Contract is the major-versioned Component Model execution service consumed by WASI and other component-world plugins.
Functions ¶
func Definition ¶
func Definition() wago.PluginDefinition
Definition returns fresh immutable metadata for the explicit provider.
func Provider ¶
func Provider() wago.PluginProvider
Provider is the side-effect-free catalog entry for Component Model support.
Types ¶
type AsyncHostFunc ¶
type AsyncHostFunc = instance.AsyncHostFunc
AsyncHostFunc implements an async-lowered component import.
type BorrowDesc ¶
type BorrowDesc = binary.BorrowDesc
BorrowDesc is borrow<R> -- a handle lent for the duration of the call.
type CompileCache ¶
type CompileCache = instance.CompileCache
CompileCache amortizes component decoding and embedded core-module compilation across repeated Service.WithInstance calls. A cache belongs to one loaded Component Model provider and must be closed before that runtime.
func NewCompileCache ¶
func NewCompileCache() *CompileCache
NewCompileCache returns an empty compile cache. Close it before closing the Wago runtime that loaded the Component Model provider.
type EnumDesc ¶
EnumDesc is a set of named cases with no payloads. Its Value is the case index as a uint32.
type FuncDesc ¶
FuncDesc, and its parts, describe a whole host func signature. Build one with TypeTable.Func rather than by hand.
type FuncParam ¶
FuncDesc, and its parts, describe a whole host func signature. Build one with TypeTable.Func rather than by hand.
type FuncResult ¶
type FuncResult = binary.FuncResult
FuncDesc, and its parts, describe a whole host func signature. Build one with TypeTable.Func rather than by hand.
type FuncResults ¶
type FuncResults = binary.FuncResults
FuncDesc, and its parts, describe a whole host func signature. Build one with TypeTable.Func rather than by hand.
type HandleTable ¶
type HandleTable = instance.HandleTable
HandleTable is one instance's resource handle table. Obtain it with WithResourcesHook; use it to mint own<T>/borrow<T> handles that sit nested inside a composite result, which the engine's automatic top-level handle translation does not reach.
type Instance ¶
Instance is a live component instance. It is valid only during the Service.WithInstance callback that supplied it.
type ListDesc ¶
ListDesc is an unbounded sequence. Its Value is a []Value -- or, for list<u8> specifically, a []byte, which lowers with a single copy.
type Option ¶
Option configures one component instantiation.
func WithAsyncImport ¶
func WithAsyncImport(iface, name string, fn AsyncHostFunc, params, results []TypeDesc) Option
WithAsyncImport registers an async-lowered component import.
func WithCompileCache ¶
func WithCompileCache(cache *CompileCache) Option
WithCompileCache reuses cache across component instantiations.
func WithHostResourceDtor ¶
WithHostResourceDtor registers the Go destructor run when the guest drops an owned handle of the host resource tagged `tag`.
func WithHostState ¶
WithHostState attaches an opaque, intentionally shared value to every Instance built with this option. Use WithHostStateFactory for mutable state that must be isolated per instantiation.
Use a package-private key type, not a bare string, so two independent host implementations cannot collide:
type myHostKey struct{}
component.WithHostStateFactory(myHostKey{}, func() any { return newMyHost() })
h := inst.HostState(myHostKey{}).(*myHost)
func WithHostStateFactory ¶
WithHostStateFactory creates a fresh value for each instantiation.
func WithImport ¶
WithImport registers a synchronous component import.
func WithImportCustom ¶
WithImportCustom registers fn as the host implementation of iface/name with a hand-built signature -- the general form of WithImport, and the only one that can express a nested composite. Build fd and resolve from a TypeTable:
tbl := component.NewTypeTable()
fd := tbl.Func([]component.TypeRef{component.Prim("string")},
tbl.Result(tbl.List(component.Prim("string")), component.Prim("u32")))
opt := component.WithImportCustom("acme:api/host@1.0.0", "lookup", fn, fd, tbl.Resolver())
iface is matched with its "@x.y.z" version suffix stripped, so one registration serves every patch version of an interface.
func WithOptionsFactory ¶
WithOptionsFactory creates a fresh, coherent option bundle for each instantiation.
func WithResourceTag ¶
WithResourceTag declares that the resource `name`, exported by the imported interface `iface`, is the one this host tags as `tag` when minting handles.
Required for any resource-bearing interface: the guest drops handles through a canon carrying the component binary's own type index, while the host mints them under a tag of its choosing. Without this mapping the two numberings disagree and the first drop trips the handle table's cross-type check.
func WithResourcesHook ¶
func WithResourcesHook(hook func(*HandleTable)) Option
WithResourcesHook registers a callback run once per instantiation, with that instance's HandleTable, before any host func executes. This is how a host implementation gets the table it needs to mint nested handles.
type OptionDesc ¶
type OptionDesc = binary.OptionDesc
OptionDesc is option<T>. Its Value is nil for none, or the inner value.
type OwnDesc ¶
OwnDesc is own<R> -- an owned handle to a resource. Lifting one gives the host the rep it names and consumes the guest's handle.
type PendingCall ¶
type PendingCall = instance.PendingCall
PendingCall is a live CallAsync invocation, suspended awaiting external import completions. See Instance.CallAsync.
type PrimitiveDesc ¶
type PrimitiveDesc = binary.PrimitiveDesc
PrimitiveDesc is bool, s8-s64, u8-u64, f32, f64, char, or string. See Prim for the ergonomic spelling.
type RecordDesc ¶
type RecordDesc = binary.RecordDesc
RecordDesc is a struct with named fields. Its Value is a []Value in field order.
type RecordField ¶
type RecordField = binary.RecordField
RecordField is one named field of a RecordDesc.
type Resolver ¶
Resolver maps a TypeRef's index back to its descriptor. TypeTable.Resolver produces the one matching a table.
type ResultDesc ¶
type ResultDesc = binary.ResultDesc
ResultDesc is result<T, E>; either arm may be absent. Its Value is a ResultValue.
type ResultValue ¶
type ResultValue = abi.ResultValue
ResultValue is the Go shape of a result value. IsErr selects the arm; Payload is that arm's value, or nil for an arm declared without a type.
A result is NOT a Go error: returning a Go error from a HostFunc traps the guest, whereas a ResultValue with IsErr set is an ordinary value the guest receives and can handle. Use the error return only for "this call cannot proceed", and ResultValue for a WIT-declared failure.
type Service ¶
type Service interface {
WithInstance(context.Context, []byte, func(*Instance) error, ...Option) error
}
Service is the Component Model plugin's cross-plugin execution boundary. WithInstance keeps the service and every core resource it creates inside the caller's contract lease. The instance is closed before WithInstance returns and must not be retained by fn.
type TypeDesc ¶
TypeDesc is one WIT type. The concrete descriptors below implement it. It is a sealed interface -- a type outside wazy cannot implement it, because the ABI dispatches on the concrete descriptors and an unknown one has no defined lowering.
type TypeRef ¶
TypeRef refers to a type from inside a composite: either a primitive (spelled inline) or an index into the TypeTable the enclosing FuncDesc was built with. Prefer the TypeTable sugar constructors over building these by hand.
type TypeTable ¶
type TypeTable struct {
// contains filtered or unexported fields
}
TypeTable interns the composite types one host func's signature refers to, handing back a TypeRef for each. It exists because a WIT type is a graph, not a tree: `list<list<u8>>` needs the inner `list<u8>` to be nameable from the outer one, and a TypeRef names it by index into exactly this table.
One table per func signature. Indices are local to it, and the Resolver it produces is what the engine uses to walk back from a TypeRef to a descriptor, so a FuncDesc and the table it was built from must be passed to WithImportCustom together.
The Add method is the primitive; the sugar methods below (List, Option, Result, Tuple, Record, Variant) cover the shapes that actually occur and keep TypeRef out of caller code:
tbl := component.NewTypeTable()
fd := tbl.Func(
[]component.TypeRef{tbl.Record("name", component.Prim("string"), "count", component.Prim("u32"))},
tbl.Result(tbl.List(component.Prim("string")), component.Prim("u32")),
)
opt := component.WithImportCustom("acme:api/host@1.0.0", "lookup", fn, fd, tbl.Resolver())
A TypeTable is not safe for concurrent use; build a signature on one goroutine, then it is read-only.
func (*TypeTable) Add ¶
Add interns td and returns the TypeRef naming it. A primitive is returned inline (it needs no table slot), so Add(PrimitiveDesc{...}) and Prim(...) are interchangeable.
func (*TypeTable) Enum ¶
Enum interns an enum of the named cases. A value of it is the case index as a uint32.
func (*TypeTable) Flags ¶
Flags interns a flags bitset of the named flags. A value of it is a uint32 whose bits are set in declaration order.
func (*TypeTable) Func ¶
Func assembles a FuncDesc from params and a single unnamed result. Pass the zero TypeRef for a func that returns nothing.
func (*TypeTable) Own ¶
Own interns own<R> for the resource identified by tag -- the same tag passed to WithResourceTag and used when minting handles.
func (*TypeTable) Record ¶
Record interns a record from alternating name/type pairs: Record("port", Prim("u16"), "host", Prim("string")). Panics on an odd number of arguments or a non-string in a name position, since both are programmer errors in a signature that is built once at startup.
func (*TypeTable) Resolver ¶
Resolver returns the Resolver over the table's current entries. Call it after the signature is fully built.
func (*TypeTable) Result ¶
Result interns result<ok, err>. Pass the zero TypeRef for an arm the WIT declares without a type: Result(ok, TypeRef{}) is `result<ok>`, and Result(TypeRef{}, TypeRef{}) is a bare `result`.
func (*TypeTable) Variant ¶
func (t *TypeTable) Variant(cases ...VariantCaseSpec) TypeRef
Variant interns a variant. Each case is a name and an optional payload; pass the zero TypeRef for a case that carries none. Case order is the discriminant order a VariantValue's Disc indexes into.
type Value ¶
Value is a component-level call value matching the Canonical ABI lifting of a WIT type.
type VariantCase ¶
type VariantCase = binary.VariantCase
VariantCase is one case of a VariantDesc; a nil Type means no payload.
type VariantCaseSpec ¶
VariantCaseSpec is one case for TypeTable.Variant: a name, and a payload type or the zero TypeRef for none.
type VariantDesc ¶
type VariantDesc = binary.VariantDesc
VariantDesc is a discriminated union. Its Value is a VariantValue.
type VariantValue ¶
type VariantValue = abi.VariantValue
VariantValue is the Go shape of a variant value: Disc is the case index in declaration order, Payload is that case's value (nil when the case carries none).
Directories
¶
| Path | Synopsis |
|---|---|
|
internal
|
|
|
abi
Package abi implements the Canonical ABI for the WebAssembly Component Model.
|
Package abi implements the Canonical ABI for the WebAssembly Component Model. |
|
engine
Package engine adapts Wago's core WebAssembly runtime to the small runtime surface needed by the Component Model linker.
|
Package engine adapts Wago's core WebAssembly runtime to the small runtime surface needed by the Component Model linker. |
|
instance
Package instance instantiates a decoded WebAssembly component and exposes its exported functions for calling.
|
Package instance instantiates a decoded WebAssembly component and exposes its exported functions for calling. |
|
testfixtures
Package testfixtures holds guest components shared by more than one package's tests.
|
Package testfixtures holds guest components shared by more than one package's tests. |
|
testrequire
Package require includes test assertions that fail the test immediately.
|
Package require includes test assertions that fail the test immediately. |
|
Package register exposes the Component Model provider catalog to generated Wago runtimes.
|
Package register exposes the Component Model provider catalog to generated Wago runtimes. |