From 0a59f811b7b98da55e08960d6ab9d2a04e77b004 Mon Sep 17 00:00:00 2001 From: Jiahao XU <30436523+NobodyXu@users.noreply.github.com> Date: Sat, 11 Jan 2025 23:49:48 +1100 Subject: [PATCH 1/3] Fix compiler detection for cargo-zigbuild --- src/tool.rs | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/tool.rs b/src/tool.rs index af43a918e..f11ea1dfe 100644 --- a/src/tool.rs +++ b/src/tool.rs @@ -106,10 +106,11 @@ impl Tool { } fn guess_family_from_stdout( - stdout: &str, + stdout: &[u8], path: &Path, cargo_output: &CargoOutput, ) -> Result { + let stdout = String::from_utf8_lossy(&stdout); cargo_output.print_debug(&stdout); // https://gitlab.kitware.com/cmake/cmake/-/blob/69a2eeb9dff5b60f2f1e5b425002a0fd45b7cadb/Modules/CMakeDetermineCompilerId.cmake#L267-271 @@ -192,18 +193,17 @@ impl Tool { path, &compiler_detect_output, )?; - let stdout = String::from_utf8_lossy(&stdout); - if stdout.contains("-Wslash-u-filename") { - let stdout = run_output( - Command::new(path).arg("-E").arg("--").arg(tmp.path()), - path, - &compiler_detect_output, - )?; - let stdout = String::from_utf8_lossy(&stdout); - guess_family_from_stdout(&stdout, path, cargo_output) - } else { - guess_family_from_stdout(&stdout, path, cargo_output) + match guess_family_from_stdout(&stdout, path, cargo_output) { + Err(_) if String::from_utf8(&stdout).contains("-Wslash-u-filename") => { + let stdout = run_output( + Command::new(path).arg("-E").arg("--").arg(tmp.path()), + path, + &compiler_detect_output, + )?; + guess_family_from_stdout(&stdout, path, cargo_output) + } + res => res, } } let detect_family = |path: &Path| -> Result { From fada001df5723f238d3f6a094a4c8bf89734f32e Mon Sep 17 00:00:00 2001 From: Jiahao XU <30436523+NobodyXu@users.noreply.github.com> Date: Sun, 12 Jan 2025 01:22:17 +1100 Subject: [PATCH 2/3] Fix compilation in tool.rs --- src/tool.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tool.rs b/src/tool.rs index f11ea1dfe..517896afd 100644 --- a/src/tool.rs +++ b/src/tool.rs @@ -195,7 +195,7 @@ impl Tool { )?; match guess_family_from_stdout(&stdout, path, cargo_output) { - Err(_) if String::from_utf8(&stdout).contains("-Wslash-u-filename") => { + Err(_) if String::from_utf8_lossy(&stdout).contains("-Wslash-u-filename") => { let stdout = run_output( Command::new(path).arg("-E").arg("--").arg(tmp.path()), path, From 162de1ba3a04e14b6c94bd4ee61c96aec6bcaeb8 Mon Sep 17 00:00:00 2001 From: Jiahao XU <30436523+NobodyXu@users.noreply.github.com> Date: Sun, 12 Jan 2025 01:30:52 +1100 Subject: [PATCH 3/3] Fix clippy warning in tool.rs --- src/tool.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tool.rs b/src/tool.rs index 517896afd..a96ef5d5f 100644 --- a/src/tool.rs +++ b/src/tool.rs @@ -110,7 +110,7 @@ impl Tool { path: &Path, cargo_output: &CargoOutput, ) -> Result { - let stdout = String::from_utf8_lossy(&stdout); + let stdout = String::from_utf8_lossy(stdout); cargo_output.print_debug(&stdout); // https://gitlab.kitware.com/cmake/cmake/-/blob/69a2eeb9dff5b60f2f1e5b425002a0fd45b7cadb/Modules/CMakeDetermineCompilerId.cmake#L267-271