CompiledModule: export Custom Sections (#1048)

Signed-off-by: Edoardo Vacchi <evacchi@users.noreply.github.com>
Co-authored-by: Takeshi Yoneda <t.y.mathetake@gmail.com>
This commit is contained in:
Edoardo Vacchi
2023-01-19 13:39:43 +01:00
committed by GitHub
parent f484f22e47
commit d07c40f5d6
5 changed files with 153 additions and 1 deletions

43
config_example_test.go Normal file
View File

@@ -0,0 +1,43 @@
package wazero_test
import (
"context"
_ "embed"
"log"
"github.com/tetratelabs/wazero"
"github.com/tetratelabs/wazero/api"
)
// This is a basic example of retrieving custom sections using RuntimeConfig.WithCustomSections.
func Example_runtimeConfig_WithCustomSections() {
ctx := context.Background()
config := wazero.NewRuntimeConfig().WithCustomSections(true)
r := wazero.NewRuntimeWithConfig(ctx, config)
defer r.Close(ctx)
m, err := r.CompileModule(ctx, addWasm)
if err != nil {
log.Panicln(err)
}
if m.CustomSections() == nil {
log.Panicln("Custom sections should not be nil")
}
mustContain(m.CustomSections(), "producers")
mustContain(m.CustomSections(), "target_features")
// Output:
//
}
func mustContain(ss []api.CustomSection, name string) {
for _, s := range ss {
if s.Name() == name {
return
}
}
log.Panicf("Could not find section named %s\n", name)
}