From 9c227f7f9eff9fedf66cc2c643607f203cbef3c4 Mon Sep 17 00:00:00 2001 From: David Calavera Date: Wed, 30 Mar 2022 22:37:46 -0700 Subject: [PATCH] Fix Zig detection on Windows. We need to execute the search command in a new Windows shell to work, otherwise the command always fails with "Program not found". Signed-off-by: David Calavera --- src/zig.rs | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/src/zig.rs b/src/zig.rs index 792d398..747c488 100644 --- a/src/zig.rs +++ b/src/zig.rs @@ -169,7 +169,14 @@ impl Zig { /// Detect the plain zig binary fn find_zig_bin() -> Result<(String, Vec)> { - let output = Command::new("zig").arg("version").output()?; + let output = if cfg!(target_os = "windows") { + Command::new("cmd.exe") + .args(&["/c", "zig", "version"]) + .output()? + } else { + Command::new("zig").arg("version").output()? + }; + let version_str = str::from_utf8(&output.stdout).context("`zig version` didn't return utf8 output")?; Self::validate_zig_version(version_str)?; @@ -178,9 +185,16 @@ impl Zig { /// Detect the Python ziglang package fn find_zig_python() -> Result<(String, Vec)> { - let output = Command::new("python3") - .args(&["-m", "ziglang", "version"]) - .output()?; + let output = if cfg!(target_os = "windows") { + Command::new("cmd.exe") + .args(&["/c", "python3", "-m", "ziglang", "version"]) + .output()? + } else { + Command::new("python3") + .args(&["-m", "ziglang", "version"]) + .output()? + }; + let version_str = str::from_utf8(&output.stdout) .context("`python3 -m ziglang version` didn't return utf8 output")?; Self::validate_zig_version(version_str)?;