@@ -116,7 +116,7 @@ impl Cargo {
116116 // as they don't invoke rustc at all.
117117 Kind :: Clean | Kind :: Suggest | Kind :: Format | Kind :: Setup => { }
118118 _ => {
119- cargo. configure_linker ( builder) ;
119+ cargo. configure_linker ( builder, mode ) ;
120120 }
121121 }
122122
@@ -205,7 +205,7 @@ impl Cargo {
205205 self
206206 }
207207
208- fn configure_linker ( & mut self , builder : & Builder < ' _ > ) -> & mut Cargo {
208+ fn configure_linker ( & mut self , builder : & Builder < ' _ > , mode : Mode ) -> & mut Cargo {
209209 let target = self . target ;
210210 let compiler = self . compiler ;
211211
@@ -260,7 +260,15 @@ impl Cargo {
260260 }
261261 }
262262
263- for arg in linker_args ( builder, compiler. host , LldThreads :: Yes ) {
263+ // When determining flags for the host (build scripts/proc macros),
264+ // we use the snapshot compiler when building `Mode::Std` tools, and
265+ // the current compiler when building anything else.
266+ // We need to determine the current stage here to pass proper linker args (e.g. -C vs -Z)
267+ // to the compiler used to compile build scripts.
268+ // This should stay synchronized with the [cargo] function.
269+ let host_stage = if mode == Mode :: Std { 0 } else { compiler. stage } ;
270+
271+ for arg in linker_args ( builder, compiler. host , LldThreads :: Yes , host_stage) {
264272 self . hostflags . arg ( & arg) ;
265273 }
266274
@@ -270,10 +278,10 @@ impl Cargo {
270278 }
271279 // We want to set -Clinker using Cargo, therefore we only call `linker_flags` and not
272280 // `linker_args` here.
273- for flag in linker_flags ( builder, target, LldThreads :: Yes ) {
281+ for flag in linker_flags ( builder, target, LldThreads :: Yes , compiler . stage ) {
274282 self . rustflags . arg ( & flag) ;
275283 }
276- for arg in linker_args ( builder, target, LldThreads :: Yes ) {
284+ for arg in linker_args ( builder, target, LldThreads :: Yes , compiler . stage ) {
277285 self . rustdocflags . arg ( & arg) ;
278286 }
279287
0 commit comments