only wasi_cap_std_sync and wasi_tokio need to define WasiCtxBuilders (#2917)
* wasmtime-wasi: re-exporting this WasiCtxBuilder was shadowing the right one wasi-common's WasiCtxBuilder is really only useful wasi_cap_std_sync and wasi_tokio to implement their own Builder on top of. This re-export of wasi-common's is 1. not useful and 2. shadow's the re-export of the right one in sync::*. * wasi-common: eliminate WasiCtxBuilder, make the builder methods on WasiCtx instead * delete wasi-common::WasiCtxBuilder altogether just put those methods directly on &mut WasiCtx. As a bonus, the sync and tokio WasiCtxBuilder::build functions are no longer fallible! * bench fixes * more test fixes
This commit is contained in:
@@ -47,61 +47,60 @@ use std::path::Path;
|
||||
use std::rc::Rc;
|
||||
use wasi_common::{table::Table, Error, WasiCtx, WasiFile};
|
||||
|
||||
pub struct WasiCtxBuilder(wasi_common::WasiCtxBuilder);
|
||||
pub struct WasiCtxBuilder(WasiCtx);
|
||||
|
||||
impl WasiCtxBuilder {
|
||||
pub fn new() -> Self {
|
||||
WasiCtxBuilder(WasiCtx::builder(
|
||||
WasiCtxBuilder(WasiCtx::new(
|
||||
random_ctx(),
|
||||
clocks_ctx(),
|
||||
sched_ctx(),
|
||||
Rc::new(RefCell::new(Table::new())),
|
||||
))
|
||||
}
|
||||
pub fn env(self, var: &str, value: &str) -> Result<Self, wasi_common::StringArrayError> {
|
||||
let s = self.0.env(var, value)?;
|
||||
Ok(WasiCtxBuilder(s))
|
||||
pub fn env(mut self, var: &str, value: &str) -> Result<Self, wasi_common::StringArrayError> {
|
||||
self.0.push_env(var, value)?;
|
||||
Ok(self)
|
||||
}
|
||||
pub fn envs(self, env: &[(String, String)]) -> Result<Self, wasi_common::StringArrayError> {
|
||||
let mut s = self;
|
||||
pub fn envs(mut self, env: &[(String, String)]) -> Result<Self, wasi_common::StringArrayError> {
|
||||
for (k, v) in env {
|
||||
s = s.env(k, v)?;
|
||||
self.0.push_env(k, v)?;
|
||||
}
|
||||
Ok(s)
|
||||
Ok(self)
|
||||
}
|
||||
pub fn inherit_env(self) -> Result<Self, wasi_common::StringArrayError> {
|
||||
let mut s = self.0;
|
||||
pub fn inherit_env(mut self) -> Result<Self, wasi_common::StringArrayError> {
|
||||
for (key, value) in std::env::vars() {
|
||||
s = s.env(&key, &value)?;
|
||||
self.0.push_env(&key, &value)?;
|
||||
}
|
||||
Ok(WasiCtxBuilder(s))
|
||||
Ok(self)
|
||||
}
|
||||
pub fn arg(self, arg: &str) -> Result<Self, wasi_common::StringArrayError> {
|
||||
let s = self.0.arg(arg)?;
|
||||
Ok(WasiCtxBuilder(s))
|
||||
pub fn arg(mut self, arg: &str) -> Result<Self, wasi_common::StringArrayError> {
|
||||
self.0.push_arg(arg)?;
|
||||
Ok(self)
|
||||
}
|
||||
pub fn args(self, arg: &[String]) -> Result<Self, wasi_common::StringArrayError> {
|
||||
let mut s = self;
|
||||
pub fn args(mut self, arg: &[String]) -> Result<Self, wasi_common::StringArrayError> {
|
||||
for a in arg {
|
||||
s = s.arg(&a)?;
|
||||
self.0.push_arg(&a)?;
|
||||
}
|
||||
Ok(s)
|
||||
Ok(self)
|
||||
}
|
||||
pub fn inherit_args(self) -> Result<Self, wasi_common::StringArrayError> {
|
||||
let mut s = self.0;
|
||||
pub fn inherit_args(mut self) -> Result<Self, wasi_common::StringArrayError> {
|
||||
for arg in std::env::args() {
|
||||
s = s.arg(&arg)?;
|
||||
self.0.push_arg(&arg)?;
|
||||
}
|
||||
Ok(WasiCtxBuilder(s))
|
||||
Ok(self)
|
||||
}
|
||||
pub fn stdin(self, f: Box<dyn WasiFile>) -> Self {
|
||||
WasiCtxBuilder(self.0.stdin(f))
|
||||
pub fn stdin(mut self, f: Box<dyn WasiFile>) -> Self {
|
||||
self.0.set_stdin(f);
|
||||
self
|
||||
}
|
||||
pub fn stdout(self, f: Box<dyn WasiFile>) -> Self {
|
||||
WasiCtxBuilder(self.0.stdout(f))
|
||||
pub fn stdout(mut self, f: Box<dyn WasiFile>) -> Self {
|
||||
self.0.set_stdout(f);
|
||||
self
|
||||
}
|
||||
pub fn stderr(self, f: Box<dyn WasiFile>) -> Self {
|
||||
WasiCtxBuilder(self.0.stderr(f))
|
||||
pub fn stderr(mut self, f: Box<dyn WasiFile>) -> Self {
|
||||
self.0.set_stderr(f);
|
||||
self
|
||||
}
|
||||
pub fn inherit_stdin(self) -> Self {
|
||||
self.stdin(Box::new(crate::stdio::stdin()))
|
||||
@@ -115,12 +114,13 @@ impl WasiCtxBuilder {
|
||||
pub fn inherit_stdio(self) -> Self {
|
||||
self.inherit_stdin().inherit_stdout().inherit_stderr()
|
||||
}
|
||||
pub fn preopened_dir(self, dir: Dir, guest_path: impl AsRef<Path>) -> Result<Self, Error> {
|
||||
pub fn preopened_dir(mut 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, guest_path)?))
|
||||
self.0.push_preopened_dir(dir, guest_path)?;
|
||||
Ok(self)
|
||||
}
|
||||
pub fn build(self) -> Result<WasiCtx, Error> {
|
||||
self.0.build()
|
||||
pub fn build(self) -> WasiCtx {
|
||||
self.0
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user