Skip to content

Commit e14b18c

Browse files
authored
enable async tests for Go (#1454)
Also, I've updated the Go runtime patch to provide a private symbol (`wasiOnIdle`) rather than a public one (`WasiOnIdle`) and access it using a `//go:linkname` directive. Signed-off-by: Joel Dice <joel.dice@fermyon.com>
1 parent 4f08c3c commit e14b18c

File tree

4 files changed

+28
-9
lines changed

4 files changed

+28
-9
lines changed

.github/workflows/main.yml

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,12 +127,23 @@ jobs:
127127
- uses: actions/checkout@v4
128128
with:
129129
submodules: true
130+
130131
- name: Install Rust
131132
run: rustup update stable --no-self-update && rustup default stable
132133
- run: rustup target add wasm32-wasip2
134+
135+
# As of this writing, we need [a patched build of
136+
# Go](https://github.com/dicej/go/releases/tag/go1.25.5-wasi-on-idle) to
137+
# support async.
138+
- name: Install Patched Go
139+
run: |
140+
curl -OL https://github.com/dicej/go/releases/download/go1.25.5-wasi-on-idle/go-linux-amd64-bootstrap.tbz
141+
tar xf go-linux-amd64-bootstrap.tbz
142+
echo "$(pwd)/go-linux-amd64-bootstrap/bin" >> $GITHUB_PATH
143+
133144
- uses: ./.github/actions/install-wasi-sdk
134145
- run: |
135-
cargo run test --languages rust,c tests/runtime-async \
146+
cargo run test --languages rust,c,go tests/runtime-async \
136147
--artifacts target/artifacts \
137148
--rust-wit-bindgen-path ./crates/guest-rust \
138149
--runner "wasmtime -W component-model-async"

crates/go/README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@ world provided:
3333
- (if needed) `wit_types/wit_stream.go`: defines a `StreamReader` and `StreamWriter` types if required by the WIT world
3434
- (if needed) `wit_types/wit_future.go`: defines a `FutureReader` and `FutureWriter` types if required by the WIT world
3535

36+
Note that async support currently requires [a patched version of
37+
Go](https://github.com/dicej/go/releases/tag/go1.25.5-wasi-on-idle). Code
38+
generated for worlds that don't use any async features can be compiled using a
39+
stock release of Go.
40+
3641
## Example
3742

3843
### Prerequisites

crates/go/src/wit_async.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,9 @@ func Callback(event0, event1, event2 uint32) uint32 {
6464
return callback(event0, event1, event2)
6565
}
6666

67+
//go:linkname wasiOnIdle runtime.wasiOnIdle
68+
func wasiOnIdle(callback func() bool)
69+
6770
func callback(event0, event1, event2 uint32) uint32 {
6871
yielding := state.yielding
6972
if state.yielding != nil {
@@ -109,12 +112,12 @@ func callback(event0, event1, event2 uint32) uint32 {
109112
//
110113
// Note that this function is _not_ currently part of upstream Go; it
111114
// requires [this
112-
// patch](https://github.com/dicej/go/commit/a1c83220fc9576cdb810e9624366cb998e69b22b)
113-
runtime.WasiOnIdle(func() bool {
115+
// patch](https://github.com/dicej/go/commit/40fc123d5bce6448fc4e4601fd33bad4250b36a5)
116+
wasiOnIdle(func() bool {
114117
state.channel <- unit{}
115118
return true
116119
})
117-
defer runtime.WasiOnIdle(func() bool {
120+
defer wasiOnIdle(func() bool {
118121
return false
119122
})
120123

crates/test/src/go.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,16 @@ impl LanguageMethods for Go {
1818

1919
fn should_fail_verify(
2020
&self,
21-
_name: &str,
21+
name: &str,
2222
config: &crate::config::WitConfig,
2323
_args: &[String],
2424
) -> bool {
2525
// TODO: We _do_ support async, but only with a build of Go that has
2626
// [this
27-
// patch](https://github.com/dicej/go/commit/a1c83220fc9576cdb810e9624366cb998e69b22b).
28-
// Once we either publish builds containing that patch or upstream
29-
// something equivalent, we can remove the ` || config.async_` here.
30-
config.error_context || config.async_
27+
// patch](https://github.com/dicej/go/commit/40fc123d5bce6448fc4e4601fd33bad4250b36a5).
28+
// Once we upstream something equivalent, we can remove the ` || name ==
29+
// "async-trait-function.wit"` here.
30+
config.error_context || name == "async-trait-function.wit"
3131
}
3232

3333
fn default_bindgen_args_for_codegen(&self) -> &[&str] {

0 commit comments

Comments
 (0)