@@ -11,7 +11,7 @@ use std::path::{Path, PathBuf};
1111use std:: process:: Command ;
1212use std:: time:: { Duration , Instant } ;
1313
14- use build_helper:: t ;
14+ use build_helper:: { output , t } ;
1515
1616use crate :: cache:: { Cache , Interned , INTERNER } ;
1717use crate :: check;
@@ -23,7 +23,7 @@ use crate::install;
2323use crate :: native;
2424use crate :: test;
2525use crate :: tool;
26- use crate :: util:: { self , add_dylib_path, exe, libdir} ;
26+ use crate :: util:: { self , add_dylib_path, add_link_lib_path , exe, libdir} ;
2727use crate :: { Build , DocTests , GitRepo , Mode } ;
2828
2929pub use crate :: Compiler ;
@@ -1034,6 +1034,20 @@ impl<'a> Builder<'a> {
10341034 . env ( "RUSTC_SNAPSHOT_LIBDIR" , self . rustc_libdir ( compiler) ) ;
10351035 }
10361036
1037+ // Tools that use compiler libraries may inherit the `-lLLVM` link
1038+ // requirement, but the `-L` library path is not propagated across
1039+ // separate Cargo projects. We can add LLVM's library path to the
1040+ // platform-specific environment variable as a workaround.
1041+ //
1042+ // Note that this is disabled if LLVM itself is disabled or we're in a
1043+ // check build, where if we're in a check build there's no need to build
1044+ // all of LLVM and such.
1045+ if self . config . llvm_enabled ( ) && self . kind != Kind :: Check && mode == Mode :: ToolRustc {
1046+ let llvm_config = self . ensure ( native:: Llvm { target } ) ;
1047+ let llvm_libdir = output ( Command :: new ( & llvm_config) . arg ( "--libdir" ) ) ;
1048+ add_link_lib_path ( vec ! [ llvm_libdir. trim( ) . into( ) ] , & mut cargo) ;
1049+ }
1050+
10371051 if self . config . incremental {
10381052 cargo. env ( "CARGO_INCREMENTAL" , "1" ) ;
10391053 } else {
0 commit comments