1
1
use std:: env;
2
2
use std:: ffi:: { OsStr , OsString } ;
3
3
use std:: path:: { Path , PathBuf } ;
4
+ use std:: process:: Command ;
4
5
5
6
use super :: { Builder , Kind } ;
6
7
use crate :: core:: build_steps:: tool:: SourceType ;
@@ -94,6 +95,7 @@ pub struct Cargo {
94
95
rustdocflags : Rustflags ,
95
96
hostflags : HostFlags ,
96
97
allow_features : String ,
98
+ release_build : bool ,
97
99
}
98
100
99
101
impl Cargo {
@@ -121,6 +123,10 @@ impl Cargo {
121
123
cargo
122
124
}
123
125
126
+ pub fn release_build ( & mut self , release_build : bool ) {
127
+ self . release_build = release_build;
128
+ }
129
+
124
130
pub fn compiler ( & self ) -> Compiler {
125
131
self . compiler
126
132
}
@@ -335,6 +341,33 @@ impl Cargo {
335
341
336
342
impl From < Cargo > for BootstrapCommand {
337
343
fn from ( mut cargo : Cargo ) -> BootstrapCommand {
344
+ if cargo. release_build {
345
+ let mut args: Vec < String > = cargo
346
+ . command
347
+ . as_command_mut ( )
348
+ . get_args ( )
349
+ . map ( |arg| arg. to_str ( ) . unwrap ( ) . to_owned ( ) )
350
+ . collect ( ) ;
351
+
352
+ if !args. contains ( & "--release" . to_owned ( ) ) {
353
+ args. insert ( 1 , "--release" . into ( ) ) ;
354
+ }
355
+
356
+ let mut new_command = Command :: new ( cargo. command . as_command_mut ( ) . get_program ( ) ) ;
357
+ new_command. args ( args) ;
358
+
359
+ if let Some ( p) = cargo. command . as_command_mut ( ) . get_current_dir ( ) {
360
+ new_command. current_dir ( p) ;
361
+ }
362
+
363
+ for ( key, value) in cargo. command . get_envs ( ) {
364
+ let Some ( value) = value else { continue } ;
365
+ new_command. env ( key, value) ;
366
+ }
367
+
368
+ cargo. command . replace_inner_command ( new_command) ;
369
+ }
370
+
338
371
let rustflags = & cargo. rustflags . 0 ;
339
372
if !rustflags. is_empty ( ) {
340
373
cargo. command . env ( "RUSTFLAGS" , rustflags) ;
@@ -353,6 +386,7 @@ impl From<Cargo> for BootstrapCommand {
353
386
if !cargo. allow_features . is_empty ( ) {
354
387
cargo. command . env ( "RUSTC_ALLOW_FEATURES" , cargo. allow_features ) ;
355
388
}
389
+
356
390
cargo. command
357
391
}
358
392
}
@@ -422,13 +456,6 @@ impl Builder<'_> {
422
456
assert_eq ! ( target, compiler. host) ;
423
457
}
424
458
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
-
432
459
// Remove make-related flags to ensure Cargo can correctly set things up
433
460
cargo. env_remove ( "MAKEFLAGS" ) ;
434
461
cargo. env_remove ( "MFLAGS" ) ;
@@ -1214,6 +1241,10 @@ impl Builder<'_> {
1214
1241
rustflags. arg ( "-Zmir_strip_debuginfo=locals-in-tiny-functions" ) ;
1215
1242
}
1216
1243
1244
+ let release_build = self . config . rust_optimize . is_release ( ) &&
1245
+ // cargo bench/install do not accept `--release` and miri doesn't want it
1246
+ !matches ! ( cmd_kind, Kind :: Bench | Kind :: Install | Kind :: Miri | Kind :: MiriSetup | Kind :: MiriTest ) ;
1247
+
1217
1248
Cargo {
1218
1249
command : cargo,
1219
1250
compiler,
@@ -1222,6 +1253,7 @@ impl Builder<'_> {
1222
1253
rustdocflags,
1223
1254
hostflags,
1224
1255
allow_features,
1256
+ release_build,
1225
1257
}
1226
1258
}
1227
1259
}
0 commit comments