Skip to content

Commit 18ef92c

Browse files
ricochetvados-cosmonic
authored andcommitted
fix(wash): windows path to target
Verbatim paths on Windows are not well supported, e.g. "\\\\?\\C:\\Users..." while technically valid, causes some fs api's like `exists` to fail errantly. The fix is to use a third party lib normpath to normalize the path to the wasm binary. Related issue: rust-lang/cargo#9770 Signed-off-by: Bailey Hayes <behayes2@gmail.com> Co-authored-by: Victor Adossi <123968127+vados-cosmonic@users.noreply.github.com>
1 parent c413b3e commit 18ef92c

File tree

4 files changed

+35
-21
lines changed

4 files changed

+35
-21
lines changed

Cargo.lock

+10
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ names = { version = "0.14", default-features = false }
118118
nix = { version = "0.27", default-features = false }
119119
nkeys = { version = "0.3", default-features = false }
120120
notify = { version = "6", default-features = false }
121+
normpath = { version = "1.1" , default-features = false }
121122
nuid = { version = "0.4", default-features = false }
122123
oci-distribution = { version = "0.9", default-features = false }
123124
once_cell = { version = "1", default-features = false }

crates/wash-lib/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ heck = { workspace = true, optional = true }
5454
ignore = { workspace = true, optional = true }
5555
indicatif = { workspace = true, optional = true }
5656
nkeys = { workspace = true }
57+
normpath = { workspace = true }
5758
oci-distribution = { workspace = true, features = ["rustls-tls"] }
5859
path-absolutize = { workspace = true, features = [
5960
"once_cell_cache",

crates/wash-lib/src/build.rs

+23-21
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use std::{
99
};
1010

1111
use anyhow::{anyhow, bail, Context, Result};
12+
use normpath::PathExt;
1213
use tracing::{debug, info, warn};
1314
use wasm_encoder::{Encode, Section};
1415
use wit_bindgen_core::Files;
@@ -240,10 +241,7 @@ fn build_rust_actor(
240241
// Change directory into the project directory
241242
std::env::set_current_dir(&common_config.path)?;
242243

243-
let metadata = cargo_metadata::MetadataCommand::new().exec()?;
244-
let target_path = metadata.target_directory.as_path();
245-
let build_target = rust_config.build_target(&actor_config.wasm_target);
246-
244+
let build_target: &str = rust_config.build_target(&actor_config.wasm_target);
247245
let result = command
248246
.args(["build", "--release", "--target", build_target])
249247
.status()
@@ -265,23 +263,27 @@ fn build_rust_actor(
265263
.as_ref()
266264
.unwrap_or(&common_config.name);
267265

268-
let wasm_file = PathBuf::from(format!(
269-
"{}/{}/release/{}.wasm",
270-
rust_config
271-
.target_path
272-
.clone()
273-
.unwrap_or_else(|| PathBuf::from(target_path))
274-
.to_string_lossy(),
275-
build_target,
276-
wasm_bin_name,
277-
));
278-
279-
if !wasm_file.exists() {
280-
bail!(
281-
"Could not find compiled wasm file, please ensure {} exists",
282-
wasm_file.display()
283-
);
284-
}
266+
// NOTE: Windows paths are tricky.
267+
// We're using a third-party library normpath to ensure that the paths are normalized.
268+
// Once out of nightly, we should be able to use std::path::absolute
269+
// https://github.com/rust-lang/rust/pull/91673
270+
let metadata = cargo_metadata::MetadataCommand::new().exec()?;
271+
let target_path = rust_config
272+
.target_path
273+
.clone()
274+
.unwrap_or_else(|| PathBuf::from(metadata.target_directory.as_std_path()));
275+
let mut wasm_path_buf = PathBuf::from(target_path);
276+
wasm_path_buf.push(build_target);
277+
wasm_path_buf.push("release");
278+
wasm_path_buf.push(format!("{}.wasm", wasm_bin_name));
279+
280+
// Ensure the file exists, normalize uses the fs and file must exist
281+
let wasm_file = match wasm_path_buf.normalize() {
282+
Ok(p) => p,
283+
Err(e) => bail!(
284+
"Could not find compiled wasm file, please ensure {:?} exists. Error: {:?}", wasm_path_buf, e
285+
),
286+
};
285287

286288
// move the file out into the build/ folder for parity with tinygo and convienience for users.
287289
let copied_wasm_file = PathBuf::from(format!("build/{}.wasm", wasm_bin_name));

0 commit comments

Comments
 (0)