Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add cwd to the manifest as a command annotation #5057

Merged
merged 2 commits into from
Sep 4, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions lib/wasix/src/runners/wasi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,10 @@ impl crate::runners::Runner for WasiRunner {
}
}

if let Some(cwd) = cmd.metadata().annotation::<String>("cwd")? {
maminrayej marked this conversation as resolved.
Show resolved Hide resolved
maminrayej marked this conversation as resolved.
Show resolved Hide resolved
env.set_current_dir(PathBuf::from(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]
cwd = "/data"
maminrayej marked this conversation as resolved.
Show resolved Hide resolved
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
Loading