@@ -23,7 +23,7 @@ use crate::builder::crate_description;
23
23
use crate :: builder:: Cargo ;
24
24
use crate :: builder:: { Builder , Kind , PathSet , RunConfig , ShouldRun , Step , TaskPath } ;
25
25
use crate :: cache:: { Interned , INTERNER } ;
26
- use crate :: config:: { LlvmLibunwind , RustcLto , TargetSelection } ;
26
+ use crate :: config:: { DebuginfoLevel , LlvmLibunwind , RustcLto , TargetSelection } ;
27
27
use crate :: dist;
28
28
use crate :: llvm;
29
29
use crate :: tool:: SourceType ;
@@ -883,16 +883,39 @@ impl Step for Rustc {
883
883
compiler. host ,
884
884
target,
885
885
) ;
886
+ let stamp = librustc_stamp ( builder, compiler, target) ;
886
887
run_cargo (
887
888
builder,
888
889
cargo,
889
890
vec ! [ ] ,
890
- & librustc_stamp ( builder , compiler , target ) ,
891
+ & stamp ,
891
892
vec ! [ ] ,
892
893
false ,
893
894
true , // Only ship rustc_driver.so and .rmeta files, not all intermediate .rlib files.
894
895
) ;
895
896
897
+ // When building `librustc_driver.so` (like `libLLVM.so`) on linux, it can contain
898
+ // unexpected debuginfo from dependencies, for example from the C++ standard library used in
899
+ // our LLVM wrapper. Unless we're explicitly requesting `librustc_driver` to be built with
900
+ // debuginfo (via the debuginfo level of the executables using it): strip this debuginfo
901
+ // away after the fact. This is to make the distributed artifacts smaller, and therefore we
902
+ // only do this at stage >= 1.
903
+ // FIXME: to make things simpler for now, limit this to the host and target where we know
904
+ // `strip -g` is both available and will fix the issue, i.e. on a x64 linux host that is not
905
+ // cross-compiling. Expand this to other appropriate targets in the future.
906
+ if compiler. stage != 0
907
+ && builder. config . rust_debuginfo_level_rustc == DebuginfoLevel :: None
908
+ && builder. config . rust_debuginfo_level_tools == DebuginfoLevel :: None
909
+ && target == "x86_64-unknown-linux-gnu"
910
+ && target == builder. config . build
911
+ {
912
+ let target_root_dir = stamp. parent ( ) . unwrap ( ) ;
913
+ let rustc_driver = target_root_dir. join ( "librustc_driver.so" ) ;
914
+ if rustc_driver. exists ( ) {
915
+ output ( Command :: new ( "strip" ) . arg ( "--strip-debug" ) . arg ( rustc_driver) ) ;
916
+ }
917
+ }
918
+
896
919
builder. ensure ( RustcLink :: from_rustc (
897
920
self ,
898
921
builder. compiler ( compiler. stage , builder. config . build ) ,
0 commit comments