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)

examples/allocation/tinygo/testdata/greet.wasm

100755100644
296 KB
Binary file not shown.

examples/basic/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ typically a `%.wasm` file.
1919
the minimal command to build a `%.wasm` binary.
2020

2121
```bash
22-
cd testdata; tinygo build -o add.wasm -target=wasi add.go
22+
(cd testdata; tinygo build -buildmode=c-shared -target=wasip1 -o add.wasm add.go)
2323
```
2424

2525
### Notes

examples/basic/add.go

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

4343
// Instantiate the guest Wasm into the same runtime. It exports the `add`
4444
// function, implemented in WebAssembly.
45-
mod, err := r.Instantiate(ctx, addWasm)
45+
mod, err := r.InstantiateWithConfig(ctx, addWasm, wazero.NewModuleConfig().WithStartFunctions("_initialize"))
4646
if err != nil {
4747
log.Panicf("failed to instantiate module: %v", err)
4848
}

examples/basic/testdata/add.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package main
22

3-
//export add
3+
//go:wasmexport add
44
func add(x, y uint32) uint32 {
55
return x + y
66
}

examples/basic/testdata/add.wasm

100755100644
97.8 KB
Binary file not shown.

examples/cli/testdata/cli.wasm

100755100644
-9.16 KB
Binary file not shown.
Binary file not shown.
-6.38 KB
Binary file not shown.
9.66 KB
Binary file not shown.
-4.79 KB
Binary file not shown.

internal/integration_test/engine/dwarf_test.go

Lines changed: 41 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -85,77 +85,48 @@ wasm stack trace:
8585
}
8686

