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-common support for tokio, & wiggle support for async methods containing sync code #2832

Merged
merged 73 commits into from
May 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
73 commits
Select commit Hold shift + click to select a range
c62d7f9
wasmtime_wiggle: when async feature is disabled, run async on dummy e…
pchickey Apr 13, 2021
68daec7
wasi-common: WasiSched is an async trait now; poll_oneoff and sched_y…
pchickey Apr 13, 2021
22d18ff
cap-std-sync: async-trait e-paperwork
pchickey Apr 13, 2021
ac3b456
wasi-cap-std-async: exactly like wasi-cap-std-sync but with a differe…
pchickey Apr 13, 2021
8f9fb1f
make wasi-cap-std-async work with wasmtime-wasi
pchickey Apr 13, 2021
201da20
make wasmtime-wasi configurable at macro whether its real async or bl…
pchickey Apr 13, 2021
2b7a93c
wasmtime-wasi: two distinct definitions of the Wasi struct, when sync…
pchickey Apr 13, 2021
bac02c5
port command and example to use sync wasmtime_wasi
pchickey Apr 13, 2021
66251c2
c-api: always use synchronous wasi-common
pchickey Apr 13, 2021
7590198
add tokio example
pchickey Apr 14, 2021
247795c
fix
pchickey Apr 14, 2021
c691d18
fix
pchickey Apr 14, 2021
0127676
wasi-cap-std-async is better named wasi-tokio
pchickey Apr 14, 2021
228096c
wiggle: convenient syntax for marking all funcs async
pchickey Apr 14, 2021
025a1ec
wasi-common: snapshots 0 and 1 traits are all async now
pchickey Apr 14, 2021
00e5856
WasiFile: all operations are now async
pchickey Apr 14, 2021
564e43d
WasiDir: make all operations async
pchickey Apr 14, 2021
c0e89b8
wasi-cap-std-sync: WasiFile and WasiDir converted to async_traits
pchickey Apr 14, 2021
2f0c7e5
wasmtime-wasi: all funcs are async now
pchickey Apr 14, 2021
b883bda
fix test-programs for sync wasi
pchickey Apr 14, 2021
7202494
fix windows sched
pchickey Apr 14, 2021
2ddf4c1
tokio example requires enabling a cargo feature
pchickey Apr 14, 2021
33dbd43
use tokio's File with a cap-std Dir
pchickey Apr 15, 2021
9880d09
do some programming
pchickey Apr 15, 2021
d2a98ce
use some better traits
pchickey Apr 15, 2021
675b579
use AsyncSeek
pchickey Apr 19, 2021
8667d8c
test-programs: test wasi-tokio
pchickey Apr 19, 2021
3d3a2ac
wasi-tokio: WIP need to port the sync scheduler into a spawn_blocking
pchickey Apr 19, 2021
27464c8
cargo.lock
pchickey Apr 19, 2021
fa44ec2
tokio sched: comment out just to make it compile
pchickey Apr 26, 2021
b307dce
add readable and writable futures to WasiFile trait
pchickey Apr 26, 2021
867d2c9
follow the types
pchickey Apr 26, 2021
a532d0f
subscribe to mut fds
pchickey Apr 26, 2021
02581dd
poll_oneoff test: don't try to poll same fd for read and write
pchickey Apr 28, 2021
b3e1ab4
restructure Poll to hold a Table and fd instead of a RefMut<dyn WasiF…
pchickey Apr 28, 2021
ab4f5bb
move dummy executor out to wiggle:: for reuse
pchickey Apr 29, 2021
b7efcbe
jump through enough hoops for the poll lifetime to work out
pchickey Apr 29, 2021
7f34ccb
various fixes to the design of Poll
pchickey Apr 30, 2021
62c4f0d
wasi-tokio kinda sorta working
pchickey May 1, 2021
3df9cdd
better unit test
pchickey May 3, 2021
5ab8346
fix windows sync scheduler
pchickey May 3, 2021
686d8c2
fix test harness
pchickey May 4, 2021
f76fe8b
rewrite wasi-tokio as just an task::block_in_place wrapper on cap-std…
pchickey May 4, 2021
e0f3423
support windows
pchickey May 4, 2021
0faf3b2
wasmtime-wasi: keep exporting sync at the top level
pchickey May 5, 2021
f8d1e57
publish wasi-tokio
pchickey May 5, 2021
3e8ea09
ci debugging
pchickey May 5, 2021
909d691
run wasi-tokio test early, turn off fail-fast so we see all platforms
pchickey May 5, 2021
9e04c53
poll oneoff tests: what if we read a non-empty file?
pchickey May 5, 2021
6616c1e
fix warnings
pchickey May 5, 2021
148afd3
fix yaml syntax
pchickey May 5, 2021
2a0eb39
get rid of debugging changes to ci
pchickey May 6, 2021
f4d8511
tests dont need fuel
pchickey May 6, 2021
208013e
de-duplicate code
pchickey May 6, 2021
f3ffd74
dont depend on wiggle for just the one func
pchickey May 6, 2021
76be195
explain!
pchickey May 6, 2021
e50f1b2
better name and comment
pchickey May 6, 2021
b0335d3
fixes to example
pchickey May 6, 2021
3d9b98f
fix example
pchickey May 6, 2021
ff8bdc3
reuse cap-std-syncs windows scheduler without copypaste
pchickey May 6, 2021
add115b
fix
pchickey May 6, 2021
b19d862
fix test harness stdio
pchickey May 6, 2021
35a9d4e
less general mechanism for examples cargo feature
pchickey May 6, 2021
e9f410d
run_in_dummy_executor isnt unsafe, its just a bad idea
pchickey May 6, 2021
b7593cb
Merge remote-tracking branch 'origin/main' into pch/wiggle_sync_shimming
pchickey May 7, 2021
9b09272
poll_oneoff: bound tests for time, rather than instant completion
pchickey May 7, 2021
ee8a8a2
poll_oneoff_stdio test: loosen up contract
pchickey May 7, 2021
68fdadd
tokio poll_oneoff test: CI needs more than 1ms to complete it
pchickey May 7, 2021
b450094
debug
pchickey May 7, 2021
86bd56f
turn off fail-fast again
pchickey May 7, 2021
548b6c5
windows fixes
pchickey May 7, 2021
74e9b38
lets try 10ms, macos ci timed out with 5ms
pchickey May 7, 2021
bae1a56
10ms here, and let it timeout in addition to ready?
pchickey May 7, 2021
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
2 changes: 2 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ jobs:
name: Test
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
build: [stable, beta, nightly, windows, macos]
include:
Expand Down Expand Up @@ -382,6 +383,7 @@ jobs:
name: Build wasmtime
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
include:
- build: x86_64-linux
Expand Down
121 changes: 119 additions & 2 deletions Cargo.lock

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

