Skip to content

Commit a0483a0

Browse files
authored
Merge pull request #7 from dhil/wasmfx-merge
Merge with upstream
2 parents bafa3fb + 9c610ee commit a0483a0

File tree

32 files changed

+174
-155
lines changed

32 files changed

+174
-155
lines changed

.github/workflows/main.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ jobs:
6060
runs-on: ${{ matrix.os }}
6161
steps:
6262
- uses: actions/checkout@v4
63+
with:
64+
submodules: true
6365
- name: Install Rust
6466
run: rustup update stable --no-self-update && rustup default stable
6567
- name: Install wasm32-unknown-unknown target

.gitmodules

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
[submodule "tests/codegen/wasi-filesystem"]
2+
path = tests/codegen/wasi-filesystem
3+
url = https://github.com/WebAssembly/wasi-filesystem
4+
[submodule "tests/codegen/wasi-http"]
5+
path = tests/codegen/wasi-http
6+
url = https://github.com/WebAssembly/wasi-http
7+
[submodule "tests/codegen/wasi-cli"]
8+
path = tests/codegen/wasi-cli
9+
url = https://github.com/WebAssembly/wasi-cli
10+
[submodule "tests/codegen/wasi-io"]
11+
path = tests/codegen/wasi-io
12+
url = https://github.com/WebAssembly/wasi-io
13+
[submodule "tests/codegen/wasi-clocks"]
14+
path = tests/codegen/wasi-clocks
15+
url = https://github.com/WebAssembly/wasi-clocks

Cargo.lock

Lines changed: 11 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ resolver = "2"
1818

1919
[workspace.package]
2020
edition = "2021"
21-
version = "0.23.0"
21+
version = "0.24.0"
2222

2323
[workspace.dependencies]
2424
anyhow = "1.0.72"
@@ -34,14 +34,14 @@ wasm-encoder = { git = "https://github.com/wasmfx/wasmfx-tools", tag = "v1.202.
3434
wit-parser = { git = "https://github.com/wasmfx/wasmfx-tools", tag = "v1.202.0" }
3535
wit-component = { git = "https://github.com/wasmfx/wasmfx-tools", tag = "v1.202.0" }
3636

37-
wit-bindgen-core = { path = 'crates/core', version = '0.23.0' }
38-
wit-bindgen-c = { path = 'crates/c', version = '0.23.0' }
39-
wit-bindgen-rust = { path = "crates/rust", version = "0.23.0" }
40-
wit-bindgen-teavm-java = { path = 'crates/teavm-java', version = '0.23.0' }
41-
wit-bindgen-go = { path = 'crates/go', version = '0.23.0' }
42-
wit-bindgen-csharp = { path = 'crates/csharp', version = '0.23.0' }
43-
wit-bindgen-markdown = { path = 'crates/markdown', version = '0.23.0' }
44-
wit-bindgen = { path = 'crates/guest-rust', version = '0.23.0', default-features = false }
37+
wit-bindgen-core = { path = 'crates/core', version = '0.24.0' }
38+
wit-bindgen-c = { path = 'crates/c', version = '0.24.0' }
39+
wit-bindgen-rust = { path = "crates/rust", version = "0.24.0" }
40+
wit-bindgen-teavm-java = { path = 'crates/teavm-java', version = '0.24.0' }
41+
wit-bindgen-go = { path = 'crates/go', version = '0.24.0' }
42+
wit-bindgen-csharp = { path = 'crates/csharp', version = '0.24.0' }
43+
wit-bindgen-markdown = { path = 'crates/markdown', version = '0.24.0' }
44+
wit-bindgen = { path = 'crates/guest-rust', version = '0.24.0', default-features = false }
4545

4646
[[bin]]
4747
name = "wit-bindgen"

README.md

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -320,15 +320,13 @@ e.g. Java, Kotlin, Clojure, Scala, etc.
320320

321321
### Guest: TinyGo
322322

323-
Go code can be compiled for the `wasm32-wasi` target using the [TinyGo](https://tinygo.org/) compiler. For example, the following command compiles `main.go` to a wasm modules with WASI support:
323+
You can compile Go code into a Wasm module using the [TinyGo](https://tinygo.org/) compiler. For example, the following command compiles `main.go` to a WASI module:
324324

325325
`tinygo build -target=wasi main.go`
326326

327-
> Note: the current TinyGo bindgen only supports TinyGo version v0.27.0 or later.
327+
> Note: the current TinyGo `bindgen` requires TinyGo version v0.27.0 or later.
328328
329-
To start in Go a `*.go` and `*.h` C header file are generated for your
330-
project to use. These files are generated with the [`wit-bindgen` CLI
331-
command][cli-install] in this repository.
329+
When using `wit-bindgen tiny-go` bindgen, `*.go` and `*.h` C header file are generated for your project. These files are generated with the [`wit-bindgen` CLI command][cli-install] in this repository.
332330

333331
```sh
334332
wit-bindgen tiny-go ./wit
@@ -338,35 +336,42 @@ wit-bindgen tiny-go ./wit
338336
# Generating "host_component_type.o"
339337
```
340338

341-
If your Go code uses `result` or `option` type, a second Go file `host_types.go` will be generated. This file contains the Go types that correspond to the `result` and `option` types in the WIT file.
339+
If your Go code uses `result` or `option` type, an additional Go file `host_types.go` will be generated. This file contains the Go types that correspond to the `result` and `option` types in the WIT file.
342340

343-
Some example code using this would then look like
341+
An example of using the generated Go code would look like:
342+
343+
Initialize Go:
344+
```bash
345+
go mod init example.com
346+
```
347+
348+
Create your Go main file:
344349

345350
```go
346351
// my-component.go
347352
package main
348353

349354
import (
350-
gen "host/gen"
355+
api "example.com/api"
351356
)
352357

353358
func init() {
354359
a := HostImpl{}
355-
gen.SetHost(a)
360+
api.SetHost(a)
356361
}
357362

358363
type HostImpl struct {
359364
}
360365

361366
func (e HostImpl) Run() {
362-
gen.Print("Hello, world!")
367+
api.HostPrint("Hello, world!")
363368
}
364369

365-
//go:generate wit-bindgen tiny-go ../wit --out-dir=gen
370+
//go:generate wit-bindgen tiny-go wit --out-dir=api
366371
func main() {}
367372
```
368373

369-
This can then be compiled with `tinygo` and assembled into a component with:
374+
This setup allows you to invoke `go generate`, which generates the bindings for the Go code into an `api` directory. Afterward, you can compile your Go code into a WASI module using the TinyGo compiler. Lastly you can componentize the module using `wasm-tools`:
370375

371376
```sh
372377
go generate # generate bindings for Go

crates/csharp/tests/codegen.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,11 @@ macro_rules! codegen_test {
5656
"worlds-with-types",
5757
"variants-unioning-types",
5858
"go_params",
59+
"wasi-cli",
60+
"wasi-clocks",
61+
"wasi-filesystem",
62+
"wasi-http",
63+
"wasi-io",
5964
]
6065
.contains(&$name)
6166
{

0 commit comments

Comments
 (0)