Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WASI Preview 2: rewrite streams and pollable implementation #6556

Merged
merged 122 commits into from
Jul 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
122 commits
Select commit Hold shift + click to select a range
585f9fb
preview2: make everything but streams/io and poll/poll synchronous
Jun 1, 2023
d647665
streams: get rid of as_any method, which is no longer used
Jun 1, 2023
9d04496
delete legacy sched and pollable concepts
Jun 1, 2023
cda675b
more code motion and renaming
Jun 2, 2023
8233f7c
make tokio a workspace dep, because we need it directly in wasmtime-wasi
Jun 8, 2023
0f8f79e
HostPollable exists
Jun 8, 2023
a3a3dbc
more fixes
Jun 8, 2023
1183313
pollable can trap, and implement clock properly
Jun 8, 2023
93913f7
HostPollable is now a generator of futures
Jun 9, 2023
f670a06
explain various todo!s
Jun 8, 2023
a71719b
Synchronous version of the wasi-preview2-components tests
elliottt Jun 9, 2023
4d87859
Change with_tokio to accept the future as an argument
elliottt Jun 15, 2023
6c4f0ae
Store futures in the PollOneoff struct instead, to avoid dropping them
elliottt Jun 15, 2023
444d011
Remove TODO for HostOutputStream impl for WritePipe
elliottt Jun 15, 2023
8ee7f35
Implement pollable for ReadPipe
elliottt Jun 15, 2023
ff4e314
Use a Notify when ReadPipe is ready
elliottt Jun 16, 2023
e5b1aff
wip
elliottt Jun 21, 2023
96ea603
wip
elliottt Jun 21, 2023
cdd1dce
Read/write pipe ends with tokio channels
elliottt Jun 21, 2023
8aa1ca8
Empty reader/writer wrappers
elliottt Jun 21, 2023
f1b93a2
EmptyStream, and warning cleanup
elliottt Jun 21, 2023
9680e7e
Wrapped reader/writer structs
elliottt Jun 22, 2023
c76cce5
Rework stdio in terms of wrapped read/write
elliottt Jun 22, 2023
a5151e9
Add MemoryOutputPipe and update tests
elliottt Jun 22, 2023
d11c286
Remove todo
elliottt Jun 22, 2023
8927d69
Merge remote-tracking branch 'origin/main' into pch/preview2_async_st…
Jun 22, 2023
ac71a90
rewrite nearly everything
Jun 23, 2023
35d8b6a
implement the pipe stuff
Jun 23, 2023
a2326e7
wibble
Jun 23, 2023
621956f
fix MemoryOutputPipe just enough to make the tests compile
Jun 23, 2023
2b793ef
Move the table iteration into a helper function
elliottt Jun 23, 2023
1dedcf2
AsyncFd stream implementation to fix stdin on unix
elliottt Jun 23, 2023
8001a7a
Rename Wrapped{Read,Write} streams to Async{Read,Write}Stream
elliottt Jun 23, 2023
31f4c6b
Move async io wrappers into stream.rs
elliottt Jun 23, 2023
0606259
Fix the sync tests
elliottt Jun 24, 2023
e34152a
Merge remote-tracking branch 'origin/main' into pch/preview2_async_st…
Jun 26, 2023
d6389e6
fix test uses of pipes, juggle tokio context for stdin construction
Jun 27, 2023
6079001
add some fixmes
Jun 27, 2023
2924bba
the future i named Never is defined in futures-util as pending
Jun 27, 2023
7dd2ef9
i believe this is a correct implementation of one global stdin resource
Jun 27, 2023
983dfdf
move unix stdin to its own file
Jun 27, 2023
25d560b
make most of the mods private
Jun 27, 2023
7e93432
fix build - we are skipping rust 1.70
Jun 27, 2023
66d5890
preview1-in-preview2: use async funcs for io, and the async io interface
Jun 27, 2023
25a1523
windows stdin support
Jun 27, 2023
b436efb
Merge remote-tracking branch 'origin/main' into pch/preview2_async_st…
Jun 27, 2023
75d24f7
done!
Jun 27, 2023
d0d67bc
table ext functions: fix tests
Jun 28, 2023
6cc97da
tests: expect poll_oneoff_{files,stdio} to pass on all platforms
Jun 28, 2023
9d06871
export the bindings under wasmtime_wasi::preview2::bindings
Jun 28, 2023
6994d6c
fix renaming of wasi to bindings in tests
Jun 29, 2023
3f7561f
use block_in_place throughout filesystem
Jun 29, 2023
789beec
AsyncFdStream: ensure file is nonblocking
Jun 29, 2023
9da134b
tests: block_in_place requires multi-threaded runtime
Jun 29, 2023
783966f
actually, use fcntl_setfl to make the asyncfd file nonblocking
Jun 29, 2023
a699981
fix windows block_on
Jun 29, 2023
1f39f9d
docs, remove unnecessary methods
Jun 29, 2023
22f340a
more docs
Jun 29, 2023
6b47b1b
Add a workspace dependency on bytes-1.4
elliottt Jul 12, 2023
26be285
Remove vectored stream operations
elliottt Jul 12, 2023
173d545
Rework the read/write stream traits
elliottt Jul 12, 2023
9ae4754
Add a size parameter to `read`, and switch to usize for traits
elliottt Jul 12, 2023
70b0b76
Pipe through the bool -> stream-status change in wit
elliottt Jul 12, 2023
99cb341
Plumb stream-status through write operations in wit
elliottt Jul 13, 2023
6e122cf
write host trait also gives streamstate
Jul 13, 2023
44e373e
hook new stream host read/write back up to the wit bindgen
Jul 13, 2023
f01ee86
sketchy AsyncReadStream impl
Jul 13, 2023
fc4652c
Fill out implementations for AsyncReadStream and AsyncWriteStream
elliottt Jul 14, 2023
6b3ce6a
some reasonable read tests
Jul 14, 2023
276fdfc
more
Jul 14, 2023
63d346e
first smoke test for AsyncWriteStream
Jul 14, 2023
9ec8f55
bunch of AsyncWriteStream tests
Jul 14, 2023
3eb762e
half-baked idea that the output-stream interface will need a flush me…
Jul 14, 2023
22e74d2
adapter: fixes for changes to stream wit
Jul 14, 2023
9533039
fix new rust 1.71 warnings
Jul 14, 2023
189fcf9
make stdin work on unix without using AsyncFdStream
Jul 15, 2023
db17624
delete AsyncFdStream for now
Jul 15, 2023
146a58b
Implement some memory pipe operations, and move async wrappers to the…
elliottt Jul 18, 2023
eacfe90
Make blocking_write actually block until everything is written
elliottt Jul 18, 2023
842bb38
Remove debug print
elliottt Jul 18, 2023
56112b4
Adapter stdio should use blocking write
elliottt Jul 18, 2023
6d1711a
Clean up implementations of {blocking_}write_zeros and skip
elliottt Jul 18, 2023
0a72164
Remove debug macro usage
elliottt Jul 18, 2023
4babe7e
Move EmptyStream to pipe, and split it into four variants
elliottt Jul 18, 2023
f1daf36
Add a big warning about resource lifetime tracking in pollables
elliottt Jul 18, 2023
1c4cff5
Start working through changes to the filesystem implementation
elliottt Jul 19, 2023
51fae7d
Remove todos in the filesystem implementation
elliottt Jul 19, 2023
0f1d7ff
Avoid lifetime errors by moving blocking operations to File and Dir
elliottt Jul 19, 2023
d1e1e50
Fix more lifetime issues with `block`
elliottt Jul 19, 2023
73a5f41
Finish filling out translation impl
elliottt Jul 19, 2023
799249c
fix warnings
Jul 19, 2023
b062968
we can likely eliminate block_in_place in the stdin implementations
Jul 19, 2023
fa92e35
sync command uses sync filesystem, start of translation layer
Jul 19, 2023
d0925d4
symc filesystem: all the trait boilerplate is in place
Jul 19, 2023
d02c6c2
finish type conversion boilerplate
Jul 19, 2023
95df882
Revert "half-baked idea that the output-stream interface will need a …
Jul 19, 2023
1e59531
cargo fmt
Jul 19, 2023
2b4a3fd
Merge remote-tracking branch 'origin/main' into pch/preview2_async_st…
Jul 19, 2023
5abe3f0
test type fixes
Jul 19, 2023
84742b0
renames and comments
Jul 19, 2023
b577f74
refactor stream table internals so we can have a blocking variant...
Jul 20, 2023
4bbf669
preview1 host adapter: stdout/stderr use blocking_write here too
Jul 20, 2023
b540814
filesystem streams are blocking now
Jul 20, 2023
90d87c3
fixes
Jul 20, 2023
6d39ecf
satisfy cargo doc
Jul 20, 2023
8fe0708
cargo vet: dep upgrades taken care of by imports from mozilla
Jul 20, 2023
d21b556
unix stdio: eliminate block_in_place
Jul 20, 2023
f6c28ef
replace private in_tokio with spawn, since its only used for spawning
Jul 20, 2023
db4f882
comments
Jul 20, 2023
f60b57f
worker thread stdin implementation can be tested on linux, i guess
Jul 20, 2023
0a4d500
eliminate tokio boilerplate - no longer using tokios lock
Jul 20, 2023
834430f
rename our private block_on to in_tokio
Jul 20, 2023
9d9d3f5
fill in missing file input skip
Jul 20, 2023
be9a4b6
code review: fix MemoryInputPipe. Closed status is always available i…
Jul 21, 2023
a3e31b3
code review: empty input stream is not essential, closed input stream…
Jul 21, 2023
3c2f413
code review: unreachable
Jul 21, 2023
fa61800
turn worker thread (windows) stdin off
Jul 21, 2023
2374cd1
expect preview2-based poll_oneoff_stdio to fail on windows
Jul 21, 2023
32fcfa2
command directory_list test: no need to inherit stdin
Jul 21, 2023
9cd4221
preview1 in preview2: turn off inherit_stdio except for poll_oneoff_s…
Jul 21, 2023
dd15998
wasi-preview2-components: apparently inherit_stdio was on everywhere …
Jul 21, 2023
6aae4ea
extend timeout for riscv64 i suppose
Jul 22, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 28 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,9 @@ tempfile = "3.1.0"
filecheck = "0.5.0"
libc = "0.2.60"
file-per-thread-logger = "0.2.0"
tokio = { version = "1.26.0" }
bytes = "1.4"
futures = { version = "0.3.27", default-features = false }
indexmap = "2.0.0"
pretty_env_logger = "0.5.0"
syn = "2.0.25"
Expand Down
2 changes: 1 addition & 1 deletion crates/test-programs/reactor-tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ publish = false
crate-type=["cdylib"]

