Skip to content

Commit

Permalink
Merge pull request #3805 from wasmerio/wasi-runner-args
Browse files Browse the repository at this point in the history
Wasi runner args
  • Loading branch information
Michael Bryan authored Apr 21, 2023
2 parents e5ecdda + fa69ad4 commit 0b44bf1
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 4 deletions.
62 changes: 60 additions & 2 deletions lib/wasi/src/runners/wasi_common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ impl CommonWasiOptions {
container_fs: Arc<dyn FileSystem>,
wasi: &WasiAnnotation,
) -> Result<(), anyhow::Error> {
builder.add_args(&self.args);

let fs = prepare_filesystem(&self.mapped_dirs, container_fs, |path| {
builder.add_preopen_dir(path).map_err(Error::from)
})?;
Expand Down Expand Up @@ -218,6 +216,66 @@ mod tests {

const PYTHON: &[u8] = include_bytes!("../../../c-api/examples/assets/python-0.1.0.wasmer");

/// Fixes <https://github.com/wasmerio/wasmer/issues/3789>
#[test]
fn mix_args_from_the_webc_and_user() {
let args = CommonWasiOptions {
args: vec!["extra".to_string(), "args".to_string()],
..Default::default()
};
let mut builder = WasiEnvBuilder::new("program-name");
let fs = Arc::new(virtual_fs::EmptyFileSystem::default());
let mut annotations = WasiAnnotation::new("some-atom");
annotations.main_args = Some(vec![
"hard".to_string(),
"coded".to_string(),
"args".to_string(),
]);

args.prepare_webc_env(&mut builder, fs, &annotations)
.unwrap();

assert_eq!(
builder.get_args(),
[
// the program name from
"program-name",
// from the WEBC's annotations
"hard",
"coded",
"args",
// from the user
"extra",
"args",
]
);
}

#[test]
fn mix_env_vars_from_the_webc_and_user() {
let args = CommonWasiOptions {
env: vec![("EXTRA".to_string(), "envs".to_string())]
.into_iter()
.collect(),
..Default::default()
};
let mut builder = WasiEnvBuilder::new("python");
let fs = Arc::new(virtual_fs::EmptyFileSystem::default());
let mut annotations = WasiAnnotation::new("python");
annotations.env = Some(vec!["HARD_CODED=env-vars".to_string()]);

args.prepare_webc_env(&mut builder, fs, &annotations)
.unwrap();

assert_eq!(
builder.get_env(),
[
("HARD_CODED".to_string(), b"env-vars".to_vec()),
("EXTRA".to_string(), b"envs".to_vec()),
]
);
}

#[test]
fn python_use_case() {
let temp = TempDir::new().unwrap();
Expand Down
10 changes: 8 additions & 2 deletions tests/integration/cli/tests/run_unstable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,14 @@ use wasmer_integration_tests_cli::get_wasmer_path;
const RUST_LOG: &str = "info,wasmer_wasi::runners=debug,virtual_fs::trace_fs=trace";

fn wasmer_run_unstable() -> std::process::Command {
let mut cmd = std::process::Command::new(get_wasmer_path());
cmd.env("RUST_LOG", RUST_LOG).arg("run-unstable");
let mut cmd = std::process::Command::new("cargo");
cmd.arg("run")
.arg("--quiet")
.arg("--package=wasmer-cli")
.arg("--features=singlepass")
.arg("--")
.arg("run-unstable");
cmd.env("RUST_LOG", RUST_LOG);
cmd
}

Expand Down

0 comments on commit 0b44bf1

Please sign in to comment.