Skip to content

Commit 088fe2a

Browse files
Merge pull request bytecodealliance#175 from Mossaka/mossaka/fix-go-docs
component-model/src/language-support/go: fix go docs
2 parents 683f208 + 32efb42 commit 088fe2a

File tree

1 file changed

+11
-49
lines changed
  • component-model/src/language-support

1 file changed

+11
-49
lines changed

component-model/src/language-support/go.md

Lines changed: 11 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@ Optional: Install the `wkg` CLI tool to resolve the imports in the WIT file. The
2020

2121
## 2. Determine which World the Component will Implement
2222

23-
The `wasip2` target of TinyGo assumes that the component is targeting `wasi:cli/command@0.2.0` world so it requires the imports of `wasi:cli/imports@0.2.0`. We need to include them in the `add.wit`. Tools like `wkg` can be handy to build a complete WIT package by resolving the imports.
23+
The `wasip2` target of TinyGo assumes that the component is targeting `wasi:cli/command@0.2.0` world so it requires the imports of `wasi:cli/imports@0.2.0`. We need to include them in the `add.wit`.
24+
25+
Tools like `wkg` can be convenient to build a complete WIT package by resolving the imports.
2426

2527
```wit
2628
# wit/add.wit
@@ -34,55 +36,15 @@ world adder {
3436
Running the `wkg wit build` command will resolve the imports and generate the complete WIT file encoded as a Wasm component.
3537

3638
```console
37-
wkg wit build
39+
$ wkg wit build
40+
WIT package written to docs:adder@0.1.0.wasm
3841
```
3942

40-
Or you can manually include the required imports in the `add.wit` file. Below is the minimal `add.wit` file that includes the required imports:
41-
42-
```wit
43-
package docs:adder@0.1.0;
44-
45-
world adder {
46-
import wasi:io/error@0.2.0;
47-
import wasi:io/streams@0.2.0;
48-
import wasi:cli/stdout@0.2.0;
49-
import wasi:random/random@0.2.0;
50-
51-
export add: func(x: s32, y: s32) -> s32;
52-
}
53-
54-
package wasi:io@0.2.0 {
55-
interface error {
56-
resource error;
57-
}
58-
interface streams {
59-
use error.{error};
60-
61-
resource output-stream {
62-
blocking-write-and-flush: func(contents: list<u8>) -> result<_, stream-error>;
63-
}
64-
65-
variant stream-error {
66-
last-operation-failed(error),
67-
closed,
68-
}
69-
}
70-
}
71-
72-
package wasi:cli@0.2.0 {
73-
interface stdout {
74-
use wasi:io/streams@0.2.0.{output-stream};
43+
The `docs:adder@0.1.0.wasm` file is a Wasm encoding of the WIT package. Next, we can generate the bindings for it:
7544

76-
get-stdout: func() -> output-stream;
77-
}
78-
}
79-
80-
81-
package wasi:random@0.2.0 {
82-
interface random {
83-
get-random-u64: func() -> u64;
84-
}
85-
}
45+
```console
46+
$ go get go.bytecodealliance.org/cmd/wit-bindgen-go
47+
$ go run go.bytecodealliance.org/cmd/wit-bindgen-go generate -o internal/ ./docs:adder@0.1.0.wasm
8648
```
8749

8850
Now, create your Go project:
@@ -96,10 +58,10 @@ Next, we can generate the bindings for the `add.wit` file:
9658

9759
```console
9860
$ go get go.bytecodealliance.org/cmd/wit-bindgen-go
99-
$ go run go.bytecodealliance.org/cmd/wit-bindgen-go generate -o internal/ ./add.wit
61+
$ go run go.bytecodealliance.org/cmd/wit-bindgen-go generate -o internal/ ./docs:adder@0.1.0.wasm
10062
```
10163

102-
The `internal` directory will contain the generated Go code for the `add.wit` file.
64+
The `internal` directory will contain the generated Go code that WIT package.
10365

10466
```console
10567
$ tree internal

0 commit comments

Comments
 (0)