Repository navigation
go: add --stackful-exports for async exports - #1784
Conversation
Add an option that makes async exports stackful. The generated code uses the [async-lift-stackful] name, does not export a [callback] function and returns nothing from the wrapper, since the result goes through task.return. This is for runtimes that can block a thread, such as TinyGo with cooperative threads. In the core ABI, lower a result to memory for stackful exports the same way as for the other export variants. This replaces a todo.
dicej
left a comment
There was a problem hiding this comment.
Thanks, @dgryski. Great to see the stackful async ABI finally being used in guest code, and I'm pleasantly surprised how little needed to change here.
Now that bytecodealliance/go-pkg#19 is merged, I assume we'll want to make a release of that project and bump REMOTE_PKG_VERSION here to match. At that point, will we be able to enable runtime and (if it's not redundant) compile-time tests using TinyGo as well as big Go in CI? If so, I'd like to see that happen either as part of this PR or a follow up so that nothing regresses silently.
|
My tinygo waspi3 port is here: https://github.com/dgryski/tinygo/tree/dgryski/wasip3 . It uses tinygo's pthread-based scheduler along with the support in wasi-libc ( WebAssembly/wasi-libc#799 ) to run as a basic port. The pthreads work means we don't have to rely on asyncify, which is fantastic. TinyGo can also use wit-bindgen generated bindings directly to run on wasip3 hosts and make calls into components. After this PR is merged, I'll open a PR for tinygo, and when that is merged and we have the next stable release (0.45, probably before the end of the year) we can figure out what we're going to add to CI. We can add regular Go to CI in the meantime. |
Sounds good. Note that we already have regular Go CI; I was just wondering when we could add TinyGo as well. |
Adds
--stackful-exportsto the Go generator. With it, async exports use the[async-lift-stackful]ABI instead of callback-based[async-lift]:[async-lift-stackful]<name>and no[callback]function is exported,witAsync.Run(func() { ... })and returns nothing, since the result is delivered viatask.return.This is for runtimes that can block a thread inside an export, such as TinyGo's wasip3 target with cooperative threads. The default output is unchanged.
In
crates/core/src/abi.rs,AbiVariant::GuestExportAsyncStackfulnow lowers a result to memory like the other guest-export variants, replacing atodo!("stackful exports are not yet supported").Dependencies
Needs the TinyGo implementation of
wit/asyncfrom bytecodealliance/go-pkg#19 at runtime. This PR doesn't bump thecrates/go/src/pkgsubmodule; that should follow once go-pkg#19 lands.Testing
Generated bindings for a
wasi:http/handlerworld with--stackful-exports --generate-stubs, built with TinyGo's wasip3 target, and ran the component under wasmtime (async import, streamed bodies, overlapping requests).I haven't added a codegen test in
tests/yet. Happy to add one if you can point me at the preferred place for an option-specific Go test.