Documentation
¶
Overview ¶
Package bindgen generates Go bindings for a WIT world, so a host calls and implements a component's interfaces in Go types rather than in component.Values:
- a Go type for each record, variant, enum, flags and resource the world's functions use;
- for each import, a Go interface the host implements, and the options that register it;
- for the exports, a type wrapping the component.Instance, with a method per exported function, and one making each stream and future type the world passes.
The generated code depends only on package component and package witgo. cmd/wazy-bindgen runs Generate from the command line, for go generate, on a WIT package or on a compiled component, whose WIT wit.FromComponent reads.
A world's WASI imports are not bound by default: wazy's imports/wasip2 implements them, and its options go to Instantiate next to the bindings.
Bindings can share an imported interface's code rather than each holding a copy. GenerateTree writes each imported interface a package of its own, which holds nothing that depends on the world, so every world generated into the same tree shares it; and Options.With points an interface at such a package that already exists. Its Go names, its converters and its resource tags are the same in every world: it exports what other packages need of it, the host interface it is implemented by included.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type File ¶
type File struct {
// Path is where it goes, relative to the tree's root, which is the
// directory of the base import path GenerateTree is given.
Path string
Src []byte
}
File is one file of GenerateTree's output.
func GenerateTree ¶
GenerateTree returns the bindings for opts.World in pkg as a tree of packages under the import path base: one for each imported interface, at base/<namespace>/<package>/[v<version>/]<interface> -- shared by every world's bindings generated into the same tree, as it holds nothing that depends on the world -- and one for the world, at base/<opts.Package>, holding the rest.
type Options ¶
type Options struct {
// Package is the Go package name of the generated file, or with
// GenerateTree of the world's package.
Package string
// World is the name of the world to bind, in the parsed package.
World string
// Skip lists prefixes of imported interface names to leave unbound, for
// a host that implements them by other means. Nil means "wasi:".
Skip []string
// TagBase is the first resource tag the bindings mint host handles
// under. Zero picks one from the world's name, well clear of the small
// tags imports/wasip2 uses. An imported interface's own package (see
// GenerateTree and With) has tags of its own instead, the same in every
// world.
TagBase uint32
// With maps imported interfaces to the Go packages already holding their
// bindings, which the generated code uses rather than writing its own:
// an interface name ("wasi:http/types@0.2.0", or without the version to
// match any) to an import path. The package is GenerateTree's for the
// interface, from any world importing the same WIT of it.
With map[string]string
}
Options says what to generate.
Directories
¶
| Path | Synopsis |
|---|---|
|
internal
|
|
|
convtest
Package convtest binds the WIT world conv.
|
Package convtest binds the WIT world conv. |
|
kitchen
Package kitchen binds the WIT world kitchen.
|
Package kitchen binds the WIT world kitchen. |
|
storebind
Package storebind binds the WIT world app.
|
Package storebind binds the WIT world app. |
|
storebind/tree/app
Package app binds the WIT world app.
|
Package app binds the WIT world app. |
|
storebind/tree/example/store/v1.0.0/kv
Package kv binds the WIT interface example:store/kv@1.0.0, for a host implementing it.
|
Package kv binds the WIT interface example:store/kv@1.0.0, for a host implementing it. |
|
storebind/with
Package with binds the WIT world app.
|
Package with binds the WIT world app. |