Skip to content

Add async support to the component model C API#12973

Merged
alexcrichton merged 1 commit intobytecodealliance:mainfrom
chaynabors:add-component-async-c-api
Apr 8, 2026
Merged

Add async support to the component model C API#12973
alexcrichton merged 1 commit intobytecodealliance:mainfrom
chaynabors:add-component-async-c-api

Conversation

@chaynabors
Copy link
Copy Markdown
Contributor

@chaynabors chaynabors commented Apr 6, 2026

Closes #12955

Adds async equivalents of the component model C API, following the existing core module async patterns in async.h.

New functions:

  • wasm_component_model_async
  • wasm_component_model_async_builtins
  • wasm_component_model_async_stackful
  • wasmtime_component_func_call_async
  • wasmtime_component_linker_instantiate_async
  • wasmtime_component_linker_instance_add_func_async
  • wasmtime_component_linker_add_wasip2_async
  • wasmtime_component_linker_add_wasi_http_async

A few notes on the design:

  • No store-level value storage reuse (unlike core module's wasm_val_storage). The sync component model C API doesn't have it either, so this could be a follow-up for both sync and async.
  • C++ header only wraps the WASI/HTTP linker functions since the future-returning functions would need some fort of CallFuture wrapper that doesn't exist for core modules either. Should I add one?
  • Feature gated behind component-model-async, enabled by default in release builds. Should this be disabled by default?
  • No C API tests for async exist in the codebase today, including for non-component modules. Happy to add some scaffolding if we want it, and have a preference for how it's done.
  • I include async.h at the top with the rest of the includes. It's harmless since the file itself is entirely conditional in the interior but the import could be inlined further down. There wasn't any precedence and that gets messy so I didn't.

@chaynabors chaynabors force-pushed the add-component-async-c-api branch from 405336c to ab667f1 Compare April 6, 2026 19:14
@chaynabors chaynabors marked this pull request as ready for review April 6, 2026 19:32
@chaynabors chaynabors requested a review from a team as a code owner April 6, 2026 19:32
@chaynabors chaynabors requested review from alexcrichton and removed request for a team April 6, 2026 19:32
@chaynabors chaynabors force-pushed the add-component-async-c-api branch from ab667f1 to 7784a33 Compare April 6, 2026 19:48
@github-actions github-actions bot added the wasmtime:c-api Issues pertaining to the C API. label Apr 6, 2026
Copy link
Copy Markdown
Member

@alexcrichton alexcrichton left a comment

Choose a reason for hiding this comment

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

Thanks for this! Just some minor stylistic comments below, but overall looks great.

There's currently no tests in this PR, and while I realize that we don't currently have tests for async in the C/C++ APIs, would you be up for adding some at least simple tests for calling functions/host functions/etc?

@chaynabors chaynabors force-pushed the add-component-async-c-api branch 2 times, most recently from b2644ef to 85dad84 Compare April 8, 2026 17:11
Copy link
Copy Markdown
Member

@alexcrichton alexcrichton left a comment

Choose a reason for hiding this comment

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

Thanks again for this!

@alexcrichton alexcrichton added this pull request to the merge queue Apr 8, 2026
@chaynabors chaynabors force-pushed the add-component-async-c-api branch from 85dad84 to dec2b79 Compare April 8, 2026 17:48
@chaynabors
Copy link
Copy Markdown
Contributor Author

chaynabors commented Apr 8, 2026

@alexcrichton, found a bug with the implementation and resolved it. It appears that the PR is still queued. That feels a little scary from a security perspective so I figured I'd flag? I'm not sure if it's attempting to merge 85dad84 or dec2b79.

Thanks for the nits, I fixed both of them and added tests for module-level and component model async as I'm sure you've already realized. I'll short circuit the ask for tests next time. Thanks for the quick turnaround.

@chaynabors chaynabors marked this pull request as draft April 8, 2026 17:59
@chaynabors chaynabors requested a review from alexcrichton April 8, 2026 17:59
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Apr 8, 2026
@chaynabors chaynabors marked this pull request as ready for review April 8, 2026 18:05
@chaynabors
Copy link
Copy Markdown
Contributor Author

chaynabors commented Apr 8, 2026

Alright, it appears that when I pushed to the branch tests got cancelled and took a bit to propagate. Would make a lot more sense for the approved commit before the push to have been merged otherwise the merge queue is unhermetic?

In any case, checks appear to be bugging out in GitHub, but they pass locally. Sorry for the trouble.

@alexcrichton alexcrichton reopened this Apr 8, 2026
@alexcrichton
Copy link
Copy Markdown
Member

Ah no worries, github merge queues are a bit weird if someone with non-write-access to the repo pushes while it's in the queue, but nothing bad happens it just means that the previous version of the PR is tested/enqueued. The main weird part is that had tests passed this PR would have merged without your updated changes, but that's mostly a github thing.

The tests actually failed due to a completely unrelated spurious failure, but hey worked out!

And yeah sometimes github doesn't actually run PR CI. No idea why, but closing/reopening a PR often fixes that.

@alexcrichton alexcrichton enabled auto-merge April 8, 2026 18:30
@alexcrichton alexcrichton added this pull request to the merge queue Apr 8, 2026
Merged via the queue into bytecodealliance:main with commit 22b2684 Apr 8, 2026
52 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

wasmtime:c-api Issues pertaining to the C API.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

c-api: Async support for the component model

2 participants