Skip to content

go: add --stackful-exports for async exports - #1784

Merged
dicej merged 1 commit into
bytecodealliance:mainfrom
dgryski:dgryski/tinygo-wasip3
Nov 18, 2026
Merged

dicej merged 1 commit into
bytecodealliance:mainfrom
dgryski:dgryski/tinygo-wasip3

Conversation

@dgryski

@dgryski dgryski commented Nov 11, 2026

Copy link
Copy Markdown
Contributor

Adds --stackful-exports to the Go generator. With it, async exports use the [async-lift-stackful] ABI instead of callback-based [async-lift]:

  • the export is named [async-lift-stackful]<name> and no [callback] function is exported,
  • the wrapper runs the body in witAsync.Run(func() { ... }) and returns nothing, since the result is delivered via task.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::GuestExportAsyncStackful now lowers a result to memory like the other guest-export variants, replacing a todo!("stackful exports are not yet supported").

Dependencies

Needs the TinyGo implementation of wit/async from bytecodealliance/go-pkg#19 at runtime. This PR doesn't bump the crates/go/src/pkg submodule; that should follow once go-pkg#19 lands.

Testing

Generated bindings for a wasi:http/handler world 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.

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 dicej left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@dgryski

dgryski commented Nov 18, 2026

Copy link
Copy Markdown
Contributor Author

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.

@dicej

dicej commented Nov 18, 2026

Copy link
Copy Markdown
Collaborator

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.

@dicej
dicej added this pull request to the merge queue Nov 18, 2026
Merged via the queue into bytecodealliance:main with commit 2dae8a6 Nov 18, 2026
31 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants