@ -8,68 +8,67 @@ use std::future::Future;
use std ::path ::Path ;
use std ::path ::Path ;
use std ::rc ::Rc ;
use std ::rc ::Rc ;
pub use wasi_cap_std_sync ::{ clocks_ctx , random_ctx } ;
pub use wasi_cap_std_sync ::{ clocks_ctx , random_ctx } ;
use wasi_common ::{ Error , Table , WasiCtx } ;
use wasi_common ::{ Error , Table , WasiCtx , WasiFile } ;
pub use dir ::Dir ;
pub use dir ::Dir ;
pub use file ::File ;
pub use file ::File ;
use crate ::sched ::sched_ctx ;
use crate ::sched ::sched_ctx ;
pub struct WasiCtxBuilder ( wasi_common ::WasiCtxBuilder ) ;
pub struct WasiCtxBuilder ( WasiCtx ) ;
impl WasiCtxBuilder {
impl WasiCtxBuilder {
pub fn new ( ) -> Self {
pub fn new ( ) -> Self {
WasiCtxBuilder ( WasiCtx ::builder (
WasiCtxBuilder ( WasiCtx ::new (
random_ctx ( ) ,
random_ctx ( ) ,
clocks_ctx ( ) ,
clocks_ctx ( ) ,
sched_ctx ( ) ,
sched_ctx ( ) ,
Rc ::new ( RefCell ::new ( Table ::new ( ) ) ) ,
Rc ::new ( RefCell ::new ( Table ::new ( ) ) ) ,
) )
) )
}
}
pub fn env ( self , var : & str , value : & str ) -> Result < Self , wasi_common ::StringArrayError > {
pub fn env ( mut self , var : & str , value : & str ) -> Result < Self , wasi_common ::StringArrayError > {
let s = self . 0. env ( var , value ) ? ;
self . 0. push_ env( var , value ) ? ;
Ok ( WasiCtxBuilder ( s ) )
Ok ( self )
}
}
pub fn envs ( self , env : & [ ( String , String ) ] ) -> Result < Self , wasi_common ::StringArrayError > {
pub fn envs ( mut self , env : & [ ( String , String ) ] ) -> Result < Self , wasi_common ::StringArrayError > {
let mut s = self ;
for ( k , v ) in env {
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 > {
pub fn inherit_env ( mut self ) -> Result < Self , wasi_common ::StringArrayError > {
let mut s = self . 0 ;
for ( key , value ) in std ::env ::vars ( ) {
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 > {
pub fn arg ( mut self , arg : & str ) -> Result < Self , wasi_common ::StringArrayError > {
let s = self . 0. arg ( arg ) ? ;
self . 0. push_ arg( arg ) ? ;
Ok ( WasiCtxBuilder ( s ) )
Ok ( self )
}
}
pub fn args ( self , arg : & [ String ] ) -> Result < Self , wasi_common ::StringArrayError > {
pub fn args ( mut self , arg : & [ String ] ) -> Result < Self , wasi_common ::StringArrayError > {
let mut s = self ;
for a in arg {
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 > {
pub fn inherit_args ( mut self ) -> Result < Self , wasi_common ::StringArrayError > {
let mut s = self . 0 ;
for arg in std ::env ::args ( ) {
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 wasi_common ::WasiFile > ) -> Self {
pub fn stdin ( mut self , f : Box < dyn WasiFile > ) -> Self {
WasiCtxBuilder ( self . 0. stdin ( f ) )
self . 0. set_stdin ( f ) ;
self
}
}
pub fn stdout ( self , f : Box < dyn wasi_common ::WasiFile > ) -> Self {
pub fn stdout ( mut self , f : Box < dyn WasiFile > ) -> Self {
WasiCtxBuilder ( self . 0. stdout ( f ) )
self . 0. set_stdout ( f ) ;
self
}
}
pub fn stderr ( self , f : Box < dyn wasi_common ::WasiFile > ) -> Self {
pub fn stderr ( mut self , f : Box < dyn WasiFile > ) -> Self {
WasiCtxBuilder ( self . 0. stderr ( f ) )
self . 0. set_stderr ( f ) ;
self
}
}
pub fn inherit_stdin ( self ) -> Self {
pub fn inherit_stdin ( self ) -> Self {
self . stdin ( Box ::new ( crate ::stdio ::stdin ( ) ) )
self . stdin ( Box ::new ( crate ::stdio ::stdin ( ) ) )
@ -84,15 +83,16 @@ impl WasiCtxBuilder {
self . inherit_stdin ( ) . inherit_stdout ( ) . inherit_stderr ( )
self . inherit_stdin ( ) . inherit_stdout ( ) . inherit_stderr ( )
}
}
pub fn preopened_dir (
pub fn preopened_dir (
self ,
mut self ,
dir : cap_std ::fs ::Dir ,
dir : cap_std ::fs ::Dir ,
guest_path : impl AsRef < Path > ,
guest_path : impl AsRef < Path > ,
) -> Result < Self , wasi_common ::Error > {
) -> Result < Self , Error > {
let dir = Box ::new ( Dir ::from_cap_std ( dir ) ) ;
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 , wasi_common ::Error > {
pub fn build ( self ) -> WasiCtx {
self . 0. build ( )
self . 0
}
}
}
}