7 changes: 7 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ tempfile = "3.1.0"
test-programs = { path = "crates/test-programs" }
wasmtime-fuzzing = { path = "crates/fuzzing" }
wasmtime-runtime = { path = "crates/runtime" }
tokio = { version = "1.5.0", features = ["rt", "time", "macros", "rt-multi-thread"] }
tracing-subscriber = "0.2.16"
wast = "35.0.0"

Expand All @@ -78,8 +79,10 @@ members = [
"crates/wiggle/wasmtime",
"crates/wasi-common",
"crates/wasi-common/cap-std-sync",
"crates/wasi-common/tokio",
"examples/fib-debug/wasm",
"examples/wasi/wasm",
"examples/tokio/wasm",
"fuzz",
]

Expand Down Expand Up @@ -107,5 +110,9 @@ maintenance = { status = "actively-developed" }
name = "host_segfault"
harness = false

[[example]]
name = "tokio"
required-features = ["wasmtime-wasi/tokio"]

[profile.dev.package.backtrace]
debug = false # FIXME(#1813)
3 changes: 1 addition & 2 deletions crates/bench-api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,8 @@ use std::env;
use std::os::raw::{c_int, c_void};
use std::path::Path;
use std::slice;
use wasi_cap_std_sync::WasiCtxBuilder;
use wasmtime::{Config, Engine, Instance, Linker, Module, Store};
use wasmtime_wasi::Wasi;
use wasmtime_wasi::sync::{Wasi, WasiCtxBuilder};

