From 942d5d8b84f55d71a275a7d6f3446587ab7368a3 Mon Sep 17 00:00:00 2001 From: Physcik Date: Mon, 15 Dec 2025 15:26:38 +0500 Subject: Wasm build pipeline --- inter/go.mod | 5 +++++ inter/go.sum | 2 ++ inter/main.go | 42 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 49 insertions(+) create mode 100644 inter/go.mod create mode 100644 inter/go.sum create mode 100644 inter/main.go (limited to 'inter') diff --git a/inter/go.mod b/inter/go.mod new file mode 100644 index 0000000..ec2d0ad --- /dev/null +++ b/inter/go.mod @@ -0,0 +1,5 @@ +module inter + +go 1.25.4 + +require github.com/tetratelabs/wazero v1.10.1 // indirect diff --git a/inter/go.sum b/inter/go.sum new file mode 100644 index 0000000..c3d453a --- /dev/null +++ b/inter/go.sum @@ -0,0 +1,2 @@ +github.com/tetratelabs/wazero v1.10.1 h1:2DugeJf6VVk58KTPszlNfeeN8AhhpwcZqkJj2wwFuH8= +github.com/tetratelabs/wazero v1.10.1/go.mod h1:DRm5twOQ5Gr1AoEdSi0CLjDQF1J9ZAuyqFIjl1KKfQU= diff --git a/inter/main.go b/inter/main.go new file mode 100644 index 0000000..e0dd0a7 --- /dev/null +++ b/inter/main.go @@ -0,0 +1,42 @@ +package main + +import ( + "context" + "fmt" + "os" + + "github.com/tetratelabs/wazero" + "github.com/tetratelabs/wazero/imports/wasi_snapshot_preview1" +) + +const wasmLocation = "../hello.wasm" + +func main() { + var ctx = context.Background() + + var runtime = wazero.NewRuntime(ctx) + defer runtime.Close(ctx) + + wasi_snapshot_preview1.MustInstantiate(ctx, runtime) + + var wasm, wasmErr = LoadWasm() + if wasmErr != nil { + panic(fmt.Sprintf("Failed to load WASM module: %s", wasmErr.Error())) + } + + var mod, modErr = runtime.Instantiate(ctx, wasm) + if modErr != nil { + panic(fmt.Sprintf("Failed to instantiate WASM module: %s", modErr.Error())) + } + + var add = mod.ExportedFunction("Add") + var result, callErr = add.Call(ctx, 25, 25) + if callErr != nil { + panic(fmt.Sprintf("Failed to call WASM finction: %s", callErr.Error())) + } + fmt.Printf("Addition result: %v\n", result[0]) +} + +func LoadWasm() ([]byte, error) { + return os.ReadFile(wasmLocation) +} -- cgit v1.3