Merge pull request #2776 from bytecodealliance/pch/wasmtime_wasi_usability
`wasmtime-wasi` usability: re-exports of common siblings
This commit is contained in:
4
Cargo.lock
generated
4
Cargo.lock
generated
@@ -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",
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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,
|
||||
},
|
||||
|
||||
@@ -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<Path>,
|
||||
) -> Result<Self, Error> {
|
||||
pub fn preopened_dir(self, dir: Dir, guest_path: impl AsRef<Path>) -> Result<Self, Error> {
|
||||
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<WasiCtx, Error> {
|
||||
self.0.build()
|
||||
|
||||
@@ -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"]
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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};
|
||||
|
||||
@@ -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() {
|
||||
|
||||
@@ -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()?,
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user