pub type ExitCode = c_int;
pub const OK: ExitCode = 0;
Expand Down
7 changes: 4 additions & 3 deletions crates/c-api/src/wasi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@ use std::slice;
use std::str;
use wasmtime::{Extern, Linker, Trap};
use wasmtime_wasi::{
snapshots::preview_0::Wasi as WasiSnapshot0,
snapshots::preview_1::Wasi as WasiPreview1,
sync::{Dir, WasiCtxBuilder},
sync::{
snapshots::preview_0::Wasi as WasiSnapshot0, snapshots::preview_1::Wasi as WasiPreview1,
Dir, WasiCtxBuilder,
},
WasiCtx,
};

Expand Down
11 changes: 7 additions & 4 deletions crates/misc/run-examples/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,13 @@ fn main() -> anyhow::Result<()> {
.arg(target))?;
}
println!("======== Rust example `{}` ============", example);
run(Command::new("cargo")
.arg("run")
.arg("--example")
.arg(&example))?;
let mut cargo_cmd = Command::new("cargo");
cargo_cmd.arg("run").arg("--example").arg(&example);

if example.contains("tokio") {
cargo_cmd.arg("--features").arg("wasmtime-wasi/tokio");
}
run(&mut cargo_cmd)?;

println!("======== C/C++ example `{}` ============", example);
for extension in ["c", "cc"].iter() {
Expand Down
3 changes: 2 additions & 1 deletion crates/test-programs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,15 @@ cfg-if = "1.0"
wasi-common = { path = "../wasi-common", version = "0.26.0" }
wasi-cap-std-sync = { path = "../wasi-common/cap-std-sync", version = "0.26.0" }
wasmtime = { path = "../wasmtime", version = "0.26.0" }
wasmtime-wasi = { path = "../wasi", version = "0.26.0" }
wasmtime-wasi = { path = "../wasi", version = "0.26.0", features = ["tokio"] }
target-lexicon = "0.12.0"
pretty_env_logger = "0.4.0"
tempfile = "3.1.0"
os_pipe = "0.9"
anyhow = "1.0.19"
wat = "1.0.37"
cap-std = "0.13"
tokio = { version = "1.5.0", features = ["rt-multi-thread"] }

[features]
test_programs = []
11 changes: 9 additions & 2 deletions crates/test-programs/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ mod wasi_tests {
File::create(out_dir.join("wasi_tests.rs")).expect("error generating test source file");
build_tests("wasi-tests", &out_dir).expect("building tests");
test_directory(&mut out, "wasi-cap-std-sync", "cap_std_sync", &out_dir)
.expect("generating tests");
.expect("generating wasi-cap-std-sync tests");
test_directory(&mut out, "wasi-tokio", "tokio", &out_dir)
.expect("generating wasi-tokio tests");
}

fn build_tests(testsuite: &str, out_dir: &Path) -> io::Result<()> {
Expand Down Expand Up @@ -173,6 +175,7 @@ mod wasi_tests {
match testsuite {
"wasi-cap-std-sync" => cap_std_sync_ignore(name),
"wasi-virtfs" => virtfs_ignore(name),
"wasi-tokio" => tokio_ignore(name),
_ => panic!("unknown test suite: {}", testsuite),
}
}
Expand Down Expand Up @@ -200,6 +203,10 @@ mod wasi_tests {
.contains(&name)
}

/// Tokio should support the same things as cap_std_sync
fn tokio_ignore(name: &str) -> bool {
cap_std_sync_ignore(name)
}
/// Virtfs barely works at all and is not suitable for any purpose
fn virtfs_ignore(name: &str) -> bool {
[
Expand Down Expand Up @@ -260,7 +267,7 @@ mod wasi_tests {
/// Mark tests which require inheriting parent process stdio
fn inherit_stdio(testsuite: &str, name: &str) -> bool {
match testsuite {
"wasi-cap-std-sync" => match name {
"wasi-cap-std-sync" | "wasi-tokio" => match name {
"poll_oneoff_stdio" => true,
_ => false,
},
Expand Down
Loading