ModuleName is the module name WASI functions are exported into.
See https://github.com/WebAssembly/WASI/blob/snapshot-01/phases/snapshot/docs.md
const ModuleName = wasip1.InternalModuleName
func Instantiate(ctx context.Context, r wazero.Runtime) (api.Closer, error)
Instantiate instantiates the ModuleName module into the runtime.
func MustInstantiate(ctx context.Context, r wazero.Runtime)
MustInstantiate calls Instantiate or panics on error.
This is a simpler function for those who know the module ModuleName is not already instantiated, and don't need to unload it.
Builder configures the ModuleName module for later use via Compile or Instantiate.
type Builder interface { // Compile compiles the ModuleName module. Call this before Instantiate. // // Note: This has the same effect as the same function on wazero.HostModuleBuilder. Compile(context.Context) (wazero.CompiledModule, error) // Instantiate instantiates the ModuleName module and returns a function to close it. // // Note: This has the same effect as the same function on wazero.HostModuleBuilder. Instantiate(context.Context) (api.Closer, error) }
func NewBuilder(r wazero.Runtime) Builder
NewBuilder returns a new Builder.
FunctionExporter exports functions into a wazero.HostModuleBuilder.
type FunctionExporter interface { ExportFunctions(wazero.HostModuleBuilder) }
func NewFunctionExporter() FunctionExporter
NewFunctionExporter returns a new FunctionExporter. This is used for the following two use cases:
// Export the default WASI functions. wasiBuilder := r.NewHostModuleBuilder(ModuleName) wasi_snapshot_preview1.NewFunctionExporter().ExportFunctions(wasiBuilder) // Subsequent calls to NewFunctionBuilder override built-in exports. wasiBuilder.NewFunctionBuilder(). WithFunc(func(ctx context.Context, mod api.Module, exitCode uint32) { // your custom logic }).Export("proc_exit")
// Instantiate the current WASI functions under the wasi_unstable // instead of wasi_snapshot_preview1. wasiBuilder := r.NewHostModuleBuilder("wasi_unstable") wasi_snapshot_preview1.NewFunctionExporter().ExportFunctions(wasiBuilder) _, err := wasiBuilder.Instantiate(testCtx, r)