Skip to content

Commit

Permalink
Merge pull request #5057 from wasmerio/add-cwd-to-manifest
Browse files Browse the repository at this point in the history
Add `cwd` to the manifest as a command annotation
  • Loading branch information
syrusakbary committed Sep 4, 2024
2 parents c54d30e + 3fbffbb commit 14a8c42
Show file tree
Hide file tree
Showing 7 changed files with 75 additions and 22 deletions.
28 changes: 7 additions & 21 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 @@ -92,7 +92,7 @@ wasmer-config = { path = "./lib/config" }
wasmer-wasix = { path = "./lib/wasix" }

# Wasmer-owned crates
webc = { version = "6.0.0-rc1", default-features = false, features = ["package"] }
webc = { version = "6.0.0-rc3", default-features = false, features = ["package"] }
edge-schema = { version = "=0.1.0" }
shared-buffer = "0.1.4"

Expand Down
4 changes: 4 additions & 0 deletions lib/wasix/src/runners/wasi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,10 @@ impl crate::runners::Runner for WasiRunner {
}
}

if let Some(cwd) = &wasi.cwd {
env.set_current_dir(cwd);
}

let env = env.build()?;
let store = runtime.new_store();

Expand Down
26 changes: 26 additions & 0 deletions tests/integration/cli/tests/packages/list-cwd/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#include <stdio.h>
#include <dirent.h>
#include <unistd.h>
#include <string.h>

int main(int argc, char *argv[])
{
DIR *dir;
struct dirent *entry;

dir = opendir("./");
if (dir == NULL)
{
perror("opendir");
return 1;
}

while ((entry = readdir(dir)) != NULL)
{
printf("%s\n", entry->d_name);
}

closedir(dir);

return 0;
}
Binary file not shown.
14 changes: 14 additions & 0 deletions tests/integration/cli/tests/packages/list-cwd/wasmer.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[[module]]
name = "main"
source = "main.wasm"

[fs]
"/data" = "."

[[command]]
name = "run"
module = "main"
runner = "wasi"

[command.annotations.wasi]
cwd = "/data"
23 changes: 23 additions & 0 deletions tests/integration/cli/tests/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,29 @@ static CACHE_RUST_LOG: Lazy<String> = Lazy::new(|| {
.join(",")
});

#[test]
fn list_cwd() {
let package = packages().join("list-cwd");

let output = Command::new(get_wasmer_path())
.arg("run")
.arg(package)
.output()
.unwrap();

let stdout = output.stdout;

let expected = ".
..
main.c
main.wasm
wasmer.toml
"
.to_owned();

assert_eq!(expected, String::from_utf8(stdout).unwrap());
}

#[test]
fn nested_mounted_paths() {
let package = packages().join("nested-mounted-paths");
Expand Down

0 comments on commit 14a8c42

Please sign in to comment.