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])
| 36 | // not be able to leverage Compile/Instantiate, most application should not need |
| 37 | // to use this function. |
| 38 | func 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 | |
| 59 | func appendValueTypes(buffer []api.ValueType, values []Value) []api.ValueType { |
| 60 | for _, v := range values { |
no test coverage detected