From 7303793fa08856b7fc00c4088c47a22a45f7cc87 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9o=20Gaspard?= Date: Wed, 13 Jan 2021 04:09:32 +0100 Subject: [PATCH 1/6] also expose WasiCtxBuilder --- crates/wasi-c2/src/lib.rs | 2 +- crates/wasi-c2/wasmtime/src/lib.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/wasi-c2/src/lib.rs b/crates/wasi-c2/src/lib.rs index 71fb8a3122..a654335324 100644 --- a/crates/wasi-c2/src/lib.rs +++ b/crates/wasi-c2/src/lib.rs @@ -13,7 +13,7 @@ mod string_array; pub mod table; pub mod virt; -pub use ctx::WasiCtx; +pub use ctx::{WasiCtx, WasiCtxBuilder}; pub use dir::{DirCaps, WasiDir}; pub use error::Error; pub use file::{FileCaps, WasiFile}; diff --git a/crates/wasi-c2/wasmtime/src/lib.rs b/crates/wasi-c2/wasmtime/src/lib.rs index 02fdd558ec..b3b02cae1a 100644 --- a/crates/wasi-c2/wasmtime/src/lib.rs +++ b/crates/wasi-c2/wasmtime/src/lib.rs @@ -1,4 +1,4 @@ -pub use wasi_c2::WasiCtx; +pub use wasi_c2::{WasiCtx, WasiCtxBuilder}; // Defines a `struct Wasi` with member fields and appropriate APIs for dealing // with all the various WASI exports. From f3156114c4fd126f0ca35e77bc81991056085885 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9o=20Gaspard?= Date: Wed, 13 Jan 2021 04:24:02 +0100 Subject: [PATCH 2/6] =?UTF-8?q?reserve=20keys=200,=201=20and=202=C2=A0for?= =?UTF-8?q?=20stdio?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- crates/wasi-c2/src/table.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/wasi-c2/src/table.rs b/crates/wasi-c2/src/table.rs index 788f8cebfd..9cfbb3691b 100644 --- a/crates/wasi-c2/src/table.rs +++ b/crates/wasi-c2/src/table.rs @@ -12,7 +12,7 @@ impl Table { pub fn new() -> Self { Table { map: HashMap::new(), - next_key: 0, + next_key: 3, // 0, 1 and 2 are reserved for stdio } } From 2e035be60a2f6067cc7b170e1e269f483bb5ec7f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9o=20Gaspard?= Date: Wed, 13 Jan 2021 04:51:00 +0100 Subject: [PATCH 3/6] make WasiCtxBuilder be an actual builder, allowing to call .build() at the end of a call chain --- crates/wasi-c2/src/ctx.rs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/crates/wasi-c2/src/ctx.rs b/crates/wasi-c2/src/ctx.rs index b9e74e3c18..5f60ccca9c 100644 --- a/crates/wasi-c2/src/ctx.rs +++ b/crates/wasi-c2/src/ctx.rs @@ -66,12 +66,12 @@ impl WasiCtxBuilder { Ok(self.0) } - pub fn arg(&mut self, arg: &str) -> Result<&mut Self, StringArrayError> { + pub fn arg(mut self, arg: &str) -> Result { self.0.args.push(arg.to_owned())?; Ok(self) } - pub fn stdin(&mut self, f: Box) -> &mut Self { + pub fn stdin(mut self, f: Box) -> Self { self.0.insert_file( 0, f, @@ -80,7 +80,7 @@ impl WasiCtxBuilder { self } - pub fn stdout(&mut self, f: Box) -> &mut Self { + pub fn stdout(mut self, f: Box) -> Self { self.0.insert_file( 1, f, @@ -89,7 +89,7 @@ impl WasiCtxBuilder { self } - pub fn stderr(&mut self, f: Box) -> &mut Self { + pub fn stderr(mut self, f: Box) -> Self { self.0.insert_file( 2, f, @@ -98,17 +98,17 @@ impl WasiCtxBuilder { self } - pub fn inherit_stdio(&mut self) -> &mut Self { + pub fn inherit_stdio(self) -> Self { self.stdin(Box::new(crate::stdio::stdin())) .stdout(Box::new(crate::stdio::stdout())) .stderr(Box::new(crate::stdio::stderr())) } pub fn preopened_dir( - &mut self, + mut self, dir: Box, path: impl AsRef, - ) -> Result<&mut Self, Error> { + ) -> Result { let caps = DirCaps::all(); let file_caps = FileCaps::all(); self.0.table().push(Box::new(DirEntry::new( @@ -120,7 +120,7 @@ impl WasiCtxBuilder { Ok(self) } - pub fn random(&mut self, random: Box) -> &mut Self { + pub fn random(mut self, random: Box) -> Self { self.0.random.replace(random); self } From 5d8521632976f43414d1cb0d4cc1eac9589b756e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9o=20Gaspard?= Date: Wed, 13 Jan 2021 05:05:37 +0100 Subject: [PATCH 4/6] also reexport WasiDir from wasmtime_wasi --- crates/wasi-c2/wasmtime/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/wasi-c2/wasmtime/src/lib.rs b/crates/wasi-c2/wasmtime/src/lib.rs index b3b02cae1a..527f6502ca 100644 --- a/crates/wasi-c2/wasmtime/src/lib.rs +++ b/crates/wasi-c2/wasmtime/src/lib.rs @@ -1,4 +1,4 @@ -pub use wasi_c2::{WasiCtx, WasiCtxBuilder}; +pub use wasi_c2::{WasiCtx, WasiCtxBuilder, WasiDir}; // Defines a `struct Wasi` with member fields and appropriate APIs for dealing // with all the various WASI exports. From 20bb4b211e7d5d65f03f25ff6e84f42ad4896c1d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9o=20Gaspard?= Date: Wed, 13 Jan 2021 05:10:28 +0100 Subject: [PATCH 5/6] Also reexport Error from wasmtime_wasi --- crates/wasi-c2/wasmtime/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/wasi-c2/wasmtime/src/lib.rs b/crates/wasi-c2/wasmtime/src/lib.rs index 527f6502ca..915205db41 100644 --- a/crates/wasi-c2/wasmtime/src/lib.rs +++ b/crates/wasi-c2/wasmtime/src/lib.rs @@ -1,4 +1,4 @@ -pub use wasi_c2::{WasiCtx, WasiCtxBuilder, WasiDir}; +pub use wasi_c2::{Error, WasiCtx, WasiCtxBuilder, WasiDir}; // Defines a `struct Wasi` with member fields and appropriate APIs for dealing // with all the various WASI exports. From 932378eb7b499e0b23ad8a8e762cc8e905100d8a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9o=20Gaspard?= Date: Wed, 13 Jan 2021 05:18:36 +0100 Subject: [PATCH 6/6] reexport all the things required to implement WasiDir --- crates/wasi-c2/src/lib.rs | 5 +++-- crates/wasi-c2/wasmtime/src/lib.rs | 5 ++++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/crates/wasi-c2/src/lib.rs b/crates/wasi-c2/src/lib.rs index a654335324..7aa79d3d9e 100644 --- a/crates/wasi-c2/src/lib.rs +++ b/crates/wasi-c2/src/lib.rs @@ -13,8 +13,9 @@ mod string_array; pub mod table; pub mod virt; +pub use cap_fs_ext::SystemTimeSpec; pub use ctx::{WasiCtx, WasiCtxBuilder}; -pub use dir::{DirCaps, WasiDir}; +pub use dir::{DirCaps, ReaddirCursor, ReaddirEntity, WasiDir}; pub use error::Error; -pub use file::{FileCaps, WasiFile}; +pub use file::{FdFlags, FileCaps, Filestat, OFlags, WasiFile}; pub use string_array::StringArrayError; diff --git a/crates/wasi-c2/wasmtime/src/lib.rs b/crates/wasi-c2/wasmtime/src/lib.rs index 915205db41..d9df5e48ae 100644 --- a/crates/wasi-c2/wasmtime/src/lib.rs +++ b/crates/wasi-c2/wasmtime/src/lib.rs @@ -1,4 +1,7 @@ -pub use wasi_c2::{Error, WasiCtx, WasiCtxBuilder, WasiDir}; +pub use wasi_c2::{ + Error, FdFlags, FileCaps, Filestat, OFlags, ReaddirCursor, ReaddirEntity, SystemTimeSpec, + WasiCtx, WasiCtxBuilder, WasiDir, WasiFile, +}; // Defines a `struct Wasi` with member fields and appropriate APIs for dealing // with all the various WASI exports.