Skip to content

Commit acfec3e

Browse files
committed
Fix compiler family detection on clang-cl workaround
1 parent 6e800fe commit acfec3e

File tree

1 file changed

+14
-14
lines changed

1 file changed

+14
-14
lines changed

src/tool.rs

+14-14
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,18 @@ impl Tool {
110110
cargo_output: &CargoOutput,
111111
out_dir: Option<&Path>,
112112
) -> Result<ToolFamily, Error> {
113+
// https://gitlab.kitware.com/cmake/cmake/-/blob/69a2eeb9dff5b60f2f1e5b425002a0fd45b7cadb/Modules/CMakeDetermineCompilerId.cmake#L267-271
114+
// stdin is set to null to ensure that the help output is never paginated.
115+
let accepts_cl_style_flags =
116+
run(Command::new(path).arg("-?").stdin(Stdio::null()), path, &{
117+
// the errors are not errors!
118+
let mut cargo_output = cargo_output.clone();
119+
cargo_output.warnings = cargo_output.debug;
120+
cargo_output.output = OutputKind::Discard;
121+
cargo_output
122+
})
123+
.is_ok();
124+
113125
let out_dir = out_dir
114126
.map(Cow::Borrowed)
115127
.unwrap_or_else(|| Cow::Owned(env::temp_dir()));
@@ -142,7 +154,8 @@ impl Tool {
142154

143155
let mut cmd = Command::new(path);
144156
cmd.arg("-E");
145-
if compiler.family == (ToolFamily::Msvc { clang_cl: true }) {
157+
// there is no reliable way to detect clang-cl at this point
158+
if accepts_cl_style_flags && path.file_name() == Some(OsStr::new("clang-cl")) {
146159
// #513: For `clang-cl`, separate flags/options from the input file.
147160
// When cross-compiling macOS -> Windows, this avoids interpreting
148161
// common `/Users/...` paths as the `/U` flag and triggering
@@ -163,21 +176,8 @@ impl Tool {
163176
},
164177
)?;
165178
let stdout = String::from_utf8_lossy(&stdout);
166-
167179
cargo_output.print_debug(&stdout);
168180

169-
// https://gitlab.kitware.com/cmake/cmake/-/blob/69a2eeb9dff5b60f2f1e5b425002a0fd45b7cadb/Modules/CMakeDetermineCompilerId.cmake#L267-271
170-
// stdin is set to null to ensure that the help output is never paginated.
171-
let accepts_cl_style_flags =
172-
run(Command::new(path).arg("-?").stdin(Stdio::null()), path, &{
173-
// the errors are not errors!
174-
let mut cargo_output = cargo_output.clone();
175-
cargo_output.warnings = cargo_output.debug;
176-
cargo_output.output = OutputKind::Discard;
177-
cargo_output
178-
})
179-
.is_ok();
180-
181181
let clang = stdout.contains(r#""clang""#);
182182
let gcc = stdout.contains(r#""gcc""#);
183183
let emscripten = stdout.contains(r#""emscripten""#);

0 commit comments

Comments
 (0)