diff --git a/Cargo.lock b/Cargo.lock index 9aa8863d4378..0e40dba03d7a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3269,7 +3269,6 @@ name = "wasmtime-cli" version = "0.25.0" dependencies = [ "anyhow", - "cap-std", "env_logger 0.8.3", "file-per-thread-logger", "filecheck", @@ -3285,8 +3284,6 @@ dependencies = [ "tempfile", "test-programs", "tracing-subscriber", - "wasi-cap-std-sync", - "wasi-common", "wasmparser", "wasmtime", "wasmtime-cache", @@ -3513,6 +3510,7 @@ name = "wasmtime-wasi" version = "0.25.0" dependencies = [ "anyhow", + "wasi-cap-std-sync", "wasi-common", "wasmtime", "wasmtime-wiggle", diff --git a/Cargo.toml b/Cargo.toml index 6bcd156b6005..be37d8cec7a2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -32,8 +32,6 @@ wasmtime-wast = { path = "crates/wast", version = "0.25.0" } wasmtime-wasi = { path = "crates/wasi", version = "0.25.0" } wasmtime-wasi-crypto = { path = "crates/wasi-crypto", version = "0.25.0", optional = true } wasmtime-wasi-nn = { path = "crates/wasi-nn", version = "0.25.0", optional = true } -wasi-common = { path = "crates/wasi-common", version = "0.25.0" } -wasi-cap-std-sync = { path = "crates/wasi-common/cap-std-sync", version = "0.25.0" } structopt = { version = "0.3.5", features = ["color", "suggestions"] } object = { version = "0.23.0", default-features = false, features = ["write"] } anyhow = "1.0.19" @@ -46,7 +44,6 @@ log = "0.4.8" rayon = "1.2.1" humantime = "2.0.0" wasmparser = "0.77.0" -cap-std = "0.13" [dev-dependencies] env_logger = "0.8.1" diff --git a/crates/c-api/src/wasi.rs b/crates/c-api/src/wasi.rs index 8fa15f0c20b2..441fa6fa5437 100644 --- a/crates/c-api/src/wasi.rs +++ b/crates/c-api/src/wasi.rs @@ -1,7 +1,6 @@ //! The WASI embedding API definitions for Wasmtime. use crate::{wasm_extern_t, wasm_importtype_t, wasm_store_t, wasm_trap_t}; use anyhow::Result; -use cap_std::fs::Dir; use std::cell::RefCell; use std::collections::HashMap; use std::ffi::CStr; @@ -11,11 +10,12 @@ use std::path::{Path, PathBuf}; use std::rc::Rc; use std::slice; use std::str; -use wasi_cap_std_sync::WasiCtxBuilder; -use wasi_common::WasiCtx; use wasmtime::{Extern, Linker, Trap}; use wasmtime_wasi::{ - snapshots::preview_0::Wasi as WasiSnapshot0, snapshots::preview_1::Wasi as WasiPreview1, + snapshots::preview_0::Wasi as WasiSnapshot0, + snapshots::preview_1::Wasi as WasiPreview1, + sync::{Dir, WasiCtxBuilder}, + WasiCtx, }; unsafe fn cstr_to_path<'a>(path: *const c_char) -> Option<&'a Path> { @@ -186,7 +186,7 @@ pub unsafe extern "C" fn wasi_config_preopen_dir( }; let dir = match cstr_to_path(path) { - Some(p) => match cap_std::fs::Dir::open_ambient_dir(p) { + Some(p) => match Dir::open_ambient_dir(p) { Ok(d) => d, Err(_) => return false, }, diff --git a/crates/wasi-common/cap-std-sync/src/lib.rs b/crates/wasi-common/cap-std-sync/src/lib.rs index fe38951296c8..ac8ee602e53d 100644 --- a/crates/wasi-common/cap-std-sync/src/lib.rs +++ b/crates/wasi-common/cap-std-sync/src/lib.rs @@ -14,6 +14,10 @@ //! `cap_std::fs::Dir`, and provides convenience methods for inheriting the //! parent process's stdio, args, and env. //! +//! For the convenience of consumers, `cap_std::fs::Dir` is re-exported from +//! this crate. This saves consumers tracking an additional dep on the exact +//! version of cap_std used by this crate, if they want to avoid it. +//! //! The only place we expect to run into long-term compatibility issues //! between `wasi-cap-std-sync` and the other impl crates that will come later //! is in the `Sched` abstraction. Once we can build an async scheduler based @@ -33,6 +37,7 @@ pub mod file; pub mod sched; pub mod stdio; +pub use cap_std::fs::Dir; pub use clocks::clocks_ctx; pub use sched::sched_ctx; @@ -110,13 +115,9 @@ impl WasiCtxBuilder { pub fn inherit_stdio(self) -> Self { self.inherit_stdin().inherit_stdout().inherit_stderr() } - pub fn preopened_dir( - self, - dir: cap_std::fs::Dir, - path: impl AsRef, - ) -> Result { + pub fn preopened_dir(self, dir: Dir, guest_path: impl AsRef) -> Result { let dir = Box::new(crate::dir::Dir::from_cap_std(dir)); - Ok(WasiCtxBuilder(self.0.preopened_dir(dir, path)?)) + Ok(WasiCtxBuilder(self.0.preopened_dir(dir, guest_path)?)) } pub fn build(self) -> Result { self.0.build() diff --git a/crates/wasi/Cargo.toml b/crates/wasi/Cargo.toml index 5937ec55a292..a6db19e5b458 100644 --- a/crates/wasi/Cargo.toml +++ b/crates/wasi/Cargo.toml @@ -14,7 +14,12 @@ build = "build.rs" [dependencies] wasi-common = { path = "../wasi-common", version = "0.25.0" } +wasi-cap-std-sync = { path = "../wasi-common/cap-std-sync", version = "0.25.0", optional = true } wiggle = { path = "../wiggle", default-features = false, version = "0.25.0" } wasmtime-wiggle = { path = "../wiggle/wasmtime", default-features = false, version = "0.25.0" } wasmtime = { path = "../wasmtime", default-features = false, version = "0.25.0" } anyhow = "1.0" + +[features] +default = ["sync"] +sync = ["wasi-cap-std-sync"] diff --git a/crates/wasi/src/lib.rs b/crates/wasi/src/lib.rs index 1c3ad448ad58..2b71d7ab371b 100644 --- a/crates/wasi/src/lib.rs +++ b/crates/wasi/src/lib.rs @@ -12,6 +12,14 @@ use std::rc::Rc; pub use wasi_common::{Error, WasiCtx, WasiCtxBuilder, WasiDir, WasiFile}; use wasmtime::{Config, Linker, Store}; +/// Re-export the commonly used wasi-cap-std-sync crate here. This saves +/// consumers of this library from having to keep additional dependencies +/// in sync. +#[cfg(feature = "sync")] +pub mod sync { + pub use wasi_cap_std_sync::*; +} + /// An instantiated instance of all available wasi exports. Presently includes /// both the "preview1" snapshot and the "unstable" (preview0) snapshot. pub struct Wasi { diff --git a/examples/linking.rs b/examples/linking.rs index 11f4022bcd8e..b4cee53a4a55 100644 --- a/examples/linking.rs +++ b/examples/linking.rs @@ -3,9 +3,8 @@ // You can execute this example with `cargo run --example linking` use anyhow::Result; -use wasi_cap_std_sync::WasiCtxBuilder; use wasmtime::*; -use wasmtime_wasi::Wasi; +use wasmtime_wasi::{sync::WasiCtxBuilder, Wasi}; fn main() -> Result<()> { let engine = Engine::default(); diff --git a/examples/wasi/main.rs b/examples/wasi/main.rs index f1487171f71f..f808be3eca2b 100644 --- a/examples/wasi/main.rs +++ b/examples/wasi/main.rs @@ -4,9 +4,8 @@ // You can execute this example with `cargo run --example wasi` use anyhow::Result; -use wasi_cap_std_sync::WasiCtxBuilder; use wasmtime::*; -use wasmtime_wasi::Wasi; +use wasmtime_wasi::{sync::WasiCtxBuilder, Wasi}; fn main() -> Result<()> { tracing_subscriber::FmtSubscriber::builder() diff --git a/src/commands/run.rs b/src/commands/run.rs index 89f9ec120f77..f8b701014689 100644 --- a/src/commands/run.rs +++ b/src/commands/run.rs @@ -2,7 +2,6 @@ use crate::{init_file_per_thread_logger, CommonOptions}; use anyhow::{bail, Context as _, Result}; -use cap_std::fs::Dir; use std::thread; use std::time::Duration; use std::{ @@ -11,9 +10,11 @@ use std::{ process, }; use structopt::{clap::AppSettings, StructOpt}; -use wasi_cap_std_sync::WasiCtxBuilder; use wasmtime::{Engine, Func, Linker, Module, Store, Trap, Val, ValType}; -use wasmtime_wasi::Wasi; +use wasmtime_wasi::{ + sync::{Dir, WasiCtxBuilder}, + Wasi, +}; #[cfg(feature = "wasi-nn")] use wasmtime_wasi_nn::{WasiNn, WasiNnCtx}; diff --git a/tests/all/host_funcs.rs b/tests/all/host_funcs.rs index 26d43299417d..360e2526adee 100644 --- a/tests/all/host_funcs.rs +++ b/tests/all/host_funcs.rs @@ -1,8 +1,7 @@ use anyhow::Result; use std::sync::atomic::{AtomicUsize, Ordering::SeqCst}; -use wasi_cap_std_sync::WasiCtxBuilder; use wasmtime::*; -use wasmtime_wasi::Wasi; +use wasmtime_wasi::{sync::WasiCtxBuilder, Wasi}; #[test] fn async_required() { diff --git a/tests/all/traps.rs b/tests/all/traps.rs index b83ac38daa32..a4686e907378 100644 --- a/tests/all/traps.rs +++ b/tests/all/traps.rs @@ -512,7 +512,7 @@ fn parse_dwarf_info() -> Result<()> { let mut linker = Linker::new(&store); wasmtime_wasi::Wasi::new( &store, - wasi_cap_std_sync::WasiCtxBuilder::new() + wasmtime_wasi::sync::WasiCtxBuilder::new() .inherit_stdio() .build()?, )