8787
func testRustDWARF(t *testing.T, r wazero.Runtime) {
88-
runDWARFTest(t, r, dwarftestdata.RustWasm, `module[] function[_start] failed: wasm error: unreachable
88+
runDWARFTest(t, r, dwarftestdata.RustWasm, `module[main-144f120e836a09da.wasm] function[_start] failed: wasm error: unreachable
8989
wasm stack trace:
90-
.__rust_start_panic(i32) i32
91-
0xc474: /index.rs:286:39 (inlined)
92-
/const_ptr.rs:870:18 (inlined)
93-
/index.rs:286:39 (inlined)
94-
/mod.rs:1630:46 (inlined)
95-
/mod.rs:405:20 (inlined)
96-
/mod.rs:1630:46 (inlined)
97-
/mod.rs:1548:18 (inlined)
98-
/iter.rs:1478:30 (inlined)
99-
/count.rs:74:18
100-
.rust_panic(i32,i32)
101-
0xa3f8: /validations.rs:57:19 (inlined)
102-
/validations.rs:57:19 (inlined)
103-
/iter.rs:140:15 (inlined)
104-
/iter.rs:140:15 (inlined)
105-
/iterator.rs:330:13 (inlined)
106-
/iterator.rs:377:9 (inlined)
107-
/mod.rs:1455:35
108-
.std::panicking::rust_panic_with_hook::h93e119628869d575(i32,i32,i32,i32,i32)
109-
0x42df: /alloc.rs:244:22 (inlined)
110-
/alloc.rs:244:22 (inlined)
111-
/alloc.rs:342:9 (inlined)
112-
/mod.rs:487:1 (inlined)
113-
/mod.rs:487:1 (inlined)
114-
/mod.rs:487:1 (inlined)
115-
/mod.rs:487:1 (inlined)
116-
/mod.rs:487:1 (inlined)
117-
/panicking.rs:292:17 (inlined)
118-
/panicking.rs:292:17
119-
.std::panicking::begin_panic_handler::{{closure}}::h2b8c0798e533b227(i32,i32,i32)
120-
0xaa8c: /mod.rs:362:12 (inlined)
121-
/mod.rs:1257:22 (inlined)
122-
/mod.rs:1235:21 (inlined)
123-
/mod.rs:1214:26
124-
.std::sys_common::backtrace::__rust_end_short_backtrace::h030a533bc034da65(i32)
125-
0xc144: /mod.rs:188:26
126-
.rust_begin_unwind(i32)
127-
0xb7df: /mod.rs:1629:9 (inlined)
128-
/builders.rs:199:17 (inlined)
129-
/result.rs:1352:22 (inlined)
130-
/builders.rs:187:23
131-
.core::panicking::panic_fmt::hb1bfc4175f838eff(i32,i32)
132-
0xbd3d: /mod.rs:1384:17
133-
.main::main::hfd44f54575e6bfdf()
134-
0xad2c: /memchr.rs
135-
.core::ops::function::FnOnce::call_once::h87e5f77996df3e28(i32)
136-
0xbd61: /mod.rs
137-
.std::sys_common::backtrace::__rust_begin_short_backtrace::h7ca17eb6aa97f768(i32)
138-
0xbd95: /mod.rs:1504:35 (inlined)
139-
/mod.rs:1407:36
140-
.std::rt::lang_start::{{closure}}::he4aa401e76315dfe(i32) i32
141-
0xae9a: /location.rs:196:6
142-
.std::rt::lang_start_internal::h3c39e5d3c278a90f(i32,i32,i32,i32) i32
143-
.std::rt::lang_start::h779801844bd22a3c(i32,i32,i32) i32
144-
0xab94: /mod.rs:1226:2
145-
.__original_main() i32
146-
0xc0ae: /methods.rs:1677:13 (inlined)
147-
/mod.rs:165:24 (inlined)
148-
/mod.rs:165:24
149-
._start()
150-
0xc10f: /mod.rs:187
151-
._start.command_export()
152-
0xc3de: /iterator.rs:2414:21 (inlined)
153-
/map.rs:124:9 (inlined)
154-
/accum.rs:42:17 (inlined)
155-
/iterator.rs:3347:9 (inlined)
156-
/count.rs:135:5 (inlined)
157-
/count.rs:135:5 (inlined)
158-
/count.rs:71:21`)
90+
main-144f120e836a09da.wasm.__rust_start_panic(i32,i32) i32
91+
0x3276: /lib.rs:100:17 (inlined)
92+
/lib.rs:43:5
93+
main-144f120e836a09da.wasm.rust_panic(i32,i32)
94+
0x31c8: /panicking.rs:862:25
95+
main-144f120e836a09da.wasm._ZN3std9panicking20rust_panic_with_hook17hf4c55e90d4731159E(i32,i32,i32,i32,i32)
96+
0x319b: /panicking.rs:826:5
97+
main-144f120e836a09da.wasm._ZN3std9panicking19begin_panic_handler28_$u7b$$u7b$closure$u7d$$u7d$17h9e9ba254d816924bE(i32)
98+
0x25e2: /panicking.rs:667:13
99+
main-144f120e836a09da.wasm._ZN3std3sys9backtrace26__rust_end_short_backtrace17h5fb21e191bc452e3E(i32)
100+
0x251c: /backtrace.rs:170:18
101+
main-144f120e836a09da.wasm.rust_begin_unwind(i32)
102+
0x2b2f: /panicking.rs:665:5
103+
main-144f120e836a09da.wasm._ZN4core9panicking9panic_fmt17hfe24bec0337a4754E(i32,i32)
104+
0x798a: /panicking.rs:76:14
105+
main-144f120e836a09da.wasm._ZN4main4main17hef810e4bf58d9cdfE()
106+
0x373: /main.rs:12:5 (inlined)
107+
/main.rs:7:5 (inlined)
108+
/main.rs:2:5
109+
main-144f120e836a09da.wasm._ZN4core3ops8function6FnOnce9call_once17hb3419529f8e10fb1E(i32)
110+
0x124: /function.rs:250:5
111+
main-144f120e836a09da.wasm._ZN3std3sys9backtrace28__rust_begin_short_backtrace17h6b7139fa671fb72eE(i32)
112+
0x289: /backtrace.rs:154:18
113+
main-144f120e836a09da.wasm._ZN3std2rt10lang_start28_$u7b$$u7b$closure$u7d$$u7d$17hefb60d097516fc9fE(i32) i32
114+
0x20c: /rt.rs:195:18
115+
main-144f120e836a09da.wasm._ZN3std2rt19lang_start_internal17h1fceb22bbe5297a1E(i32,i32,i32,i32,i32) i32
116+
0x1780: /function.rs:284:13 (inlined)
117+
/panicking.rs:557:40 (inlined)
118+
/panicking.rs:520:19 (inlined)
119+
/panic.rs:358:14 (inlined)
120+
/rt.rs:174:48 (inlined)
121+
/panicking.rs:557:40 (inlined)
122+
/panicking.rs:520:19 (inlined)
123+
/panic.rs:358:14 (inlined)
124+
/rt.rs:174:20
125+
main-144f120e836a09da.wasm._ZN3std2rt10lang_start17he470b12ea6d4e370E(i32,i32,i32,i32) i32
126+
0x1a8: /rt.rs:194:17
127+
main-144f120e836a09da.wasm.__main_void() i32
128+
main-144f120e836a09da.wasm._start()
129+
0x37: wasisdk:/crt1-command.c:43:13`)
159130
}
160131

161132
func runDWARFTest(t *testing.T, r wazero.Runtime, bin []byte, exp string) {

internal/integration_test/stdlibs/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ build.tinygo:
133133
@mkdir -p $(tinygo_bin)
134134
for value in $(tinygo_tests); do\
135135
echo Building $${value}... ;\
136-
tinygo test -target wasi -c -o $(tinygo_bin)/$$(echo $$value | sed -e 's/\//_/g').test $${value} 2>&1 >/dev/null ;\
136+
tinygo test -target wasip1 -c -o $(tinygo_bin)/$$(echo $$value | sed -e 's/\//_/g').test $${value} 2>&1 >/dev/null ;\
137137
done
138138

139139
.PHONY: build.gowasip1
-17.7 KB
Binary file not shown.

0 commit comments

Comments
 (0)