diff --git a/Cargo.lock b/Cargo.lock index 9cf4cf60..d2aad0e4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -963,6 +963,7 @@ version = "0.5.0" dependencies = [ "atty 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", "cargo_metadata 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", + "cfg-if 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", "console 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)", "curl 0.4.17 (registry+https://github.com/rust-lang/crates.io-index)", "failure 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", diff --git a/Cargo.toml b/Cargo.toml index 3e2e1377..3570a516 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,6 +12,7 @@ documentation = "https://rustwasm.github.io/wasm-pack/" [dependencies] atty = "0.2.11" cargo_metadata = "0.6.0" +cfg-if = "0.1.5" console = "0.6.1" curl = "0.4.13" failure = "0.1.2" diff --git a/src/command/build.rs b/src/command/build.rs index 9e81c653..4cfec2eb 100644 --- a/src/command/build.rs +++ b/src/command/build.rs @@ -2,6 +2,7 @@ use bindgen; use build; +use command::utils::canonicalize_path; use command::utils::{create_pkg_dir, set_crate_path}; use emoji; use error::Error; @@ -141,7 +142,7 @@ impl Build { PBAR.message(&format!( "{} Your wasm pkg is ready to publish at {:#?}.", emoji::PACKAGE, - self.out_dir.canonicalize().unwrap_or(self.out_dir.clone()) + canonicalize_path(self.out_dir.clone()).unwrap_or(self.out_dir.clone()) )); Ok(()) } diff --git a/src/command/utils.rs b/src/command/utils.rs index 07db00cd..0556669f 100644 --- a/src/command/utils.rs +++ b/src/command/utils.rs @@ -4,19 +4,17 @@ use emoji; use error::Error; use progressbar::Step; use std::fs; -use std::io; use std::path::{Path, PathBuf}; use PBAR; /// If an explicit path is given, then use it, otherwise assume the current /// directory is the crate path. -pub fn set_crate_path(path: Option) -> io::Result { +pub fn set_crate_path(path: Option) -> Result { let crate_path = match path { Some(p) => p, None => PathBuf::from("."), }; - - crate_path.canonicalize() + canonicalize_path(crate_path) } /// Construct our `pkg` directory in the crate. @@ -44,3 +42,29 @@ pub fn find_pkg_directory(path: &Path) -> Option { fn is_pkg_directory(path: &Path) -> bool { path.exists() && path.is_dir() && path.ends_with("pkg") } + +cfg_if! { + if #[cfg(windows)] { + /// Strips UNC from canonical path on Windows. + /// See https://github.com/rust-lang/rust/issues/42869 for why this is needed. + pub fn canonicalize_path(path: PathBuf) -> Result { + use std::ffi::OsString; + use std::os::windows::prelude::*; + let canonical = path.canonicalize()?; + let vec_chars = canonical.as_os_str().encode_wide().collect::>(); + if vec_chars[0..4] == [92, 92, 63, 92] { + Ok(Path::new(&OsString::from_wide(&vec_chars[4..])).to_owned()) + } + else { + Ok(canonical) + } + } + } + else { + /// Strips UNC from canonical path on Windows. + pub fn canonicalize_path(path: PathBuf) -> Result { + let canonical = path.canonicalize()?; + Ok(canonical) + } + } +} diff --git a/src/lib.rs b/src/lib.rs index bb3f2b1c..2d752473 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -3,6 +3,8 @@ #![deny(missing_docs)] extern crate cargo_metadata; +#[macro_use] +extern crate cfg_if; extern crate console; extern crate curl; #[macro_use]