@@ -40,21 +40,14 @@ $ wkg wit build
40
40
WIT package written to docs:[email protected]
41
41
```
42
42
43
- The
` docs:[email protected] ` file is a Wasm encoding of the WIT package. Next, we can generate the bindings for it:
44
-
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:[email protected]
48
- ```
49
-
50
43
Now, create your Go project:
51
44
52
45
``` console
53
46
$ mkdir add && cd add
54
47
$ go mod init example.com
55
48
```
56
49
57
- Next, we can generate the bindings for the ` add.wit ` file :
50
+ Next, we can generate the bindings for the Wasm component :
58
51
59
52
``` console
60
53
$ go get go.bytecodealliance.org/cmd/wit-bindgen-go
@@ -104,11 +97,11 @@ The `adder.exports.go` file contains the exported functions that need to be impl
104
97
package main
105
98
106
99
import (
107
- " example.com/internal/example/component/example "
100
+ " example.com/internal/docs/adder/adder "
108
101
)
109
102
110
103
func init () {
111
- example .Exports .Add = func (x int32 , y int32 ) int32 {
104
+ adder .Exports .Add = func (x int32 , y int32 ) int32 {
112
105
return x + y
113
106
}
114
107
}
@@ -127,7 +120,7 @@ We can build our component using TinyGo by specifying the wit-package to be `add
127
120
Under the hood, TinyGo invokes ` wasm-tools ` to embed the WIT file to the module and componentize it.
128
121
129
122
``` console
130
- $ tinygo build -target=wasip2 -o add.wasm --wit-package add.wit --wit-world adder main.go
123
+ $
tinygo build -target=wasip2 -o add.wasm --wit-package docs:[email protected] --wit-world adder main.go
131
124
```
132
125
133
126
We now have an add component that satisfies our ` adder ` world, exporting the ` add ` function, which
0 commit comments