Skip to content

Commit 3e5b30b

Browse files
Start to port Wasmtime to the new wasi-io API with resources. (#7029)
* Rename `Host*` things to avoid name conflicts with bindings. * Update to the latest resource-enabled wit files. * Adapting the code to the new bindings. * Update wasi-http to the resource-enabled wit deps. * Start adapting the wasi-http code to the new bindings. * Make `get_directories` always return new owned handles. * Simplify the `poll_one` implementation. * Update the wasi-preview1-component-adapter. FIXME: temporarily disable wasi-http tests. Add logging to the cli world, since stderr is now a reseource that can only be claimed once. * Work around a bug hit by poll-list, fix a bug in poll-one. * Comment out `test_fd_readwrite_invalid_fd`, which panics now. * Fix a few FIXMEs. * Use `.as_ref().trapping_unwrap()` instead of `TrappingUnwrapRef`. * Use `drop_in_place`. * Remove `State::with_mut`. * Remove the `RefCell` around the `State`. * Update to wit-bindgen 0.12. * Update wasi-http to use resources for poll and I/O. This required making incoming-body and outgoing-body resourrces too, to work with `push_input_stream_child` and `push_output_stream_child`. * Re-enable disabled tests, remove logging from the worlds. * Remove the `poll_list` workarounds that are no longer needed. * Remove logging from the adapter. That said, there is no replacement yet, so add a FIXME comment. * Reenable a test that now passes. * Remove `.descriptors_mut` and use `with_descriptors_mut` instead. Replace `.descriptors()` and `.descriptors_mut()` with functions that take closures, which limits their scope, to prevent them from invalid aliasing. * Implement dynamic borrow checking for descriptors. * Add a cargo-vet audit for wasmtime-wmemcheck. * Update cargo vet for wit-bindgen 0.12. * Cut down on duplicate sync/async resource types (#1) * Allow calling `get-directories` more than once (#2) For now `Clone` the directories into new descriptor slots as needed. * Start to lift restriction of stdio only once (#3) * Start to lift restriction of stdio only once This commit adds new `{Stdin,Stdout}Stream` traits which take over the job of the stdio streams in `WasiCtxBuilder` and `WasiCtx`. These traits bake in the ability to create a stream at any time to satisfy the API of `wasi:cli`. The TTY functionality is folded into them as while I was at it. The implementation for stdin is relatively trivial since the stdin implementation already handles multiple streams reading it. Built-in impls of the `StdinStream` trait are also provided for helper types in `preview2::pipe` which resulted in the implementation of `MemoryInputPipe` being updated to support `Clone` where all clones read the same original data. * Get tests building * Un-ignore now-passing test * Remove unneeded argument from `WasiCtxBuilder::build` * Fix tests * Remove some workarounds Stdio functions can now be called multiple times. * If `poll_oneoff` fails part-way through, clean up properly. Fix the `Drop` implementation for pollables to only drop the pollables that have been successfully added to the list. This fixes the poll_oneoff_files failure and removes a FIXME. --------- Co-authored-by: Alex Crichton <[email protected]>
1 parent 4b288ba commit 3e5b30b

File tree

102 files changed

+5212
-4965
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

102 files changed

+5212
-4965
lines changed

Cargo.lock

+10-11
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ io-extras = "0.18.0"
213213
rustix = "0.38.8"
214214
is-terminal = "0.4.0"
215215
# wit-bindgen:
216-
wit-bindgen = { version = "0.11.0", default-features = false }
216+
wit-bindgen = { version = "0.12.0", default-features = false }
217217

218218
# wasm-tools family:
219219
wasmparser = "0.113.2"

crates/test-programs/command-tests/src/bin/stream_pollable_lifetimes.rs

+10-10
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
11
use command_tests::wasi::cli::environment;
22
use command_tests::wasi::cli::stdin;
3+
use command_tests::wasi::io::poll;
34
use command_tests::wasi::io::streams;
4-
use command_tests::wasi::poll::poll;
55

66
fn main() {
77
let args = environment::get_arguments();
88

99
if args == &["correct"] {
1010
let stdin: streams::InputStream = stdin::get_stdin();
11-
let stdin_pollable = streams::subscribe_to_input_stream(stdin);
12-
let ready = poll::poll_oneoff(&[stdin_pollable]);
13-
assert_eq!(ready, &[true]);
14-
poll::drop_pollable(stdin_pollable);
15-
streams::drop_input_stream(stdin);
11+
let stdin_pollable = stdin.subscribe();
12+
let ready = poll::poll_list(&[&stdin_pollable]);
13+
assert_eq!(ready, &[0]);
14+
drop(stdin_pollable);
15+
drop(stdin);
1616
} else if args == &["trap"] {
1717
let stdin: streams::InputStream = stdin::get_stdin();
18-
let stdin_pollable = streams::subscribe_to_input_stream(stdin);
19-
let ready = poll::poll_oneoff(&[stdin_pollable]);
20-
assert_eq!(ready, &[true]);
21-
streams::drop_input_stream(stdin);
18+
let stdin_pollable = stdin.subscribe();
19+
let ready = poll::poll_list(&[&stdin_pollable]);
20+
assert_eq!(ready, &[0]);
21+
drop(stdin);
2222
unreachable!(
2323
"execution should have trapped in line above when stream dropped before pollable"
2424
);

crates/test-programs/reactor-tests/src/lib.rs

+8-21
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,10 @@ wit_bindgen::generate!({
77
});
88

99
struct T;
10-
use wasi::io::streams;
11-
use wasi::poll::poll;
10+
use wasi::io::poll;
1211

1312
static mut STATE: Vec<String> = Vec::new();
1413

15-
struct DropPollable {
16-
pollable: poll::Pollable,
17-
}
18-
19-
impl Drop for DropPollable {
20-
fn drop(&mut self) {
21-
poll::drop_pollable(self.pollable);
22-
}
23-
}
24-
2514
impl Guest for T {
2615
fn add_strings(ss: Vec<String>) -> u32 {
2716
for s in ss {
@@ -40,34 +29,32 @@ impl Guest for T {
4029
}
4130

4231
fn write_strings_to(o: OutputStream) -> Result<(), ()> {
43-
let sub = DropPollable {
44-
pollable: streams::subscribe_to_output_stream(o),
45-
};
32+
let pollable = o.subscribe();
4633
unsafe {
4734
for s in STATE.iter() {
4835
let mut out = s.as_bytes();
4936
while !out.is_empty() {
50-
poll::poll_oneoff(&[sub.pollable]);
51-
let n = match streams::check_write(o) {
37+
poll::poll_list(&[&pollable]);
38+
let n = match o.check_write() {
5239
Ok(n) => n,
5340
Err(_) => return Err(()),
5441
};
5542

5643
let len = (n as usize).min(out.len());
57-
match streams::write(o, &out[..len]) {
44+
match o.write(&out[..len]) {
5845
Ok(_) => out = &out[len..],
5946
Err(_) => return Err(()),
6047
}
6148
}
6249
}
6350

64-
match streams::flush(o) {
51+
match o.flush() {
6552
Ok(_) => {}
6653
Err(_) => return Err(()),
6754
}
6855

69-
poll::poll_oneoff(&[sub.pollable]);
70-
match streams::check_write(o) {
56+
poll::poll_list(&[&pollable]);
57+
match o.check_write() {
7158
Ok(_) => {}
7259
Err(_) => return Err(()),
7360
}

0 commit comments

Comments
 (0)