add wasmtime adapter and stdio wrappers

the stdio wrappers will not work on windows, but thats a whole other can
of worms anyway
This commit is contained in:
Pat Hickey
2020-12-11 15:00:19 -08:00
parent 73058658f4
commit 22db10e643
8 changed files with 238 additions and 0 deletions

View File

@@ -1,6 +1,7 @@
use crate::dir::{DirCaps, DirEntry, WasiDir};
use crate::file::{FileCaps, FileEntry, WasiFile};
use crate::table::Table;
use crate::Error;
use std::cell::{RefCell, RefMut};
use std::path::PathBuf;
use std::rc::Rc;
@@ -10,6 +11,10 @@ pub struct WasiCtx {
}
impl WasiCtx {
pub fn builder() -> WasiCtxBuilder {
WasiCtxBuilder(WasiCtx::new())
}
pub fn new() -> Self {
WasiCtx {
table: Rc::new(RefCell::new(Table::new())),
@@ -52,3 +57,36 @@ impl WasiCtx {
self.table.borrow_mut()
}
}
pub struct WasiCtxBuilder(WasiCtx);
impl WasiCtxBuilder {
pub fn build(self) -> Result<WasiCtx, Error> {
Ok(self.0)
}
pub fn arg(&mut self, _arg: &str) -> &mut Self {
// Intentionally left blank. We do not handle arguments yet.
self
}
pub fn inherit_stdio(&mut self) -> &mut Self {
self.0.insert_file(
0,
Box::new(crate::stdio::stdin()),
FileCaps::READ,
FileCaps::READ,
);
self.0.insert_file(
1,
Box::new(crate::stdio::stdout()),
FileCaps::WRITE,
FileCaps::WRITE,
);
self.0.insert_file(
2,
Box::new(crate::stdio::stderr()),
FileCaps::WRITE,
FileCaps::WRITE,
);
self
}
}