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

[14.0.0] Swap the order of directories in --dir #7303

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
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: 2 additions & 2 deletions ci/run-wasi-nn-example.sh
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,15 @@ pushd $WASMTIME_DIR/crates/wasi-nn/examples/classification-example
cargo build --release --target=wasm32-wasi
cp target/wasm32-wasi/release/wasi-nn-example.wasm $TMP_DIR
popd
cargo run -- run --dir fixture::$TMP_DIR -S nn $TMP_DIR/wasi-nn-example.wasm
cargo run -- run --dir $TMP_DIR::fixture -S nn $TMP_DIR/wasi-nn-example.wasm

# Build and run another example, this time using Wasmtime's graph flag to
# preload the model.
pushd $WASMTIME_DIR/crates/wasi-nn/examples/classification-example-named
cargo build --release --target=wasm32-wasi
cp target/wasm32-wasi/release/wasi-nn-example-named.wasm $TMP_DIR
popd
cargo run -- run --dir fixture::$TMP_DIR -S nn,nn-graph=openvino::$TMP_DIR \
cargo run -- run --dir $TMP_DIR::fixture -S nn,nn-graph=openvino::$TMP_DIR \
$TMP_DIR/wasi-nn-example-named.wasm

# Clean up the temporary directory only if it was not specified (users may want
Expand Down
2 changes: 1 addition & 1 deletion docs/WASI-tutorial.md
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ links as well.
`wasmtime` also has the ability to remap directories:

```
$ wasmtime --dir=. --dir=/tmp::/var/tmp demo.wasm test.txt /tmp/somewhere.txt
$ wasmtime --dir=. --dir=/var/tmp::/tmp demo.wasm test.txt /tmp/somewhere.txt
$ cat /var/tmp/somewhere.txt
hello world
```
Expand Down
18 changes: 9 additions & 9 deletions src/commands/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,12 @@ fn parse_env_var(s: &str) -> Result<(String, Option<String>)> {

fn parse_dirs(s: &str) -> Result<(String, String)> {
let mut parts = s.split("::");
let guest = parts.next().unwrap();
let host = match parts.next() {
Some(host) => host,
None => guest,
let host = parts.next().unwrap();
let guest = match parts.next() {
Some(guest) => guest,
None => host,
};
Ok((guest.into(), host.into()))
Ok((host.into(), guest.into()))
}

fn parse_preloads(s: &str) -> Result<(String, PathBuf)> {
Expand All @@ -66,11 +66,11 @@ pub struct RunCommand {

/// Grant access of a host directory to a guest.
///
/// If specified as just `GUEST_DIR` then the same directory name on the
/// host is made available within the guest. If specified as `GUEST::HOST`
/// If specified as just `HOST_DIR` then the same directory name on the
/// host is made available within the guest. If specified as `HOST::GUEST`
/// then the `HOST` directory is opened and made available as the name
/// `GUEST` in the guest.
#[clap(long = "dir", value_name = "GUEST_DIR[::HOST_DIR]", value_parser = parse_dirs)]
#[clap(long = "dir", value_name = "HOST_DIR[::GUEST_DIR]", value_parser = parse_dirs)]
dirs: Vec<(String, String)>,

/// Pass an environment variable to the program.
Expand Down Expand Up @@ -230,7 +230,7 @@ impl RunCommand {
fn compute_preopen_dirs(&self) -> Result<Vec<(String, Dir)>> {
let mut preopen_dirs = Vec::new();

for (guest, host) in self.dirs.iter() {
for (host, guest) in self.dirs.iter() {
preopen_dirs.push((
guest.clone(),
Dir::open_ambient_dir(host, ambient_authority())
Expand Down
2 changes: 1 addition & 1 deletion tests/all/wasi_testsuite.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ fn build_command<P: AsRef<Path>>(module: P, extra_flags: &[&str], spec: &Spec) -
if let Some(dirs) = &spec.dirs {
for dir in dirs {
cmd.arg("--dir");
cmd.arg(format!("{}::{}", dir, parent_dir.join(dir).display()));
cmd.arg(format!("{}::{}", parent_dir.join(dir).display(), dir));
}
}
// Add environment variables as CLI arguments.
Expand Down