Skip to content

Commit 8358482

Browse files
authored
Update to latest TinyGo and Rust (#2368)
Signed-off-by: Anuraag Agrawal <anuraaga@gmail.com>
1 parent c6e819e commit 8358482

File tree

24 files changed

+133
-185
lines changed

24 files changed

+133
-185
lines changed

.github/workflows/examples.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ on:
1717

1818
env:
1919
EMSDK_VERSION: "3.1.40"
20-
TINYGO_VERSION: "0.33.0"
20+
TINYGO_VERSION: "0.35.0"
2121
ZIG_VERSION: "0.11.0"
2222

2323
concurrency:
@@ -80,7 +80,7 @@ jobs:
8080
uses: dtolnay/rust-toolchain@stable
8181
with:
8282
toolchain: stable
83-
targets: wasm32-unknown-unknown, wasm32-wasi
83+
targets: wasm32-unknown-unknown, wasm32-wasip1
8484

8585
- name: Build TinyGo examples
8686
run: make build.examples.tinygo

.github/workflows/integration.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ defaults:
1919

2020
env: # Update this prior to requiring a higher minor version in go.mod
2121
GO_VERSION: "1.23"
22-
TINYGO_VERSION: "0.33.0"
22+
TINYGO_VERSION: "0.35.0"
2323
ZIG_VERSION: "0.11.0"
2424
BINARYEN_VERSION: "116"
2525
STDLIB_TESTS: "internal/integration_test/stdlibs"

Makefile

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,24 @@ build.examples.as:
3636
build.examples.zig: examples/allocation/zig/testdata/greet.wasm imports/wasi_snapshot_preview1/example/testdata/zig/cat.wasm imports/wasi_snapshot_preview1/testdata/zig/wasi.wasm
3737
@cd internal/testing/dwarftestdata/testdata/zig; zig build; mv zig-out/*/main.wasm ./ # Need DWARF custom sections.
3838

39-
tinygo_sources := examples/basic/testdata/add.go examples/allocation/tinygo/testdata/greet.go examples/cli/testdata/cli.go imports/wasi_snapshot_preview1/example/testdata/tinygo/cat.go imports/wasi_snapshot_preview1/testdata/tinygo/wasi.go cmd/wazero/testdata/cat/cat.go
40-
.PHONY: build.examples.tinygo
41-
build.examples.tinygo: $(tinygo_sources)
39+
tinygo_reactor_sources_reactor := examples/basic/testdata/add.go examples/allocation/tinygo/testdata/greet.go
40+
.PHONY: build.examples.tinygo_reactor
41+
build.examples.tinygo_reactor: $(tinygo_sources_reactor)
42+
@for f in $^; do \
43+
tinygo build -o $$(echo $$f | sed -e 's/\.go/\.wasm/') -scheduler=none --no-debug --target=wasip1 -buildmode=c-shared $$f; \
44+
done
45+
46+
tinygo_sources_clis := examples/cli/testdata/cli.go imports/wasi_snapshot_preview1/example/testdata/tinygo/cat.go imports/wasi_snapshot_preview1/testdata/tinygo/wasi.go cmd/wazero/testdata/cat/cat.go
47+
.PHONY: build.examples.tinygo_clis
48+
build.examples.tinygo_clis: $(tinygo_sources_clis)
4249
@for f in $^; do \
43-
tinygo build -o $$(echo $$f | sed -e 's/\.go/\.wasm/') -scheduler=none --no-debug --target=wasi $$f; \
50+
tinygo build -o $$(echo $$f | sed -e 's/\.go/\.wasm/') -scheduler=none --no-debug --target=wasip1 $$f; \
4451
done
4552
@mv cmd/wazero/testdata/cat/cat.wasm cmd/wazero/testdata/cat/cat-tinygo.wasm
4653

54+
.PHONY: build.examples.tinygo
55+
build.examples.tinygo: build.examples.tinygo_reactor build.examples.tinygo_clis
56+
4757
# We use zig to build C as it is easy to install and embeds a copy of zig-cc.
4858
# Note: Don't use "-Oz" as that breaks our wasi sock example.
4959
c_sources := imports/wasi_snapshot_preview1/example/testdata/zig-cc/cat.c imports/wasi_snapshot_preview1/testdata/zig-cc/wasi.c internal/testing/dwarftestdata/testdata/zig-cc/main.c
@@ -80,21 +90,21 @@ build.examples.emscripten: $(emscripten_sources)
8090
done
8191

8292
%/greet.wasm : cargo_target := wasm32-unknown-unknown
83-
%/cat.wasm : cargo_target := wasm32-wasi
84-
%/wasi.wasm : cargo_target := wasm32-wasi
93+
%/cat.wasm : cargo_target := wasm32-wasip1
94+
%/wasi.wasm : cargo_target := wasm32-wasip1
8595

8696
.PHONY: build.examples.rust
8797
build.examples.rust: examples/allocation/rust/testdata/greet.wasm imports/wasi_snapshot_preview1/example/testdata/cargo-wasi/cat.wasm imports/wasi_snapshot_preview1/testdata/cargo-wasi/wasi.wasm internal/testing/dwarftestdata/testdata/rust/main.wasm.xz
8898

8999
# Normally, we build release because it is smaller. Testing dwarf requires the debug build.
90100
internal/testing/dwarftestdata/testdata/rust/main.wasm.xz:
91-
cd $(@D) && cargo wasi build
92-
mv $(@D)/target/wasm32-wasi/debug/main.wasm $(@D)
101+
cd $(@D) && cargo build --target wasm32-wasip1
102+
mv $(@D)/target/wasm32-wasip1/debug/main.wasm $(@D)
93103
cd $(@D) && xz -k -f ./main.wasm # Rust's DWARF section is huge, so compress it.
94104

95-
# Builds rust using cargo normally, or cargo-wasi.
105+
# Builds rust using cargo normally
96106
%.wasm: %.rs
97-
@(cd $(@D); cargo $(if $(findstring wasi,$(cargo_target)),wasi build,build --target $(cargo_target)) --release)
107+
@(cd $(@D); cargo build --target $(cargo_target) --release)
98108
@mv $(@D)/target/$(cargo_target)/release/$(@F) $(@D)
99109

100110
spectest_base_dir := internal/integration_test/spectest

cmd/wazero/testdata/cat/cat-tinygo.wasm

100755100644
-6.38 KB
Binary file not shown.

cmd/wazero/wazero_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -337,9 +337,9 @@ func TestRun(t *testing.T) {
337337
<== (opened_fd=4,errno=ESUCCESS)
338338
==> wasi_snapshot_preview1.fd_filestat_get(fd=4)
339339
<== (filestat={filetype=REGULAR_FILE,size=5,mtim=%d},errno=ESUCCESS)
340-
==> wasi_snapshot_preview1.fd_read(fd=4,iovs=64744,iovs_len=1)
340+
==> wasi_snapshot_preview1.fd_read(fd=4,iovs=64664,iovs_len=1)
341341
<== (nread=5,errno=ESUCCESS)
342-
==> wasi_snapshot_preview1.fd_read(fd=4,iovs=64744,iovs_len=1)
342+
==> wasi_snapshot_preview1.fd_read(fd=4,iovs=64664,iovs_len=1)
343343
<== (nread=0,errno=ESUCCESS)
344344
==> wasi_snapshot_preview1.fd_close(fd=4)
345345
<== errno=ESUCCESS

example_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ func Example() {
3939

4040
// Instantiate the guest Wasm into the same runtime. It exports the `add`
4141
// function, implemented in WebAssembly.
42-
mod, err := r.Instantiate(ctx, addWasm)
42+
mod, err := r.InstantiateWithConfig(ctx, addWasm, wazero.NewModuleConfig().WithStartFunctions("_initialize"))
4343
if err != nil {
4444
log.Panicln(err)
4545
}
123 Bytes
Binary file not shown.

examples/allocation/tinygo/README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
## TinyGo allocation example
22

33
This example shows how to pass strings in and out of a Wasm function defined
4-
in TinyGo, built with `tinygo build -o greet.wasm -scheduler=none -target=wasi greet.go`
4+
in TinyGo, built with
5+
6+
```bash
7+
(cd testdata; tinygo build -scheduler=none -target=wasip1 -buildmode=c-shared -o greet.wasm greet.go)
8+
```
59

610
```bash
711
$ go run greet.go wazero

examples/allocation/tinygo/greet.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ func main() {
4444

4545
// Instantiate a WebAssembly module that imports the "log" function defined
4646
// in "env" and exports "memory" and functions we'll use in this example.
47-
mod, err := r.Instantiate(ctx, greetWasm)
47+
mod, err := r.InstantiateWithConfig(ctx, greetWasm, wazero.NewModuleConfig().WithStartFunctions("_initialize"))
4848
if err != nil {
4949
log.Panicln(err)
5050
}

examples/allocation/tinygo/testdata/greet.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ func greeting(name string) string {
3838
// _greet is a WebAssembly export that accepts a string pointer (linear memory
3939
// offset) and calls greet.
4040
//
41-
//export greet
41+
//go:wasmexport greet
4242
func _greet(ptr, size uint32) {
4343
name := ptrToString(ptr, size)
4444
greet(name)
@@ -50,7 +50,7 @@ func _greet(ptr, size uint32) {
5050
// Note: This uses a uint64 instead of two result values for compatibility with
5151
// WebAssembly 1.0.
5252
//
53-
//export greeting
53+
//go:wasmexport greeting
5454
func _greeting(ptr, size uint32) (ptrSize uint64) {
5555
name := ptrToString(ptr, size)
5656
g := greeting(name)

0 commit comments

Comments
 (0)