@@ -29,7 +29,6 @@ use build_helper::{output, mtime, up_to_date};
29
29
use filetime:: FileTime ;
30
30
use serde_json;
31
31
32
- use crate :: dist;
33
32
use crate :: util:: { exe, libdir, is_dylib} ;
34
33
use crate :: { Compiler , Mode , GitRepo } ;
35
34
use crate :: native;
@@ -115,6 +114,7 @@ impl Step for Std {
115
114
& compiler. host, target) ) ;
116
115
run_cargo ( builder,
117
116
& mut cargo,
117
+ vec ! [ ] ,
118
118
& libstd_stamp ( builder, compiler, target) ,
119
119
false ) ;
120
120
@@ -375,6 +375,7 @@ impl Step for Test {
375
375
& compiler. host, target) ) ;
376
376
run_cargo ( builder,
377
377
& mut cargo,
378
+ vec ! [ ] ,
378
379
& libtest_stamp ( builder, compiler, target) ,
379
380
false ) ;
380
381
@@ -502,6 +503,7 @@ impl Step for Rustc {
502
503
compiler. stage, & compiler. host, target) ) ;
503
504
run_cargo ( builder,
504
505
& mut cargo,
506
+ vec ! [ ] ,
505
507
& librustc_stamp ( builder, compiler, target) ,
506
508
false ) ;
507
509
@@ -644,18 +646,47 @@ impl Step for CodegenBackend {
644
646
645
647
let out_dir = builder. cargo_out ( compiler, Mode :: Codegen , target) ;
646
648
647
- let mut cargo = builder. cargo ( compiler, Mode :: Codegen , target, "build " ) ;
649
+ let mut cargo = builder. cargo ( compiler, Mode :: Codegen , target, "rustc " ) ;
648
650
cargo. arg ( "--manifest-path" )
649
651
. arg ( builder. src . join ( "src/librustc_codegen_llvm/Cargo.toml" ) ) ;
650
652
rustc_cargo_env ( builder, & mut cargo) ;
651
653
652
654
let features = build_codegen_backend ( & builder, & mut cargo, & compiler, target, backend) ;
653
655
656
+ let mut cargo_tails_args = vec ! [ ] ;
657
+
658
+ if builder. config . llvm_thin_lto {
659
+ cargo_tails_args. push ( "--" . to_string ( ) ) ;
660
+
661
+ let num_jobs = builder. jobs ( ) ;
662
+
663
+ if !target. contains ( "msvc" ) {
664
+ // Here we assume that the linker is clang. If it's not, there'll
665
+ // be linker errors.
666
+ cargo_tails_args. push ( "-Clink-arg=-fuse-ld=lld" . to_string ( ) ) ;
667
+ cargo_tails_args. push ( "-Clink-arg=-flto=thin" . to_string ( ) ) ;
668
+
669
+ if builder. config . llvm_optimize {
670
+ cargo_tails_args. push ( "-Clink-arg=-O2" . to_string ( ) ) ;
671
+ }
672
+
673
+ // Let's make LLD respect the `-j` option.
674
+ let num_jobs_arg = format ! ( "-Clink-arg=-Wl,--thinlto-jobs={}" , num_jobs) ;
675
+ cargo_tails_args. push ( num_jobs_arg) ;
676
+ } else {
677
+ // Here we assume that the linker is lld-link.exe. lld-link.exe
678
+ // does not need the extra arguments except for num_jobs
679
+ let num_jobs_arg = format ! ( "-Clink-arg=/opt:lldltojobs={}" , num_jobs) ;
680
+ cargo_tails_args. push ( num_jobs_arg) ;
681
+ }
682
+ }
683
+
654
684
let tmp_stamp = out_dir. join ( ".tmp.stamp" ) ;
655
685
656
686
let _folder = builder. fold_output ( || format ! ( "stage{}-rustc_codegen_llvm" , compiler. stage) ) ;
657
687
let files = run_cargo ( builder,
658
688
cargo. arg ( "--features" ) . arg ( features) ,
689
+ cargo_tails_args,
659
690
& tmp_stamp,
660
691
false ) ;
661
692
if builder. config . dry_run {
@@ -728,9 +759,7 @@ pub fn build_codegen_backend(builder: &Builder,
728
759
"libstdc++.a" ) ;
729
760
cargo. env ( "LLVM_STATIC_STDCPP" , file) ;
730
761
}
731
- if builder. config . llvm_link_shared ||
732
- ( builder. config . llvm_thin_lto && backend != "emscripten" )
733
- {
762
+ if builder. config . llvm_link_shared {
734
763
cargo. env ( "LLVM_LINK_SHARED" , "1" ) ;
735
764
}
736
765
}
@@ -970,8 +999,6 @@ impl Step for Assemble {
970
999
copy_lld_to_sysroot ( builder, target_compiler, & lld_install) ;
971
1000
}
972
1001
973
- dist:: maybe_install_llvm_dylib ( builder, target_compiler. host , & sysroot) ;
974
-
975
1002
// Link the compiler binary itself into place
976
1003
let out_dir = builder. cargo_out ( build_compiler, Mode :: Rustc , host) ;
977
1004
let rustc = out_dir. join ( exe ( "rustc_binary" , & * host) ) ;
@@ -998,6 +1025,7 @@ pub fn add_to_sysroot(builder: &Builder, sysroot_dst: &Path, stamp: &Path) {
998
1025
999
1026
pub fn run_cargo ( builder : & Builder ,
1000
1027
cargo : & mut Command ,
1028
+ tail_args : Vec < String > ,
1001
1029
stamp : & Path ,
1002
1030
is_check : bool )
1003
1031
-> Vec < PathBuf >
@@ -1020,7 +1048,7 @@ pub fn run_cargo(builder: &Builder,
1020
1048
// files we need to probe for later.
1021
1049
let mut deps = Vec :: new ( ) ;
1022
1050
let mut toplevel = Vec :: new ( ) ;
1023
- let ok = stream_cargo ( builder, cargo, & mut |msg| {
1051
+ let ok = stream_cargo ( builder, cargo, tail_args , & mut |msg| {
1024
1052
let filenames = match msg {
1025
1053
CargoMessage :: CompilerArtifact { filenames, .. } => filenames,
1026
1054
_ => return ,
@@ -1145,6 +1173,7 @@ pub fn run_cargo(builder: &Builder,
1145
1173
pub fn stream_cargo (
1146
1174
builder : & Builder ,
1147
1175
cargo : & mut Command ,
1176
+ tail_args : Vec < String > ,
1148
1177
cb : & mut dyn FnMut ( CargoMessage ) ,
1149
1178
) -> bool {
1150
1179
if builder. config . dry_run {
@@ -1155,6 +1184,10 @@ pub fn stream_cargo(
1155
1184
cargo. arg ( "--message-format" ) . arg ( "json" )
1156
1185
. stdout ( Stdio :: piped ( ) ) ;
1157
1186
1187
+ for arg in tail_args {
1188
+ cargo. arg ( arg) ;
1189
+ }
1190
+
1158
1191
builder. verbose ( & format ! ( "running: {:?}" , cargo) ) ;
1159
1192
let mut child = match cargo. spawn ( ) {
1160
1193
Ok ( child) => child,
0 commit comments