@@ -110,6 +110,18 @@ impl Tool {
110
110
cargo_output : & CargoOutput ,
111
111
out_dir : Option < & Path > ,
112
112
) -> 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
+
113
125
let out_dir = out_dir
114
126
. map ( Cow :: Borrowed )
115
127
. unwrap_or_else ( || Cow :: Owned ( env:: temp_dir ( ) ) ) ;
@@ -142,7 +154,8 @@ impl Tool {
142
154
143
155
let mut cmd = Command :: new ( path) ;
144
156
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" ) ) {
146
159
// #513: For `clang-cl`, separate flags/options from the input file.
147
160
// When cross-compiling macOS -> Windows, this avoids interpreting
148
161
// common `/Users/...` paths as the `/U` flag and triggering
@@ -163,21 +176,8 @@ impl Tool {
163
176
} ,
164
177
) ?;
165
178
let stdout = String :: from_utf8_lossy ( & stdout) ;
166
-
167
179
cargo_output. print_debug ( & stdout) ;
168
180
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
-
181
181
let clang = stdout. contains ( r#""clang""# ) ;
182
182
let gcc = stdout. contains ( r#""gcc""# ) ;
183
183
let emscripten = stdout. contains ( r#""emscripten""# ) ;
0 commit comments