[dependencies]
wit-bindgen = { workspace = true }
wit-bindgen = { workspace = true, features = ["macros", "realloc"] }
67 changes: 32 additions & 35 deletions crates/test-programs/tests/command.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,15 @@
use anyhow::Result;
use cap_std::{ambient_authority, fs::Dir, time::Duration};
use std::{
io::{Cursor, Write},
sync::Mutex,
};
use std::{io::Write, sync::Mutex};
use wasmtime::{
component::{Component, Linker},
Config, Engine, Store,
};
use wasmtime_wasi::preview2::{
clocks::{HostMonotonicClock, HostWallClock},
pipe::ReadPipe,
wasi::command::add_to_linker,
wasi::command::Command,
DirPerms, FilePerms, Table, WasiCtx, WasiCtxBuilder, WasiView,
command::{add_to_linker, Command},
pipe::MemoryInputPipe,
DirPerms, FilePerms, HostMonotonicClock, HostWallClock, Table, WasiCtx, WasiCtxBuilder,
WasiView,
};

lazy_static::lazy_static! {
Expand Down Expand Up @@ -63,7 +59,7 @@ async fn instantiate(
Ok((store, command))
}

#[test_log::test(tokio::test)]
#[test_log::test(tokio::test(flavor = "multi_thread"))]
async fn hello_stdout() -> Result<()> {
let mut table = Table::new();
let wasi = WasiCtxBuilder::new()
Expand All @@ -77,7 +73,7 @@ async fn hello_stdout() -> Result<()> {
.map_err(|()| anyhow::anyhow!("command returned with failing exit status"))
}

#[test_log::test(tokio::test)]
#[test_log::test(tokio::test(flavor = "multi_thread"))]
async fn panic() -> Result<()> {
let mut table = Table::new();
let wasi = WasiCtxBuilder::new()
Expand All @@ -100,7 +96,7 @@ async fn panic() -> Result<()> {
Ok(())
}

#[test_log::test(tokio::test)]
#[test_log::test(tokio::test(flavor = "multi_thread"))]
async fn args() -> Result<()> {
let mut table = Table::new();
let wasi = WasiCtxBuilder::new()
Expand All @@ -114,7 +110,7 @@ async fn args() -> Result<()> {
.map_err(|()| anyhow::anyhow!("command returned with failing exit status"))
}

#[test_log::test(tokio::test)]
#[test_log::test(tokio::test(flavor = "multi_thread"))]
async fn random() -> Result<()> {
let mut table = Table::new();
let wasi = WasiCtxBuilder::new().build(&mut table)?;
Expand All @@ -127,7 +123,7 @@ async fn random() -> Result<()> {
.map_err(|()| anyhow::anyhow!("command returned with failing exit status"))
}

#[test_log::test(tokio::test)]
#[test_log::test(tokio::test(flavor = "multi_thread"))]
async fn time() -> Result<()> {
struct FakeWallClock;

Expand Down Expand Up @@ -173,13 +169,13 @@ async fn time() -> Result<()> {
.map_err(|()| anyhow::anyhow!("command returned with failing exit status"))
}

#[test_log::test(tokio::test)]
#[test_log::test(tokio::test(flavor = "multi_thread"))]
async fn stdin() -> Result<()> {
let mut table = Table::new();
let wasi = WasiCtxBuilder::new()
.set_stdin(ReadPipe::new(Cursor::new(
"So rested he by the Tumtum tree",
)))
.set_stdin(MemoryInputPipe::new(
"So rested he by the Tumtum tree".into(),
))
.build(&mut table)?;

let (mut store, command) =
Expand All @@ -191,13 +187,13 @@ async fn stdin() -> Result<()> {
.map_err(|()| anyhow::anyhow!("command returned with failing exit status"))
}

#[test_log::test(tokio::test)]
#[test_log::test(tokio::test(flavor = "multi_thread"))]
async fn poll_stdin() -> Result<()> {
let mut table = Table::new();
let wasi = WasiCtxBuilder::new()
.set_stdin(ReadPipe::new(Cursor::new(
"So rested he by the Tumtum tree",
)))
.set_stdin(MemoryInputPipe::new(
"So rested he by the Tumtum tree".into(),
))
.build(&mut table)?;

let (mut store, command) =
Expand All @@ -209,7 +205,7 @@ async fn poll_stdin() -> Result<()> {
.map_err(|()| anyhow::anyhow!("command returned with failing exit status"))
}

#[test_log::test(tokio::test)]
#[test_log::test(tokio::test(flavor = "multi_thread"))]
async fn env() -> Result<()> {
let mut table = Table::new();
let wasi = WasiCtxBuilder::new()
Expand All @@ -226,7 +222,7 @@ async fn env() -> Result<()> {
.map_err(|()| anyhow::anyhow!("command returned with failing exit status"))
}

#[test_log::test(tokio::test)]
#[test_log::test(tokio::test(flavor = "multi_thread"))]
async fn file_read() -> Result<()> {
let dir = tempfile::tempdir()?;

Expand All @@ -248,7 +244,7 @@ async fn file_read() -> Result<()> {
.map_err(|()| anyhow::anyhow!("command returned with failing exit status"))
}

#[test_log::test(tokio::test)]
#[test_log::test(tokio::test(flavor = "multi_thread"))]
async fn file_append() -> Result<()> {
let dir = tempfile::tempdir()?;

Expand Down Expand Up @@ -280,7 +276,7 @@ async fn file_append() -> Result<()> {
Ok(())
}

#[test_log::test(tokio::test)]
#[test_log::test(tokio::test(flavor = "multi_thread"))]
async fn file_dir_sync() -> Result<()> {
let dir = tempfile::tempdir()?;

Expand All @@ -303,7 +299,7 @@ async fn file_dir_sync() -> Result<()> {
.map_err(|()| anyhow::anyhow!("command returned with failing exit status"))
}

#[test_log::test(tokio::test)]
#[test_log::test(tokio::test(flavor = "multi_thread"))]
async fn exit_success() -> Result<()> {
let mut table = Table::new();
let wasi = WasiCtxBuilder::new().build(&mut table)?;
Expand All @@ -320,7 +316,7 @@ async fn exit_success() -> Result<()> {
Ok(())
}

#[test_log::test(tokio::test)]
#[test_log::test(tokio::test(flavor = "multi_thread"))]
async fn exit_default() -> Result<()> {
let mut table = Table::new();
let wasi = WasiCtxBuilder::new().build(&mut table)?;
Expand All @@ -333,7 +329,7 @@ async fn exit_default() -> Result<()> {
Ok(())
}

#[test_log::test(tokio::test)]
#[test_log::test(tokio::test(flavor = "multi_thread"))]
async fn exit_failure() -> Result<()> {
let mut table = Table::new();
let wasi = WasiCtxBuilder::new().build(&mut table)?;
Expand All @@ -350,7 +346,7 @@ async fn exit_failure() -> Result<()> {
Ok(())
}

#[test_log::test(tokio::test)]
#[test_log::test(tokio::test(flavor = "multi_thread"))]
async fn exit_panic() -> Result<()> {
let mut table = Table::new();
let wasi = WasiCtxBuilder::new().build(&mut table)?;
Expand All @@ -367,7 +363,7 @@ async fn exit_panic() -> Result<()> {
Ok(())
}

#[test_log::test(tokio::test)]
#[test_log::test(tokio::test(flavor = "multi_thread"))]
async fn directory_list() -> Result<()> {
let dir = tempfile::tempdir()?;

Expand All @@ -382,7 +378,8 @@ async fn directory_list() -> Result<()> {

let mut table = Table::new();
let wasi = WasiCtxBuilder::new()
.inherit_stdio()
.inherit_stdout()
.inherit_stderr()
.push_preopened_dir(open_dir, DirPerms::all(), FilePerms::all(), "/")
.build(&mut table)?;

Expand All @@ -395,7 +392,7 @@ async fn directory_list() -> Result<()> {
.map_err(|()| anyhow::anyhow!("command returned with failing exit status"))
}

#[test_log::test(tokio::test)]
#[test_log::test(tokio::test(flavor = "multi_thread"))]
async fn default_clocks() -> Result<()> {
let mut table = Table::new();
let wasi = WasiCtxBuilder::new().build(&mut table)?;
Expand All @@ -409,7 +406,7 @@ async fn default_clocks() -> Result<()> {
.map_err(|()| anyhow::anyhow!("command returned with failing exit status"))
}

#[test_log::test(tokio::test)]
#[test_log::test(tokio::test(flavor = "multi_thread"))]
async fn export_cabi_realloc() -> Result<()> {
let mut table = Table::new();
let wasi = WasiCtxBuilder::new().build(&mut table)?;
Expand All @@ -425,7 +422,7 @@ async fn export_cabi_realloc() -> Result<()> {
.map_err(|()| anyhow::anyhow!("command returned with failing exit status"))
}

#[test_log::test(tokio::test)]
#[test_log::test(tokio::test(flavor = "multi_thread"))]
async fn read_only() -> Result<()> {
let dir = tempfile::tempdir()?;

Expand Down
Loading