diff --git a/Cargo.lock b/Cargo.lock index ca3bf04bc..3e30cbaa3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -476,6 +476,7 @@ dependencies = [ "contract-metadata", "contract-transcode", "current_platform", + "dirs", "heck", "hex", "impl-serde", @@ -885,6 +886,26 @@ dependencies = [ "subtle", ] +[[package]] +name = "dirs" +version = "4.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ca3aa72a6f96ea37bbc5aa912f6788242832f75369bdfdadcb0e38423f100059" +dependencies = [ + "dirs-sys", +] + +[[package]] +name = "dirs-sys" +version = "0.3.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1b1d1d91c932ef41c0f2663aa8b0ca0342d444d842c06914aa0a7e352d0bada6" +dependencies = [ + "libc", + "redox_users", + "winapi", +] + [[package]] name = "doc-comment" version = "0.3.3" @@ -2427,6 +2448,17 @@ dependencies = [ "bitflags", ] +[[package]] +name = "redox_users" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b033d837a7cf162d7993aded9304e30a83213c648b6e389db233191f891e5c2b" +dependencies = [ + "getrandom 0.2.6", + "redox_syscall", + "thiserror", +] + [[package]] name = "ref-cast" version = "1.0.7" diff --git a/Cargo.toml b/Cargo.toml index 173cabc15..d4d2cbc18 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -59,6 +59,7 @@ jsonrpsee = { version = "0.15.1", features = ["ws-client"] } [build-dependencies] anyhow = "1.0.61" +dirs = "4.0.0" zip = { version = "0.6.2", default-features = false } walkdir = "2.3.2" substrate-build-script-utils = "3.0.0" diff --git a/build.rs b/build.rs index 5a2b45334..a7849aa34 100644 --- a/build.rs +++ b/build.rs @@ -166,6 +166,24 @@ fn build_and_zip_dylint_driver( dylint_driver_dst_file: PathBuf, ) -> Result<()> { let mut cmd = Command::new("cargo"); + #[cfg(windows)] + { + // copied workaround from dylint for https://github.com/rust-lang/rustup/pull/2978 + let cargo_home = match env::var("CARGO_HOME") { + Ok(value) => Ok(PathBuf::from(value)), + Err(error) => { + dirs::home_dir() + .map(|path| path.join(".cargo")) + .ok_or(error) + } + }?; + let old_path = crate::env::var("PATH")?; + let new_path = std::env::join_paths( + std::iter::once(Path::new(&cargo_home).join("bin")) + .chain(std::env::split_paths(&old_path)), + )?; + cmd.envs(vec![("PATH", new_path)]); + } let manifest_arg = format!( "--manifest-path={}",