@@ -254,7 +254,7 @@ pub fn prepare_tool_cargo(
254254}
255255
256256macro_rules! tool {
257- ( $( $name: ident, $path: expr, $tool_name: expr, $mode: expr; ) +) => {
257+ ( $( $name: ident, $path: expr, $tool_name: expr, $mode: expr $ ( , llvm_tools = $llvm : expr ) * ; ) +) => {
258258 #[ derive( Copy , Clone ) ]
259259 pub enum Tool {
260260 $(
@@ -269,6 +269,13 @@ macro_rules! tool {
269269 } ;
270270 mode
271271 }
272+
273+ /// Whether this tool requires LLVM to run
274+ pub fn uses_llvm_tools( & self ) -> bool {
275+ match self {
276+ $( Tool :: $name => true $( && $llvm) * , ) +
277+ }
278+ }
272279 }
273280
274281 impl <' a> Builder <' a> {
@@ -333,6 +340,9 @@ macro_rules! tool {
333340 }
334341}
335342
343+ // FIXME(#51459): We have only checked that RustInstaller does not require
344+ // the LLVM binaries when running. We should go through all tools to determine
345+ // if they really need LLVM binaries, and make `llvm_tools` a required argument.
336346tool ! (
337347 Rustbook , "src/tools/rustbook" , "rustbook" , Mode :: ToolRustc ;
338348 ErrorIndex , "src/tools/error_index_generator" , "error_index_generator" , Mode :: ToolRustc ;
@@ -343,7 +353,7 @@ tool!(
343353 Compiletest , "src/tools/compiletest" , "compiletest" , Mode :: ToolTest ;
344354 BuildManifest , "src/tools/build-manifest" , "build-manifest" , Mode :: ToolStd ;
345355 RemoteTestClient , "src/tools/remote-test-client" , "remote-test-client" , Mode :: ToolStd ;
346- RustInstaller , "src/tools/rust-installer" , "fabricate" , Mode :: ToolStd ;
356+ RustInstaller , "src/tools/rust-installer" , "fabricate" , Mode :: ToolStd , llvm_tools = false ;
347357 RustdocTheme , "src/tools/rustdoc-themes" , "rustdoc-themes" , Mode :: ToolStd ;
348358) ;
349359
@@ -586,19 +596,19 @@ impl<'a> Builder<'a> {
586596 pub fn tool_cmd ( & self , tool : Tool ) -> Command {
587597 let mut cmd = Command :: new ( self . tool_exe ( tool) ) ;
588598 let compiler = self . compiler ( self . tool_default_stage ( tool) , self . config . build ) ;
589- self . prepare_tool_cmd ( compiler, tool. get_mode ( ) , & mut cmd) ;
599+ self . prepare_tool_cmd ( compiler, tool, & mut cmd) ;
590600 cmd
591601 }
592602
593603 /// Prepares the `cmd` provided to be able to run the `compiler` provided.
594604 ///
595605 /// Notably this munges the dynamic library lookup path to point to the
596606 /// right location to run `compiler`.
597- fn prepare_tool_cmd ( & self , compiler : Compiler , mode : Mode , cmd : & mut Command ) {
607+ fn prepare_tool_cmd ( & self , compiler : Compiler , tool : Tool , cmd : & mut Command ) {
598608 let host = & compiler. host ;
599609 let mut lib_paths: Vec < PathBuf > = vec ! [
600610 PathBuf :: from( & self . sysroot_libdir( compiler, compiler. host) ) ,
601- self . cargo_out( compiler, mode , * host) . join( "deps" ) ,
611+ self . cargo_out( compiler, tool . get_mode ( ) , * host) . join( "deps" ) ,
602612 ] ;
603613
604614 // On MSVC a tool may invoke a C compiler (e.g. compiletest in run-make
@@ -621,17 +631,19 @@ impl<'a> Builder<'a> {
621631
622632 // Add the llvm/bin directory to PATH since it contains lots of
623633 // useful, platform-independent tools
624- if let Some ( llvm_bin_path) = self . llvm_bin_path ( ) {
625- if host. contains ( "windows" ) {
626- // On Windows, PATH and the dynamic library path are the same,
627- // so we just add the LLVM bin path to lib_path
628- lib_paths. push ( llvm_bin_path) ;
629- } else {
630- let old_path = env:: var_os ( "PATH" ) . unwrap_or_default ( ) ;
631- let new_path = env:: join_paths ( iter:: once ( llvm_bin_path)
632- . chain ( env:: split_paths ( & old_path) ) )
633- . expect ( "Could not add LLVM bin path to PATH" ) ;
634- cmd. env ( "PATH" , new_path) ;
634+ if tool. uses_llvm_tools ( ) {
635+ if let Some ( llvm_bin_path) = self . llvm_bin_path ( ) {
636+ if host. contains ( "windows" ) {
637+ // On Windows, PATH and the dynamic library path are the same,
638+ // so we just add the LLVM bin path to lib_path
639+ lib_paths. push ( llvm_bin_path) ;
640+ } else {
641+ let old_path = env:: var_os ( "PATH" ) . unwrap_or_default ( ) ;
642+ let new_path = env:: join_paths ( iter:: once ( llvm_bin_path)
643+ . chain ( env:: split_paths ( & old_path) ) )
644+ . expect ( "Could not add LLVM bin path to PATH" ) ;
645+ cmd. env ( "PATH" , new_path) ;
646+ }
635647 }
636648 }
637649
0 commit comments