github.com/wasilibs/wazerox@v0.0.0-20240124024944-4923be63ab5f/config_example_test.go (about) 1 package wazero_test 2 3 import ( 4 "context" 5 _ "embed" 6 "log" 7 8 wazero "github.com/wasilibs/wazerox" 9 "github.com/wasilibs/wazerox/api" 10 ) 11 12 // This is a basic example of retrieving custom sections using RuntimeConfig.WithCustomSections. 13 func Example_runtimeConfig_WithCustomSections() { 14 ctx := context.Background() 15 config := wazero.NewRuntimeConfig().WithCustomSections(true) 16 17 r := wazero.NewRuntimeWithConfig(ctx, config) 18 defer r.Close(ctx) 19 20 m, err := r.CompileModule(ctx, addWasm) 21 if err != nil { 22 log.Panicln(err) 23 } 24 25 if m.CustomSections() == nil { 26 log.Panicln("Custom sections should not be nil") 27 } 28 29 mustContain(m.CustomSections(), "producers") 30 mustContain(m.CustomSections(), "target_features") 31 32 // Output: 33 // 34 } 35 36 func mustContain(ss []api.CustomSection, name string) { 37 for _, s := range ss { 38 if s.Name() == name { 39 return 40 } 41 } 42 log.Panicf("Could not find section named %s\n", name) 43 }