Skip to content

Commit

Permalink
Merge branch 'feature/preview2' of github.com:geekbeast/wasmtime into…
Browse files Browse the repository at this point in the history
… feature/preview2

* 'feature/preview2' of github.com:geekbeast/wasmtime:
  Change preview2 builder methods to use `&mut self` (bytecodealliance#6770)
  Add a bindgen test that exercises using error types from a different interface (bytecodealliance#6802)
  Resolve trappable error types with fully qualified package paths (bytecodealliance#6795)
  Update the dev-dependency for wit-bindgen to 0.9.0 (bytecodealliance#6800)
  Fix incorrect sample code in documentation (bytecodealliance#6796) (bytecodealliance#6797)
  Update preview1 to trap on misaligned pointers (bytecodealliance#6776)
  Fix posix-signals-on-macos on aarch64-apple-darwin (bytecodealliance#6793)
  consistient WASI preview1 rights reporting (bytecodealliance#6784)
  Wasmtime: Introduce `{Module,Component}::resources_required` (bytecodealliance#6789)
  • Loading branch information
Matthew Tamayo committed Aug 6, 2023
2 parents 1eac1be + 777eebf commit 79d070e
Show file tree
Hide file tree
Showing 36 changed files with 1,254 additions and 557 deletions.
104 changes: 40 additions & 64 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ io-extras = "0.18.0"
rustix = "0.38.4"

# wit-bindgen:
wit-bindgen = { version = "0.7.0", default-features = false }
wit-bindgen = { version = "0.9.0", default-features = false }

# wasm-tools family:
wasmparser = "0.110.0"
Expand Down
45 changes: 24 additions & 21 deletions benches/wasi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,26 +61,29 @@ fn instantiate(wat: &[u8]) -> (Store<WasiCtx>, TypedFunc<u64, u64>) {

/// Build a WASI context with some actual data to retrieve.
fn wasi_context() -> WasiCtx {
let wasi = WasiCtxBuilder::new();
wasi.envs(&[
("a".to_string(), "b".to_string()),
("b".to_string(), "c".to_string()),
("c".to_string(), "d".to_string()),
])
.unwrap()
.args(&[
"exe".to_string(),
"--flag1".to_string(),
"--flag2".to_string(),
"--flag3".to_string(),
"--flag4".to_string(),
])
.unwrap()
.preopened_dir(
wasmtime_wasi::Dir::open_ambient_dir("benches/wasi", wasmtime_wasi::ambient_authority())
WasiCtxBuilder::new()
.envs(&[
("a".to_string(), "b".to_string()),
("b".to_string(), "c".to_string()),
("c".to_string(), "d".to_string()),
])
.unwrap()
.args(&[
"exe".to_string(),
"--flag1".to_string(),
"--flag2".to_string(),
"--flag3".to_string(),
"--flag4".to_string(),
])
.unwrap()
.preopened_dir(
wasmtime_wasi::Dir::open_ambient_dir(
"benches/wasi",
wasmtime_wasi::ambient_authority(),
)
.unwrap(),
"/",
)
.unwrap()
.build()
"/",
)
.unwrap()
.build()
}
44 changes: 25 additions & 19 deletions crates/c-api/src/wasi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,17 +70,17 @@ impl wasi_config_t {
pub fn into_wasi_ctx(self) -> Result<WasiCtx> {
let mut builder = WasiCtxBuilder::new();
if self.inherit_args {
builder = builder.inherit_args()?;
builder.inherit_args()?;
} else if !self.args.is_empty() {
let args = self
.args
.into_iter()
.map(|bytes| Ok(String::from_utf8(bytes)?))
.collect::<Result<Vec<String>>>()?;
builder = builder.args(&args)?;
builder.args(&args)?;
}
if self.inherit_env {
builder = builder.inherit_env()?;
builder.inherit_env()?;
} else if !self.env.is_empty() {
let env = self
.env
Expand All @@ -91,44 +91,50 @@ impl wasi_config_t {
Ok((k, v))
})
.collect::<Result<Vec<(String, String)>>>()?;
builder = builder.envs(&env)?;
builder.envs(&env)?;
}
builder = match self.stdin {
WasiConfigReadPipe::None => builder,
WasiConfigReadPipe::Inherit => builder.inherit_stdin(),
match self.stdin {
WasiConfigReadPipe::None => {}
WasiConfigReadPipe::Inherit => {
builder.inherit_stdin();
}
WasiConfigReadPipe::File(file) => {
let file = cap_std::fs::File::from_std(file);
let file = wasi_cap_std_sync::file::File::from_cap_std(file);
builder.stdin(Box::new(file))
builder.stdin(Box::new(file));
}
WasiConfigReadPipe::Bytes(binary) => {
let binary = ReadPipe::from(binary);
builder.stdin(Box::new(binary))
builder.stdin(Box::new(binary));
}
};
builder = match self.stdout {
WasiConfigWritePipe::None => builder,
WasiConfigWritePipe::Inherit => builder.inherit_stdout(),
match self.stdout {
WasiConfigWritePipe::None => {}
WasiConfigWritePipe::Inherit => {
builder.inherit_stdout();
}
WasiConfigWritePipe::File(file) => {
let file = cap_std::fs::File::from_std(file);
let file = wasi_cap_std_sync::file::File::from_cap_std(file);
builder.stdout(Box::new(file))
builder.stdout(Box::new(file));
}
};
builder = match self.stderr {
WasiConfigWritePipe::None => builder,
WasiConfigWritePipe::Inherit => builder.inherit_stderr(),
match self.stderr {
WasiConfigWritePipe::None => {}
WasiConfigWritePipe::Inherit => {
builder.inherit_stderr();
}
WasiConfigWritePipe::File(file) => {
let file = cap_std::fs::File::from_std(file);
let file = wasi_cap_std_sync::file::File::from_cap_std(file);
builder.stderr(Box::new(file))
builder.stderr(Box::new(file));
}
};
for (dir, path) in self.preopen_dirs {
builder = builder.preopened_dir(dir, path)?;
builder.preopened_dir(dir, path)?;
}
for (fd_num, listener) in self.preopen_sockets {
builder = builder.preopened_socket(fd_num, listener)?;
builder.preopened_socket(fd_num, listener)?;
}
Ok(builder.build())
}
Expand Down
Loading

0 comments on commit 79d070e

Please sign in to comment.