Skip to content

Commit

Permalink
Merge pull request #2832 from bytecodealliance/pch/wiggle_sync_shimming
Browse files Browse the repository at this point in the history
wasi-common support for tokio, & wiggle support for async methods containing sync code
  • Loading branch information
Pat Hickey authored May 8, 2021
2 parents ec5d801 + bae1a56 commit f60ae73
Show file tree
Hide file tree
Showing 56 changed files with 2,876 additions and 849 deletions.
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

0 comments on commit f60ae73

Please sign in to comment.