MCPcopy Create free account
hub / github.com/dispatchrun/wazergo / Build

Function Build

module.go:38–57  ·  view source on GitHub ↗

Build builds the host module p in the wazero runtime r, returning the instance of HostModuleBuilder that was created. This is a low level function which is only exposed for certain advanced use cases where a program might not be able to leverage Compile/Instantiate, most application should not need

(runtime wazero.Runtime, mod HostModule[T])

Source from the content-addressed store, hash-verified

36// not be able to leverage Compile/Instantiate, most application should not need
37// to use this function.
38func Build[T Module](runtime wazero.Runtime, mod HostModule[T]) wazero.HostModuleBuilder {
39 moduleName := mod.Name()
40 builder := runtime.NewHostModuleBuilder(moduleName)
41
42 for export, fn := range mod.Functions() {
43 if fn.Name == "" {
44 fn.Name = export
45 }
46
47 paramTypes := appendValueTypes(make([]api.ValueType, 0, fn.NumParams()), fn.Params)
48 resultTypes := appendValueTypes(make([]api.ValueType, 0, fn.NumResults()), fn.Results)
49
50 builder.NewFunctionBuilder().
51 WithGoModuleFunction(bind(fn.Func), paramTypes, resultTypes).
52 WithName(fn.Name).
53 Export(export)
54 }
55
56 return builder
57}
58
59func appendValueTypes(buffer []api.ValueType, values []Value) []api.ValueType {
60 for _, v := range values {

Callers 1

CompileFunction · 0.85

Calls 6

appendValueTypesFunction · 0.85
bindFunction · 0.85
NumParamsMethod · 0.80
NumResultsMethod · 0.80
NameMethod · 0.65
FunctionsMethod · 0.65

Tested by

no test coverage detected