forked from tetratelabs/wazero
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig_example_test.go
43 lines (34 loc) · 904 Bytes
/
config_example_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
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)
}