@@ -13,14 +13,14 @@ use std::ffi::{OsStr, OsString};
1313use std:: path:: PathBuf ;
1414use std:: { env, fs} ;
1515
16- use crate :: Build ;
1716#[ cfg( not( test) ) ]
1817use crate :: builder:: Builder ;
1918use crate :: builder:: Kind ;
2019#[ cfg( not( test) ) ]
2120use crate :: core:: build_steps:: tool;
2221use crate :: core:: config:: Target ;
2322use crate :: utils:: exec:: command;
23+ use crate :: { Build , Subcommand } ;
2424
2525pub struct Finder {
2626 cache : HashMap < OsString , Option < PathBuf > > ,
@@ -205,6 +205,20 @@ than building it.
205205 . map ( |s| s. to_string ( ) )
206206 . collect ( ) ;
207207
208+ // Compiler tools like `cc` and `ar` are not configured for cross-targets on certain subcommands
209+ // because they are not needed.
210+ //
211+ // See `cc_detect::find` for more details.
212+ let skip_tools_checks = build. config . dry_run ( )
213+ || matches ! (
214+ build. config. cmd,
215+ Subcommand :: Clean { .. }
216+ | Subcommand :: Check { .. }
217+ | Subcommand :: Suggest { .. }
218+ | Subcommand :: Format { .. }
219+ | Subcommand :: Setup { .. }
220+ ) ;
221+
208222 // We're gonna build some custom C code here and there, host triples
209223 // also build some C++ shims for LLVM so we need a C++ compiler.
210224 for target in & build. targets {
@@ -278,15 +292,15 @@ than building it.
278292 }
279293 }
280294
281- if !build . config . dry_run ( ) {
295+ if !skip_tools_checks {
282296 cmd_finder. must_have ( build. cc ( * target) ) ;
283297 if let Some ( ar) = build. ar ( * target) {
284298 cmd_finder. must_have ( ar) ;
285299 }
286300 }
287301 }
288302
289- if !build . config . dry_run ( ) {
303+ if !skip_tools_checks {
290304 for host in & build. hosts {
291305 cmd_finder. must_have ( build. cxx ( * host) . unwrap ( ) ) ;
292306
0 commit comments