Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to latest TinyGo and Rust #2368

Merged
merged 2 commits into from
Jan 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/examples.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ on:

env:
EMSDK_VERSION: "3.1.40"
TINYGO_VERSION: "0.33.0"
TINYGO_VERSION: "0.35.0"
ZIG_VERSION: "0.11.0"

concurrency:
Expand Down Expand Up @@ -80,7 +80,7 @@ jobs:
uses: dtolnay/rust-toolchain@stable
with:
toolchain: stable
targets: wasm32-unknown-unknown, wasm32-wasi
targets: wasm32-unknown-unknown, wasm32-wasip1

- name: Build TinyGo examples
run: make build.examples.tinygo
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/integration.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ defaults:

env: # Update this prior to requiring a higher minor version in go.mod
GO_VERSION: "1.23"
TINYGO_VERSION: "0.33.0"
TINYGO_VERSION: "0.35.0"
ZIG_VERSION: "0.11.0"
BINARYEN_VERSION: "116"
STDLIB_TESTS: "internal/integration_test/stdlibs"
Expand Down
30 changes: 20 additions & 10 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,24 @@ build.examples.as:
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
@cd internal/testing/dwarftestdata/testdata/zig; zig build; mv zig-out/*/main.wasm ./ # Need DWARF custom sections.

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
.PHONY: build.examples.tinygo
build.examples.tinygo: $(tinygo_sources)
tinygo_reactor_sources_reactor := examples/basic/testdata/add.go examples/allocation/tinygo/testdata/greet.go
.PHONY: build.examples.tinygo_reactor
build.examples.tinygo_reactor: $(tinygo_sources_reactor)
@for f in $^; do \
tinygo build -o $$(echo $$f | sed -e 's/\.go/\.wasm/') -scheduler=none --no-debug --target=wasip1 -buildmode=c-shared $$f; \
done

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
.PHONY: build.examples.tinygo_clis
build.examples.tinygo_clis: $(tinygo_sources_clis)
@for f in $^; do \
tinygo build -o $$(echo $$f | sed -e 's/\.go/\.wasm/') -scheduler=none --no-debug --target=wasi $$f; \
tinygo build -o $$(echo $$f | sed -e 's/\.go/\.wasm/') -scheduler=none --no-debug --target=wasip1 $$f; \
done
@mv cmd/wazero/testdata/cat/cat.wasm cmd/wazero/testdata/cat/cat-tinygo.wasm

.PHONY: build.examples.tinygo
build.examples.tinygo: build.examples.tinygo_reactor build.examples.tinygo_clis

# We use zig to build C as it is easy to install and embeds a copy of zig-cc.
# Note: Don't use "-Oz" as that breaks our wasi sock example.
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
Expand Down Expand Up @@ -80,21 +90,21 @@ build.examples.emscripten: $(emscripten_sources)
done

%/greet.wasm : cargo_target := wasm32-unknown-unknown
%/cat.wasm : cargo_target := wasm32-wasi
%/wasi.wasm : cargo_target := wasm32-wasi
%/cat.wasm : cargo_target := wasm32-wasip1
%/wasi.wasm : cargo_target := wasm32-wasip1

.PHONY: build.examples.rust
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

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

# Builds rust using cargo normally, or cargo-wasi.
# Builds rust using cargo normally
%.wasm: %.rs
@(cd $(@D); cargo $(if $(findstring wasi,$(cargo_target)),wasi build,build --target $(cargo_target)) --release)
@(cd $(@D); cargo build --target $(cargo_target) --release)
@mv $(@D)/target/$(cargo_target)/release/$(@F) $(@D)

spectest_base_dir := internal/integration_test/spectest
Expand Down
Binary file modified cmd/wazero/testdata/cat/cat-tinygo.wasm
100755 → 100644
Binary file not shown.
4 changes: 2 additions & 2 deletions cmd/wazero/wazero_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -337,9 +337,9 @@ func TestRun(t *testing.T) {
<== (opened_fd=4,errno=ESUCCESS)
==> wasi_snapshot_preview1.fd_filestat_get(fd=4)
<== (filestat={filetype=REGULAR_FILE,size=5,mtim=%d},errno=ESUCCESS)
==> wasi_snapshot_preview1.fd_read(fd=4,iovs=64744,iovs_len=1)
==> wasi_snapshot_preview1.fd_read(fd=4,iovs=64664,iovs_len=1)
<== (nread=5,errno=ESUCCESS)
==> wasi_snapshot_preview1.fd_read(fd=4,iovs=64744,iovs_len=1)
==> wasi_snapshot_preview1.fd_read(fd=4,iovs=64664,iovs_len=1)
<== (nread=0,errno=ESUCCESS)
==> wasi_snapshot_preview1.fd_close(fd=4)
<== errno=ESUCCESS
Expand Down
2 changes: 1 addition & 1 deletion example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func Example() {

// Instantiate the guest Wasm into the same runtime. It exports the `add`
// function, implemented in WebAssembly.
mod, err := r.Instantiate(ctx, addWasm)
mod, err := r.InstantiateWithConfig(ctx, addWasm, wazero.NewModuleConfig().WithStartFunctions("_initialize"))
if err != nil {
log.Panicln(err)
}
Expand Down
Binary file modified examples/allocation/rust/testdata/greet.wasm
Binary file not shown.
6 changes: 5 additions & 1 deletion examples/allocation/tinygo/README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
## TinyGo allocation example

This example shows how to pass strings in and out of a Wasm function defined
in TinyGo, built with `tinygo build -o greet.wasm -scheduler=none -target=wasi greet.go`
in TinyGo, built with

```bash
(cd testdata; tinygo build -scheduler=none -target=wasip1 -buildmode=c-shared -o greet.wasm greet.go)
```

```bash
$ go run greet.go wazero
Expand Down
2 changes: 1 addition & 1 deletion examples/allocation/tinygo/greet.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func main() {

// Instantiate a WebAssembly module that imports the "log" function defined
// in "env" and exports "memory" and functions we'll use in this example.
mod, err := r.Instantiate(ctx, greetWasm)
mod, err := r.InstantiateWithConfig(ctx, greetWasm, wazero.NewModuleConfig().WithStartFunctions("_initialize"))
if err != nil {
log.Panicln(err)
}
Expand Down
4 changes: 2 additions & 2 deletions examples/allocation/tinygo/testdata/greet.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func greeting(name string) string {
// _greet is a WebAssembly export that accepts a string pointer (linear memory
// offset) and calls greet.
//
//export greet
//go:wasmexport greet
func _greet(ptr, size uint32) {
name := ptrToString(ptr, size)
greet(name)
Expand All @@ -50,7 +50,7 @@ func _greet(ptr, size uint32) {
// Note: This uses a uint64 instead of two result values for compatibility with
// WebAssembly 1.0.
//
//export greeting
//go:wasmexport greeting
func _greeting(ptr, size uint32) (ptrSize uint64) {
name := ptrToString(ptr, size)
g := greeting(name)
Expand Down
Binary file modified examples/allocation/tinygo/testdata/greet.wasm
100755 → 100644
Binary file not shown.
2 changes: 1 addition & 1 deletion examples/basic/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ typically a `%.wasm` file.
the minimal command to build a `%.wasm` binary.

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

### Notes
Expand Down
2 changes: 1 addition & 1 deletion examples/basic/add.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func main() {

// Instantiate the guest Wasm into the same runtime. It exports the `add`
// function, implemented in WebAssembly.
mod, err := r.Instantiate(ctx, addWasm)
mod, err := r.InstantiateWithConfig(ctx, addWasm, wazero.NewModuleConfig().WithStartFunctions("_initialize"))
if err != nil {
log.Panicf("failed to instantiate module: %v", err)
}
Expand Down
2 changes: 1 addition & 1 deletion examples/basic/testdata/add.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package main

//export add
//go:wasmexport add
func add(x, y uint32) uint32 {
return x + y
}
Expand Down
Binary file modified examples/basic/testdata/add.wasm
100755 → 100644
Binary file not shown.
Binary file modified examples/cli/testdata/cli.wasm
100755 → 100644
Binary file not shown.
Binary file modified imports/wasi_snapshot_preview1/example/testdata/cargo-wasi/cat.wasm
100644 → 100755
Binary file not shown.
Binary file modified imports/wasi_snapshot_preview1/example/testdata/tinygo/cat.wasm
100755 → 100644
Binary file not shown.
Binary file modified imports/wasi_snapshot_preview1/testdata/cargo-wasi/wasi.wasm
100644 → 100755
Binary file not shown.
Binary file modified imports/wasi_snapshot_preview1/testdata/tinygo/wasi.wasm
100755 → 100644
Binary file not shown.
111 changes: 41 additions & 70 deletions internal/integration_test/engine/dwarf_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,77 +85,48 @@ wasm stack trace:
}

func testRustDWARF(t *testing.T, r wazero.Runtime) {
runDWARFTest(t, r, dwarftestdata.RustWasm, `module[] function[_start] failed: wasm error: unreachable
runDWARFTest(t, r, dwarftestdata.RustWasm, `module[main-144f120e836a09da.wasm] function[_start] failed: wasm error: unreachable
wasm stack trace:
.__rust_start_panic(i32) i32
0xc474: /index.rs:286:39 (inlined)
/const_ptr.rs:870:18 (inlined)
/index.rs:286:39 (inlined)
/mod.rs:1630:46 (inlined)
/mod.rs:405:20 (inlined)
/mod.rs:1630:46 (inlined)
/mod.rs:1548:18 (inlined)
/iter.rs:1478:30 (inlined)
/count.rs:74:18
.rust_panic(i32,i32)
0xa3f8: /validations.rs:57:19 (inlined)
/validations.rs:57:19 (inlined)
/iter.rs:140:15 (inlined)
/iter.rs:140:15 (inlined)
/iterator.rs:330:13 (inlined)
/iterator.rs:377:9 (inlined)
/mod.rs:1455:35
.std::panicking::rust_panic_with_hook::h93e119628869d575(i32,i32,i32,i32,i32)
0x42df: /alloc.rs:244:22 (inlined)
/alloc.rs:244:22 (inlined)
/alloc.rs:342:9 (inlined)
/mod.rs:487:1 (inlined)
/mod.rs:487:1 (inlined)
/mod.rs:487:1 (inlined)
/mod.rs:487:1 (inlined)
/mod.rs:487:1 (inlined)
/panicking.rs:292:17 (inlined)
/panicking.rs:292:17
.std::panicking::begin_panic_handler::{{closure}}::h2b8c0798e533b227(i32,i32,i32)
0xaa8c: /mod.rs:362:12 (inlined)
/mod.rs:1257:22 (inlined)
/mod.rs:1235:21 (inlined)
/mod.rs:1214:26
.std::sys_common::backtrace::__rust_end_short_backtrace::h030a533bc034da65(i32)
0xc144: /mod.rs:188:26
.rust_begin_unwind(i32)
0xb7df: /mod.rs:1629:9 (inlined)
/builders.rs:199:17 (inlined)
/result.rs:1352:22 (inlined)
/builders.rs:187:23
.core::panicking::panic_fmt::hb1bfc4175f838eff(i32,i32)
0xbd3d: /mod.rs:1384:17
.main::main::hfd44f54575e6bfdf()
0xad2c: /memchr.rs
.core::ops::function::FnOnce::call_once::h87e5f77996df3e28(i32)
0xbd61: /mod.rs
.std::sys_common::backtrace::__rust_begin_short_backtrace::h7ca17eb6aa97f768(i32)
0xbd95: /mod.rs:1504:35 (inlined)
/mod.rs:1407:36
.std::rt::lang_start::{{closure}}::he4aa401e76315dfe(i32) i32
0xae9a: /location.rs:196:6
.std::rt::lang_start_internal::h3c39e5d3c278a90f(i32,i32,i32,i32) i32
.std::rt::lang_start::h779801844bd22a3c(i32,i32,i32) i32
0xab94: /mod.rs:1226:2
.__original_main() i32
0xc0ae: /methods.rs:1677:13 (inlined)
/mod.rs:165:24 (inlined)
/mod.rs:165:24
._start()
0xc10f: /mod.rs:187
._start.command_export()
0xc3de: /iterator.rs:2414:21 (inlined)
/map.rs:124:9 (inlined)
/accum.rs:42:17 (inlined)
/iterator.rs:3347:9 (inlined)
/count.rs:135:5 (inlined)
/count.rs:135:5 (inlined)
/count.rs:71:21`)
main-144f120e836a09da.wasm.__rust_start_panic(i32,i32) i32
0x3276: /lib.rs:100:17 (inlined)
/lib.rs:43:5
main-144f120e836a09da.wasm.rust_panic(i32,i32)
0x31c8: /panicking.rs:862:25
main-144f120e836a09da.wasm._ZN3std9panicking20rust_panic_with_hook17hf4c55e90d4731159E(i32,i32,i32,i32,i32)
0x319b: /panicking.rs:826:5
main-144f120e836a09da.wasm._ZN3std9panicking19begin_panic_handler28_$u7b$$u7b$closure$u7d$$u7d$17h9e9ba254d816924bE(i32)
0x25e2: /panicking.rs:667:13
main-144f120e836a09da.wasm._ZN3std3sys9backtrace26__rust_end_short_backtrace17h5fb21e191bc452e3E(i32)
0x251c: /backtrace.rs:170:18
main-144f120e836a09da.wasm.rust_begin_unwind(i32)
0x2b2f: /panicking.rs:665:5
main-144f120e836a09da.wasm._ZN4core9panicking9panic_fmt17hfe24bec0337a4754E(i32,i32)
0x798a: /panicking.rs:76:14
main-144f120e836a09da.wasm._ZN4main4main17hef810e4bf58d9cdfE()
0x373: /main.rs:12:5 (inlined)
/main.rs:7:5 (inlined)
/main.rs:2:5
main-144f120e836a09da.wasm._ZN4core3ops8function6FnOnce9call_once17hb3419529f8e10fb1E(i32)
0x124: /function.rs:250:5
main-144f120e836a09da.wasm._ZN3std3sys9backtrace28__rust_begin_short_backtrace17h6b7139fa671fb72eE(i32)
0x289: /backtrace.rs:154:18
main-144f120e836a09da.wasm._ZN3std2rt10lang_start28_$u7b$$u7b$closure$u7d$$u7d$17hefb60d097516fc9fE(i32) i32
0x20c: /rt.rs:195:18
main-144f120e836a09da.wasm._ZN3std2rt19lang_start_internal17h1fceb22bbe5297a1E(i32,i32,i32,i32,i32) i32
0x1780: /function.rs:284:13 (inlined)
/panicking.rs:557:40 (inlined)
/panicking.rs:520:19 (inlined)
/panic.rs:358:14 (inlined)
/rt.rs:174:48 (inlined)
/panicking.rs:557:40 (inlined)
/panicking.rs:520:19 (inlined)
/panic.rs:358:14 (inlined)
/rt.rs:174:20
main-144f120e836a09da.wasm._ZN3std2rt10lang_start17he470b12ea6d4e370E(i32,i32,i32,i32) i32
0x1a8: /rt.rs:194:17
main-144f120e836a09da.wasm.__main_void() i32
main-144f120e836a09da.wasm._start()
0x37: wasisdk:/crt1-command.c:43:13`)
}

func runDWARFTest(t *testing.T, r wazero.Runtime, bin []byte, exp string) {
Expand Down
2 changes: 1 addition & 1 deletion internal/integration_test/stdlibs/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ build.tinygo:
@mkdir -p $(tinygo_bin)
for value in $(tinygo_tests); do\
echo Building $${value}... ;\
tinygo test -target wasi -c -o $(tinygo_bin)/$$(echo $$value | sed -e 's/\//_/g').test $${value} 2>&1 >/dev/null ;\
tinygo test -target wasip1 -c -o $(tinygo_bin)/$$(echo $$value | sed -e 's/\//_/g').test $${value} 2>&1 >/dev/null ;\
done

.PHONY: build.gowasip1
Expand Down
Binary file modified internal/testing/dwarftestdata/testdata/rust/main.wasm.xz
100644 → 100755
Binary file not shown.
Loading
Loading