Skip to content

Commit 698952b

Browse files
authored
Add support for :: in --dir to old CLI (#7416)
In Wasmtime 13 and prior the `--dir` argument was unconditionally used to open a host dir as the same name and in the guest. In Wasmtime 14+ though this argument is being repurposed with an optional trailing `::GUEST` to configure the guest directory. This means that `--dir`-with-remapping behavior is actually unusable without the environment variable configuration from #7385 due to it parsing differently in the old and the new. This commit updates the situation by adding `::`-parsing to the old CLI meaning that both the old and the new parse this the same way. This will break any scripts that open host directories with two colons in their path, but that seems niche enough we can handle that later.
1 parent a841785 commit 698952b

2 files changed

Lines changed: 17 additions & 1 deletion

File tree

src/old_cli.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -748,7 +748,10 @@ impl RunCommand {
748748
let mut dirs = Vec::new();
749749

750750
for host in old_dirs {
751-
dirs.push((host.clone(), host));
751+
let mut parts = host.splitn(2, "::");
752+
let host = parts.next().unwrap();
753+
let guest = parts.next().unwrap_or(host);
754+
dirs.push((host.to_string(), guest.to_string()));
752755
}
753756

754757
if preview2 {

tests/all/cli_tests.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1160,6 +1160,19 @@ warning: this CLI invocation of Wasmtime is going to break in the future -- for
11601160
);
11611161
assert_eq!(String::from_utf8_lossy(&output.stderr), "");
11621162

1163+
// the `--dir` flag prints no warning when used with `::`
1164+
let dir = tempfile::tempdir()?;
1165+
std::fs::write(dir.path().join("bar.txt"), b"And stood awhile in thought")?;
1166+
let output = get_wasmtime_command()?
1167+
.args(&[
1168+
"run",
1169+
&format!("--dir={}::/", dir.path().to_str().unwrap()),
1170+
test_programs_artifacts::CLI_FILE_READ,
1171+
])
1172+
.output()?;
1173+
assert_eq!(String::from_utf8_lossy(&output.stdout), "");
1174+
assert_eq!(String::from_utf8_lossy(&output.stderr), "");
1175+
11631176
Ok(())
11641177
}
11651178

0 commit comments

Comments
 (0)