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-io
crate, the definitions of theSubscribe
,HostInputStream
, andHostOutputStream
traits, and the freshly separatedIoView
machinery, and puts it into its own cratewasmtime-wasi-io
.Users of
wasmtime-wasi
and others never have to know or care about this change, thewasmtime-wasi
crate re-exports everything now defined inwasmtime-wasi-io
at the same names as prior to this PR.Optionally, crates which depend on
wasmtime-wasi
for just the wasi-io primitives May depend directly on wasmtime-wasi-io directly. I made changes in this PR so thatwasmtime-wasi-http
changes its imports to be fromwasmtime-wasi-io
.
wasmtime-wasi-http
can't break its dep onwasmtime-wasi
for two reasons: it depends onwasmtime_wasi::runtime
to provide common code forin_tokio
sync 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_entries
andimpl poll::Host { fn poll(...) {...} }
to use aBTreeMap
in place of aHashMap
in order to enable buildingwasmtime-wasi-io
withoutstd
enabled in thewasmtime
crate 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-io
crate, the definitions of theSubscribe
,HostInputStream
, andHostOutputStream
traits, and the freshly separatedIoView
machinery, and puts it into its own cratewasmtime-wasi-io
.Users of
wasmtime-wasi
and others never have to know or care about the change to the crate, thewasmtime-wasi
crate re-exports everything now defined inwasmtime-wasi-io
prior to the PR. However, names have changed!Optionally, crates which depend on
wasmtime-wasi
for just the wasi-io primitives May depend directly on wasmtime-wasi-io directly. I made changes in this PR so thatwasmtime-wasi-http
changes its imports to be fromwasmtime-wasi-io
.
wasmtime-wasi-http
can't break its dep onwasmtime-wasi
for two reasons: it depends onwasmtime_wasi::runtime
to provide common code forin_tokio
sync 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
, andOutputStream
names 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. AndSubscribe
doesn'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_entries
andimpl poll::Host { fn poll(...) {...} }
to use aBTreeMap
in place of aHashMap
in order to enable buildingwasmtime-wasi-io
withoutstd
enabled in thewasmtime
crate 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-wasi
have to also depend onwasmtime-wasi-io
?
pchickey submitted PR review.
pchickey created PR review comment:
Yes, its possible to not add the dependency and
use
everything 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: Jan 24 2025 at 00:11 UTC