You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -9,103 +9,262 @@ The component will implement the `adder` world, which contains `add` interface w
9
9
10
10
## 1. Install the tools
11
11
12
-
Follow the [TinyGo installation instructions](https://tinygo.org/getting-started/) to install the TinyGo compiler. Additionally, install the `wasm-tools` CLI tool from the [wasm-tools repository](https://github.com/bytecodealliance/wasm-tools/releases).
12
+
Follow the [TinyGo installation instructions](https://tinygo.org/getting-started/) to install the TinyGo compiler.
13
+
14
+
Additionally, install the `wasm-tools` CLI tool from the [wasm-tools repository](https://github.com/bytecodealliance/wasm-tools/releases).
15
+
16
+
> [!WARNING]
17
+
> Due to some upstream issues, only `wasm-tools` versions 1.225.0 or earlier can be used with `wit-bindgen-go`
18
+
>
19
+
> If using the Rust toolchain to install `wasm-tools`, it can be installed like so:
To verify the installation, run the following commands:
15
23
16
-
```console
24
+
```
17
25
$ tinygo version
18
26
tinygo version 0.34.0 ...
19
27
$ wasm-tools -V
20
-
wasm-tools 1.219.1 ...
28
+
wasm-tools 1.255.0 ...
21
29
```
22
30
23
-
Optional: Install the `wkg` CLI tool to resolve the imports in the WIT file. The `wkg` CLI is a part of the [Wasm Component package manager](https://github.com/bytecodealliance/wasm-pkg-tools/releases)
31
+
Optional: Install the [`wkg`][wkg] CLI tool to resolve the imports in the WIT file. The `wkg` CLI is a part of the [Wasm Component package manager](https://github.com/bytecodealliance/wasm-pkg-tools/releases)
24
32
25
-
## 2. Determine which World the Component will Implement
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`.
35
+
## 2. Create your Go project
28
36
29
-
Tools like `wkg` can be convenient to build a complete WIT package by resolving the imports.
37
+
Now, create your Go project:
38
+
39
+
```console
40
+
mkdir add && cd add
41
+
go mod init example.com
42
+
```
43
+
44
+
Ensure that the following `tool`s are installed:
45
+
46
+
```
47
+
tool (
48
+
go.bytecodealliance.org/cmd/wit-bindgen-go
49
+
)
50
+
```
51
+
52
+
> [!NOTE]
53
+
> `go tool` was introduced in [Golang 1.24][go-1-24-release] and can be used to manage tooling in Go projects.
54
+
55
+
Consider also running `go mod tidy` after adding the above tool.
56
+
57
+
[go-1-24-release]: https://go.dev/blog/go1.24
58
+
59
+
## 2. Determine which World the Component will Implement
60
+
61
+
Since we will be implementing the [`adder` world][adder-wit], we can copy the WIT to our project,
62
+
under the `wit` folder (e.g. `wit/component.wit`):
30
63
31
64
```wit
32
-
# wit/add.wit
33
65
package docs:adder@0.1.0;
66
+
67
+
interface add {
68
+
add: func(x: u32, y: u32) -> u32;
69
+
}
70
+
71
+
world adder {
72
+
export add;
73
+
}
74
+
```
75
+
76
+
The `wasip2` target of TinyGo assumes that the component is targeting `wasi:cli/command@0.2.0` world
77
+
(part of [`wasi:cli`][wasi-cli]) so it requires the imports of `wasi:cli/imports@0.2.0`.
78
+
79
+
We need to include those interfaces as well in `component.wit`, by editing the `adder` world:
80
+
81
+
```wit
34
82
world adder {
35
83
include wasi:cli/imports@0.2.0;
36
-
export add: func(x: s32, y: s32) -> s32;
84
+
export add;
37
85
}
38
86
```
39
87
40
-
Running the`wkg wit build` command will resolve the imports and generate the complete WIT file encoded as a Wasm component.
88
+
### Using`wkg` to automatically resolve and download imports
41
89
42
-
```console
90
+
Tools like [`wkg`][wkg] can be convenient to build a complete WIT package by resolving the imports.
91
+
92
+
Running the `wkg wit fetch` command will resolve the imports and populate your `wit` folder with all relevant
0 commit comments