@@ -11,7 +11,7 @@ use std::path::{Path, PathBuf};
11
11
use std:: process:: Command ;
12
12
use std:: time:: { Duration , Instant } ;
13
13
14
- use build_helper:: t ;
14
+ use build_helper:: { output , t } ;
15
15
16
16
use crate :: cache:: { Cache , Interned , INTERNER } ;
17
17
use crate :: check;
@@ -23,7 +23,7 @@ use crate::install;
23
23
use crate :: native;
24
24
use crate :: test;
25
25
use 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} ;
27
27
use crate :: { Build , DocTests , GitRepo , Mode } ;
28
28
29
29
pub use crate :: Compiler ;
@@ -1034,6 +1034,20 @@ impl<'a> Builder<'a> {
1034
1034
. env ( "RUSTC_SNAPSHOT_LIBDIR" , self . rustc_libdir ( compiler) ) ;
1035
1035
}
1036
1036
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
+
1037
1051
if self . config . incremental {
1038
1052
cargo. env ( "CARGO_INCREMENTAL" , "1" ) ;
1039
1053
} else {
0 commit comments