-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.go
37 lines (34 loc) · 809 Bytes
/
main.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
package main
import (
"context"
_ "embed"
"github.com/tetratelabs/wazero"
"github.com/tetratelabs/wazero/wasi_snapshot_preview1"
"os"
)
//go:generate cargo build --target wasm32-wasi --release
//go:embed target/wasm32-wasi/release/issue_625_repr.wasm
var wasm []byte
func main() {
ctx := context.Background()
r := wazero.NewRuntime()
defer r.Close(ctx)
_, err := wasi_snapshot_preview1.Instantiate(ctx, r)
if err != nil {
panic(err)
}
compiled, err := r.CompileModule(ctx, wasm, wazero.NewCompileConfig())
if err != nil {
panic(err)
}
module, err := r.InstantiateModule(ctx, compiled, wazero.NewModuleConfig().
WithStdout(os.Stdout).
WithStderr(os.Stderr))
if err != nil {
panic(err)
}
_, err = module.ExportedFunction("entrypoint").Call(ctx)
if err != nil {
panic(err)
}
}