Skip to content

Support named imports of wasi:io in wasmtime-wasi - #14916

Closed
jrandolf wants to merge 2 commits into
bytecodealliance:mainfrom
jrandolf:wasi-io-named-imports
Closed

jrandolf wants to merge 2 commits into
bytecodealliance:mainfrom
jrandolf:wasi-io-named-imports

Conversation

@jrandolf

Copy link
Copy Markdown
Contributor

This builds on #14875, so only the last commit is new here.

wasmtime_wasi::p2::add_named_to_linker_async didn't handle labelled imports of wasi:io/{error,poll,streams}, so components importing them under a label, such as composed components whose dependencies are isolated from each other, failed to link. This adds them. wasi:io has no state besides the resource table, so each method looks up the table for the import's context and calls wasmtime-wasi-io.

wasi:clocks/timezone is still not covered, since wasmtime-wasi doesn't implement it at all.

Part of #14858

LLM summary of the changes

Bindings (wasi/src/p2/bindings.rs)

wasi:io/{error,poll,streams} are added to the named_imports of the async bindings. They get the same async/trappable/tracing rules as in wasmtime-wasi-io. Without labels these interfaces are aliased to wasmtime-wasi-io with with, so the rules only affect the named bindings. The resource types are the same as for unlabelled imports.

Linking (wasi/src/p2/mod.rs)

Interface gets IoError, IoPoll and IoStreams, and add_named_to_linker_with_options_async adds the three interfaces through a new HasIoNamed data type.

Implementation (wasi/src/p2/host/io.rs)

Each method of error, poll and streams looks up ctx(id).table and calls the corresponding wasmtime-wasi-io method, including convert_stream_error, which needs the id from #14875. As documented for named WASI contexts, a stream created through one label and used through another only works if their contexts share a ResourceTable.

Test (wasi/tests/all/p2)

A component imports wasi:cli/stdout and the wasi:io interfaces it uses under labels, and checks that output goes to the labelled context's stdout. It's written in WAT because a labelled wasi:cli/stdout using types from labelled wasi:io imports can't be written in WIT.

The `named_imports` option of `bindgen!` passes the host-chosen id to every
generated method except the `convert_*` methods for `trappable_error_type`.
These conversions can need the context for that id, though: converting the
`stream-error` of `wasi:io/streams`, for example, pushes an `error` resource
into a table, and with named imports the table is found through the id.

This commit threads the id through to these conversions as well, matching all
other methods of named-import traits, and updates the existing conversions in
`wasmtime-wasi` and `wasmtime-wasi-http` accordingly. This is in preparation
for supporting named imports of `wasi:io` interfaces.

Part of bytecodealliance#14858
`wasmtime_wasi::p2::add_named_to_linker_async` didn't handle labelled imports
of `wasi:io/{error,poll,streams}`, so components importing these interfaces
under a label, such as composed components whose dependencies were isolated
from each other, failed to link.

This commit adds these interfaces to the `named_imports` bindings and to
`add_named_to_linker_async`. `wasi:io` has no state outside of the resource
table, so the implementations look up the table for the named import and
then defer to `wasmtime-wasi-io`.

`wasi:clocks/timezone` remains unsupported both with and without labels as
`wasmtime-wasi` doesn't implement it.

Part of bytecodealliance#14858
@jrandolf
jrandolf marked this pull request as ready for review October 21, 2026 19:20
@jrandolf
jrandolf requested review from a team as code owners October 21, 2026 19:20
@jrandolf
jrandolf requested review from pchickey and rvolosatovs and removed request for a team October 21, 2026 19:20
@jrandolf jrandolf changed the title [DO NOT REVIEW] Support named imports of wasi:io in wasmtime-wasi Support named imports of wasi:io in wasmtime-wasi Oct 21, 2026
@github-actions github-actions Bot added wasi Issues pertaining to WASI wasmtime:api Related to the API of the `wasmtime` crate itself labels Oct 21, 2026
@pchickey

pchickey commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

I can't think of any reason a user might want to import wasi:io as a named import, or that an embedding would provide it as one. wasi:io is a singleton and so there being another instance of the same interface is nonsensical.

In general I see the wasip2 interfaces and implementations as being "done" and only getting bug fixes, and we are focusing all our energy for new development on wasip3. So, in general, I would require significant description of a real use case motivating that any of wasmtime's implementations of the p2 interfaces should be made compatible with named imports, even if unlike wasi:io they aren't a special case that should always be singular.

@jrandolf

Copy link
Copy Markdown
Contributor Author

Actually, this was an example listed in the spec which is why I added it. I also do not think it's needed. I think we can close this if everyone is on the same page

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

wasi Issues pertaining to WASI wasmtime:api Related to the API of the `wasmtime` crate itself

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants