File tree 3 files changed +30
-4
lines changed
3 files changed +30
-4
lines changed Original file line number Diff line number Diff line change @@ -92,9 +92,11 @@ fn main() {
92
92
// Get the name of the crate we're compiling, if any.
93
93
let crate_name = parse_value_from_args ( & orig_args, "--crate-name" ) ;
94
94
95
- // We want everything statically linked into `rustc_driver`, so remove `-C prefer-dynamic`
96
- if crate_name == Some ( "rustc_driver" ) && stage != "0" {
97
- // Remove `-C prefer-dynamic` to link `std` statically into `rustc_driver`
95
+ // When statically linking `std` into `rustc_driver`, remove `-C prefer-dynamic`
96
+ if env:: var ( "RUSTC_LINK_STD_INTO_RUSTC_DRIVER" ) . unwrap ( ) == "1"
97
+ && crate_name == Some ( "rustc_driver" )
98
+ && stage != "0"
99
+ {
98
100
if let Some ( pos) = args. iter ( ) . enumerate ( ) . position ( |( i, a) | {
99
101
a == "-C" && args. get ( i + 1 ) . map ( |a| a == "prefer-dynamic" ) . unwrap_or ( false )
100
102
} ) {
Original file line number Diff line number Diff line change @@ -1830,15 +1830,25 @@ impl Step for Assemble {
1830
1830
} )
1831
1831
. collect :: < HashSet < _ > > ( ) ;
1832
1832
1833
+ let link_std_into_rustc_driver = builder. link_std_into_rustc_driver ( target_compiler. host ) ;
1833
1834
let sysroot = builder. sysroot ( target_compiler) ;
1834
1835
let rustc_libdir = builder. rustc_libdir ( target_compiler) ;
1835
1836
t ! ( fs:: create_dir_all( & rustc_libdir) ) ;
1836
1837
let src_libdir = builder. sysroot_libdir ( build_compiler, host) ;
1837
1838
for f in builder. read_dir ( & src_libdir) {
1838
1839
let filename = f. file_name ( ) . into_string ( ) . unwrap ( ) ;
1840
+
1841
+ // For the later stages which gets distributed only copy over the
1842
+ // `rustc_driver` library so we don't end up with an extra copy of `std`.
1843
+ // If we're not statically linking `std` into `rustc_driver`, just copy every library
1844
+ // to ensure `std` is included.
1845
+ // We still need `std` for the initial stage as the bootstrap compiler may not
1846
+ // have the new `rustc_private` linking behavior.
1839
1847
let can_be_rustc_dep = filename. starts_with ( "rustc_driver-" )
1840
1848
|| filename. starts_with ( "librustc_driver-" )
1841
- || build_compiler. stage == 0 ;
1849
+ || build_compiler. stage == 0
1850
+ || !link_std_into_rustc_driver;
1851
+
1842
1852
if can_be_rustc_dep
1843
1853
&& ( is_dylib ( & filename) || is_debug_info ( & filename) )
1844
1854
&& !proc_macros. contains ( & filename)
Original file line number Diff line number Diff line change @@ -1106,6 +1106,12 @@ impl<'a> Builder<'a> {
1106
1106
StepDescription :: run ( v, self , paths) ;
1107
1107
}
1108
1108
1109
+ /// Returns if `std` should be statically linked into `rustc_driver`.
1110
+ /// It's currently not done on `windows-gnu` due to linker bugs.
1111
+ pub fn link_std_into_rustc_driver ( & self , target : TargetSelection ) -> bool {
1112
+ !target. triple . ends_with ( "-windows-gnu" )
1113
+ }
1114
+
1109
1115
/// Obtain a compiler at a given stage and for a given host (i.e., this is the target that the
1110
1116
/// compiler will run on, *not* the target it will build code for). Explicitly does not take
1111
1117
/// `Compiler` since all `Compiler` instances are meant to be obtained through this function,
@@ -2165,6 +2171,14 @@ impl<'a> Builder<'a> {
2165
2171
if matches ! ( mode, Mode :: Std ) {
2166
2172
rustflags. arg ( "-Cprefer-dynamic" ) ;
2167
2173
}
2174
+ if matches ! ( mode, Mode :: Rustc ) && !self . link_std_into_rustc_driver ( target) {
2175
+ rustflags. arg ( "-Cprefer-dynamic" ) ;
2176
+ }
2177
+
2178
+ cargo. env (
2179
+ "RUSTC_LINK_STD_INTO_RUSTC_DRIVER" ,
2180
+ if self . link_std_into_rustc_driver ( target) { "1" } else { "0" } ,
2181
+ ) ;
2168
2182
2169
2183
// When building incrementally we default to a lower ThinLTO import limit
2170
2184
// (unless explicitly specified otherwise). This will produce a somewhat
You can’t perform that action at this time.
0 commit comments