@@ -88,12 +88,14 @@ impl HostFlags {
8888#[ derive( Debug ) ]
8989pub struct Cargo {
9090 command : BootstrapCommand ,
91+ args : Vec < OsString > ,
9192 compiler : Compiler ,
9293 target : TargetSelection ,
9394 rustflags : Rustflags ,
9495 rustdocflags : Rustflags ,
9596 hostflags : HostFlags ,
9697 allow_features : String ,
98+ release_build : bool ,
9799}
98100
99101impl Cargo {
@@ -121,6 +123,10 @@ impl Cargo {
121123 cargo
122124 }
123125
126+ pub fn release_build ( & mut self , release_build : bool ) {
127+ self . release_build = release_build;
128+ }
129+
124130 pub fn compiler ( & self ) -> Compiler {
125131 self . compiler
126132 }
@@ -153,7 +159,7 @@ impl Cargo {
153159 }
154160
155161 pub fn arg ( & mut self , arg : impl AsRef < OsStr > ) -> & mut Cargo {
156- self . command . arg ( arg. as_ref ( ) ) ;
162+ self . args . push ( arg. as_ref ( ) . into ( ) ) ;
157163 self
158164 }
159165
@@ -335,6 +341,12 @@ impl Cargo {
335341
336342impl From < Cargo > for BootstrapCommand {
337343 fn from ( mut cargo : Cargo ) -> BootstrapCommand {
344+ if cargo. release_build {
345+ cargo. args . insert ( 0 , "--release" . into ( ) ) ;
346+ }
347+
348+ cargo. command . args ( cargo. args ) ;
349+
338350 let rustflags = & cargo. rustflags . 0 ;
339351 if !rustflags. is_empty ( ) {
340352 cargo. command . env ( "RUSTFLAGS" , rustflags) ;
@@ -353,6 +365,7 @@ impl From<Cargo> for BootstrapCommand {
353365 if !cargo. allow_features . is_empty ( ) {
354366 cargo. command . env ( "RUSTC_ALLOW_FEATURES" , cargo. allow_features ) ;
355367 }
368+
356369 cargo. command
357370 }
358371}
@@ -422,13 +435,6 @@ impl Builder<'_> {
422435 assert_eq ! ( target, compiler. host) ;
423436 }
424437
425- if self . config . rust_optimize . is_release ( ) &&
426- // cargo bench/install do not accept `--release` and miri doesn't want it
427- !matches ! ( cmd_kind, Kind :: Bench | Kind :: Install | Kind :: Miri | Kind :: MiriSetup | Kind :: MiriTest )
428- {
429- cargo. arg ( "--release" ) ;
430- }
431-
432438 // Remove make-related flags to ensure Cargo can correctly set things up
433439 cargo. env_remove ( "MAKEFLAGS" ) ;
434440 cargo. env_remove ( "MFLAGS" ) ;
@@ -1214,14 +1220,20 @@ impl Builder<'_> {
12141220 rustflags. arg ( "-Zmir_strip_debuginfo=locals-in-tiny-functions" ) ;
12151221 }
12161222
1223+ let release_build = self . config . rust_optimize . is_release ( ) &&
1224+ // cargo bench/install do not accept `--release` and miri doesn't want it
1225+ !matches ! ( cmd_kind, Kind :: Bench | Kind :: Install | Kind :: Miri | Kind :: MiriSetup | Kind :: MiriTest ) ;
1226+
12171227 Cargo {
12181228 command : cargo,
1229+ args : vec ! [ ] ,
12191230 compiler,
12201231 target,
12211232 rustflags,
12221233 rustdocflags,
12231234 hostflags,
12241235 allow_features,
1236+ release_build,
12251237 }
12261238 }
12271239}
0 commit comments