From 7c25750e3ae801ac97d2a7a47918a96f11345b43 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Quentin?= Date: Tue, 28 May 2024 15:27:15 +0200 Subject: [PATCH] Improve `xtask` on Windows (#1632) * Improve `xtask` on Windows * Use already existing `windows_safe_path` function --- xtask/src/cargo.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/xtask/src/cargo.rs b/xtask/src/cargo.rs index e5f569613..74d12fa24 100644 --- a/xtask/src/cargo.rs +++ b/xtask/src/cargo.rs @@ -7,6 +7,8 @@ use std::{ use anyhow::{bail, Result}; +use crate::windows_safe_path; + #[derive(Debug, PartialEq)] pub enum CargoAction { Build, @@ -19,6 +21,12 @@ pub fn run(args: &[String], cwd: &Path) -> Result<()> { bail!("The `cwd` argument MUST be a directory"); } + // Make sure to not use a UNC as CWD! + // That would make `OUT_DIR` a UNC which will trigger things like the one fixed in https://github.com/dtolnay/rustversion/pull/51 + // While it's fixed in `rustversion` it's not fixed for other crates we are + // using now or in future! + let cwd = windows_safe_path(cwd); + let status = Command::new(get_cargo()) .args(args) .current_dir(cwd) @@ -37,6 +45,9 @@ pub fn run(args: &[String], cwd: &Path) -> Result<()> { } fn get_cargo() -> String { + // On Windows when executed via `cargo run` (e.g. via the xtask alias) the + // `cargo` on the search path is NOT the cargo-wrapper but the `cargo` from the + // toolchain - that one doesn't understand `+toolchain` #[cfg(target_os = "windows")] let cargo = if let Ok(cargo) = std::env::var("CARGO_HOME") { format!("{cargo}/bin/cargo")