pchickey opened PR #10036 from bytecodealliance:pch/wasi_io_crate to bytecodealliance:main:
Follow-on to https://github.com/bytecodealliance/wasmtime/pull/10016
This takes the bindings generation for the
wasi-iocrate, the definitions of theSubscribe,HostInputStream, andHostOutputStreamtraits, and the freshly separatedIoViewmachinery, and puts it into its own cratewasmtime-wasi-io.Users of
wasmtime-wasiand others never have to know or care about this change, thewasmtime-wasicrate re-exports everything now defined inwasmtime-wasi-ioat the same names as prior to this PR.Optionally, crates which depend on
wasmtime-wasifor just the wasi-io primitives May depend directly on wasmtime-wasi-io directly. I made changes in this PR so thatwasmtime-wasi-httpchanges its imports to be fromwasmtime-wasi-io.
wasmtime-wasi-httpcan't break its dep onwasmtime-wasifor two reasons: it depends onwasmtime_wasi::runtimeto provide common code forin_tokiosync wrappers of async and task spawning, and its linker needs to provide the std{in,out,err} interfaces from the wasi-cli implementation inwasmtime-wasi.The big motivator of this change is to provide a common definition of wasi-io to be reusable by alternative (to
wasmtime-wasi) implementations of the rest of WASI. In particular, this crate is compatible with!#[no_std]Rust.I had to make one minor functional change to
ResourceTable::iter_entriesandimpl poll::Host { fn poll(...) {...} }to use aBTreeMapin place of aHashMapin order to enable buildingwasmtime-wasi-iowithoutstdenabled in thewasmtimecrate features.
pchickey requested fitzgen for a review on PR #10036.
pchickey requested wasmtime-default-reviewers for a review on PR #10036.
pchickey requested wasmtime-core-reviewers for a review on PR #10036.
pchickey updated PR #10036.
pchickey updated PR #10036.
pchickey updated PR #10036.
pchickey updated PR #10036.
pchickey updated PR #10036.
pchickey updated PR #10036.
pchickey updated PR #10036.
pchickey updated PR #10036.
pchickey requested alexcrichton for a review on PR #10036.
pchickey commented on PR #10036:
I updated and wrote a bunch of docs for this PR that were not included in #10016 - ready for review now @alexcrichton
pchickey updated PR #10036.
pchickey edited PR #10036:
Follow-on to https://github.com/bytecodealliance/wasmtime/pull/10016
The big motivator of this change is to provide a common definition of wasi-io to be reusable by alternative (to
wasmtime-wasi) implementations of the rest of WASI. In particular, this crate is compatible with!#[no_std]Rust.Additionally, it contains renames for things that have been bugging me for a year or two.
New wasmtime-wasi-io crate
This takes the bindings generation for the
wasi-iocrate, the definitions of theSubscribe,HostInputStream, andHostOutputStreamtraits, and the freshly separatedIoViewmachinery, and puts it into its own cratewasmtime-wasi-io.Users of
wasmtime-wasiand others never have to know or care about the change to the crate, thewasmtime-wasicrate re-exports everything now defined inwasmtime-wasi-ioprior to the PR. However, names have changed!Optionally, crates which depend on
wasmtime-wasifor just the wasi-io primitives May depend directly on wasmtime-wasi-io directly. I made changes in this PR so thatwasmtime-wasi-httpchanges its imports to be fromwasmtime-wasi-io.
wasmtime-wasi-httpcan't break its dep onwasmtime-wasifor two reasons: it depends onwasmtime_wasi::runtimeto provide common code forin_tokiosync wrappers of async and task spawning, and its linker needs to provide the std{in,out,err} interfaces from the wasi-cli implementation inwasmtime-wasi.Trait and type renaming
Programmers using the direct bindings got to see the wit
Pollable,InputStream, andOutputStreamnames insideResource<...>. However, mapping from the resources to the traits is a boring bit of boilerplate that most programmers only ever encounter very briefly, and then spend most of their time interacting with the traits. The traits are the inconsistently-namedSubscribe,HostInputStream, andHostOutputStream.Host...prefix these days means bindgen-created, while back in wasi-common meant not-bindgen-created. AndSubscribedoesn't describe that trait at all!So, I renamed according to the following:
resource type Pollable -> DynPollable resource type InputStream -> DynInputStream resource type OutputStream -> DynOutputStream trait Subscribe -> Pollable trait HostInputStream -> InputStream trait HostOutputStream -> OutputStream type alias PollableFuture -> DynFuture (little-used) type alias ClosureFuture deleted (never used)etc
I had to make one minor functional change to
ResourceTable::iter_entriesandimpl poll::Host { fn poll(...) {...} }to use aBTreeMapin place of aHashMapin order to enable buildingwasmtime-wasi-iowithoutstdenabled in thewasmtimecrate features.
pchickey updated PR #10036.
alexcrichton submitted PR review.
alexcrichton created PR review comment:
As a proof-of-concept would it be possible to not add the dependency here? Or is it required that those using
wasmtime-wasihave to also depend onwasmtime-wasi-io?
pchickey submitted PR review.
pchickey created PR review comment:
Yes, its possible to not add the dependency and
useeverything through wasmtime-wasi. I'm happy to convert it over to that if you think that is valuable, I could go either way.
alexcrichton submitted PR review.
alexcrichton created PR review comment:
Yeah if you wouldn't mind doing that I think it'd be good to have an example and basically a test for that. In Spin for example I'd hope to ideally only need to refactor a bit and not have to explicitly pick up
wasmtime-wasi-io(otherwise we might need to extend docs more to mention it)
pchickey updated PR #10036.
pchickey submitted PR review.
pchickey created PR review comment:
Done - hitting merge.
pchickey has enabled auto merge for PR #10036.
pchickey updated PR #10036.
pchickey updated PR #10036.
pchickey has enabled auto merge for PR #10036.
pchickey updated PR #10036.
pchickey has enabled auto merge for PR #10036.
pchickey updated PR #10036.
pchickey updated PR #10036.
pchickey has enabled auto merge for PR #10036.
pchickey merged PR #10036.
Last updated: Dec 13 2025 at 21:03 UTC