@@ -1265,6 +1265,8 @@ impl<'a> Builder<'a> {
1265
1265
let mut cargo = self . bare_cargo ( compiler, mode, target, cmd) ;
1266
1266
let out_dir = self . stage_out ( compiler, mode) ;
1267
1267
1268
+ let mut hostflags = HostFlags :: default ( ) ;
1269
+
1268
1270
// Codegen backends are not yet tracked by -Zbinary-dep-depinfo,
1269
1271
// so we need to explicitly clear out if they've been updated.
1270
1272
for backend in self . codegen_backends ( compiler) {
@@ -1652,10 +1654,10 @@ impl<'a> Builder<'a> {
1652
1654
}
1653
1655
1654
1656
if let Some ( host_linker) = self . linker ( compiler. host ) {
1655
- cargo . env ( "RUSTC_HOST_LINKER ", host_linker) ;
1657
+ hostflags . flag ( format ! ( "-Clinker={} ", host_linker. display ( ) ) ) ;
1656
1658
}
1657
1659
if self . is_fuse_ld_lld ( compiler. host ) {
1658
- cargo . env ( "RUSTC_HOST_FUSE_LD_LLD" , "1 ") ;
1660
+ hostflags . flag ( "-Clink-args=-fuse-ld=lld ") ;
1659
1661
}
1660
1662
1661
1663
if let Some ( target_linker) = self . linker ( target) {
@@ -1739,7 +1741,8 @@ impl<'a> Builder<'a> {
1739
1741
}
1740
1742
1741
1743
if let Some ( x) = self . crt_static ( compiler. host ) {
1742
- cargo. env ( "RUSTC_HOST_CRT_STATIC" , x. to_string ( ) ) ;
1744
+ let sign = if x { "+" } else { "-" } ;
1745
+ hostflags. flag ( format ! ( "-Ctarget-feature={sign}crt-static" ) ) ;
1743
1746
}
1744
1747
1745
1748
if let Some ( map_to) = self . build . debuginfo_map_to ( GitRepo :: Rustc ) {
@@ -2051,7 +2054,7 @@ impl<'a> Builder<'a> {
2051
2054
cargo. env ( "RUSTFLAGS" , & rustc_args. join ( " " ) ) ;
2052
2055
}
2053
2056
2054
- Cargo { command : cargo, rustflags, rustdocflags, allow_features }
2057
+ Cargo { command : cargo, rustflags, rustdocflags, hostflags , allow_features }
2055
2058
}
2056
2059
2057
2060
/// Ensure that a given step is built, returning its output. This will
@@ -2229,11 +2232,27 @@ impl Rustflags {
2229
2232
}
2230
2233
}
2231
2234
2235
+ /// Flags that are passed to the `rustc` and `rustdoc` shim binaries.
2236
+ /// These flags will only be applied when compiling host code, i.e. when
2237
+ /// `--target` is unset.
2238
+ #[ derive( Debug , Default ) ]
2239
+ pub struct HostFlags {
2240
+ rustc : Vec < String > ,
2241
+ }
2242
+
2243
+ impl HostFlags {
2244
+ /// Adds a host rustc flag.
2245
+ fn flag < S : Into < String > > ( & mut self , flag : S ) {
2246
+ self . rustc . push ( flag. into ( ) ) ;
2247
+ }
2248
+ }
2249
+
2232
2250
#[ derive( Debug ) ]
2233
2251
pub struct Cargo {
2234
2252
command : Command ,
2235
2253
rustflags : Rustflags ,
2236
2254
rustdocflags : Rustflags ,
2255
+ hostflags : HostFlags ,
2237
2256
allow_features : String ,
2238
2257
}
2239
2258
@@ -2305,6 +2324,11 @@ impl From<Cargo> for Command {
2305
2324
cargo. command . env ( "RUSTDOCFLAGS" , rustdocflags) ;
2306
2325
}
2307
2326
2327
+ let hostflags = cargo. hostflags ;
2328
+ for ( index, flag) in hostflags. rustc . into_iter ( ) . enumerate ( ) {
2329
+ cargo. command . env ( format ! ( "RUSTC_HOST_CMD_{index}" ) , flag) ;
2330
+ }
2331
+
2308
2332
if !cargo. allow_features . is_empty ( ) {
2309
2333
cargo. command . env ( "RUSTC_ALLOW_FEATURES" , cargo. allow_features ) ;
2310
2334
}
0 commit comments