diff --git a/src/tool.rs b/src/tool.rs index a7e3f926..ecf5b7b4 100644 --- a/src/tool.rs +++ b/src/tool.rs @@ -110,6 +110,18 @@ impl Tool { cargo_output: &CargoOutput, out_dir: Option<&Path>, ) -> Result { + // https://gitlab.kitware.com/cmake/cmake/-/blob/69a2eeb9dff5b60f2f1e5b425002a0fd45b7cadb/Modules/CMakeDetermineCompilerId.cmake#L267-271 + // stdin is set to null to ensure that the help output is never paginated. + let accepts_cl_style_flags = + run(Command::new(path).arg("-?").stdin(Stdio::null()), path, &{ + // the errors are not errors! + let mut cargo_output = cargo_output.clone(); + cargo_output.warnings = cargo_output.debug; + cargo_output.output = OutputKind::Discard; + cargo_output + }) + .is_ok(); + let out_dir = out_dir .map(Cow::Borrowed) .unwrap_or_else(|| Cow::Owned(env::temp_dir())); @@ -142,7 +154,8 @@ impl Tool { let mut cmd = Command::new(path); cmd.arg("-E"); - if compiler.family == (ToolFamily::Msvc { clang_cl: true }) { + // there is no reliable way to detect clang-cl at this point + if accepts_cl_style_flags && path.file_name() == Some(OsStr::new("clang-cl")) { // #513: For `clang-cl`, separate flags/options from the input file. // When cross-compiling macOS -> Windows, this avoids interpreting // common `/Users/...` paths as the `/U` flag and triggering @@ -163,21 +176,8 @@ impl Tool { }, )?; 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 - // stdin is set to null to ensure that the help output is never paginated. - let accepts_cl_style_flags = - run(Command::new(path).arg("-?").stdin(Stdio::null()), path, &{ - // the errors are not errors! - let mut cargo_output = cargo_output.clone(); - cargo_output.warnings = cargo_output.debug; - cargo_output.output = OutputKind::Discard; - cargo_output - }) - .is_ok(); - let clang = stdout.contains(r#""clang""#); let gcc = stdout.contains(r#""gcc""#); let emscripten = stdout.contains(r#""emscripten""#);