From a33ec1b9069fbb35a2362df903fb807ac2fda285 Mon Sep 17 00:00:00 2001 From: Lorenzo Fontoura Date: Fri, 31 Jan 2025 01:45:24 +1000 Subject: [PATCH 1/2] docs: fix go command --- component-model/src/language-support/go.md | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/component-model/src/language-support/go.md b/component-model/src/language-support/go.md index 56f9cf7..c99c46c 100644 --- a/component-model/src/language-support/go.md +++ b/component-model/src/language-support/go.md @@ -40,13 +40,6 @@ $ wkg wit build WIT package written to docs:adder@0.1.0.wasm ``` -The `docs:adder@0.1.0.wasm` file is a Wasm encoding of the WIT package. Next, we can generate the bindings for it: - -```console -$ go get go.bytecodealliance.org/cmd/wit-bindgen-go -$ go run go.bytecodealliance.org/cmd/wit-bindgen-go generate -o internal/ ./docs:adder@0.1.0.wasm -``` - Now, create your Go project: ```console @@ -54,7 +47,7 @@ $ mkdir add && cd add $ go mod init example.com ``` -Next, we can generate the bindings for the `add.wit` file: +Next, we can generate the bindings for the Wasm component: ```console $ go get go.bytecodealliance.org/cmd/wit-bindgen-go From f6f7dc5565ea9429587fdf3615ba30a1484f1625 Mon Sep 17 00:00:00 2001 From: Lorenzo Fontoura Date: Fri, 31 Jan 2025 02:00:59 +1000 Subject: [PATCH 2/2] fix: build command --- component-model/src/language-support/go.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/component-model/src/language-support/go.md b/component-model/src/language-support/go.md index c99c46c..79962f7 100644 --- a/component-model/src/language-support/go.md +++ b/component-model/src/language-support/go.md @@ -97,11 +97,11 @@ The `adder.exports.go` file contains the exported functions that need to be impl package main import ( - "example.com/internal/example/component/example" + "example.com/internal/docs/adder/adder" ) func init() { - example.Exports.Add = func(x int32, y int32) int32 { + adder.Exports.Add = func(x int32, y int32) int32 { return x + y } } @@ -120,7 +120,7 @@ We can build our component using TinyGo by specifying the wit-package to be `add Under the hood, TinyGo invokes `wasm-tools` to embed the WIT file to the module and componentize it. ```console -$ tinygo build -target=wasip2 -o add.wasm --wit-package add.wit --wit-world adder main.go +$ tinygo build -target=wasip2 -o add.wasm --wit-package docs:adder@0.1.0.wasm --wit-world adder main.go ``` We now have an add component that satisfies our `adder` world, exporting the `add` function, which