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,31 @@ 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
+ args. insert ( 1 , "--release" . into ( ) ) ;
353
+
354
+ let mut new_command = Command :: new ( cargo. command . as_command_mut ( ) . get_program ( ) ) ;
355
+ new_command. args ( args) ;
356
+
357
+ if let Some ( p) = cargo. command . as_command_mut ( ) . get_current_dir ( ) {
358
+ new_command. current_dir ( p) ;
359
+ }
360
+
361
+ for ( key, value) in cargo. command . get_envs ( ) {
362
+ let Some ( value) = value else { continue } ;
363
+ new_command. env ( key, value) ;
364
+ }
365
+
366
+ cargo. command . replace_inner_command ( new_command) ;
367
+ }
368
+
338
369
let rustflags = & cargo. rustflags . 0 ;
339
370
if !rustflags. is_empty ( ) {
340
371
cargo. command . env ( "RUSTFLAGS" , rustflags) ;
@@ -353,6 +384,7 @@ impl From<Cargo> for BootstrapCommand {
353
384
if !cargo. allow_features . is_empty ( ) {
354
385
cargo. command . env ( "RUSTC_ALLOW_FEATURES" , cargo. allow_features ) ;
355
386
}
387
+
356
388
cargo. command
357
389
}
358
390
}
@@ -422,13 +454,6 @@ impl Builder<'_> {
422
454
assert_eq ! ( target, compiler. host) ;
423
455
}
424
456
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
457
// Remove make-related flags to ensure Cargo can correctly set things up
433
458
cargo. env_remove ( "MAKEFLAGS" ) ;
434
459
cargo. env_remove ( "MFLAGS" ) ;
@@ -1214,6 +1239,10 @@ impl Builder<'_> {
1214
1239
rustflags. arg ( "-Zmir_strip_debuginfo=locals-in-tiny-functions" ) ;
1215
1240
}
1216
1241
1242
+ let release_build = self . config . rust_optimize . is_release ( ) &&
1243
+ // cargo bench/install do not accept `--release` and miri doesn't want it
1244
+ !matches ! ( cmd_kind, Kind :: Bench | Kind :: Install | Kind :: Miri | Kind :: MiriSetup | Kind :: MiriTest ) ;
1245
+
1217
1246
Cargo {
1218
1247
command : cargo,
1219
1248
compiler,
@@ -1222,6 +1251,7 @@ impl Builder<'_> {
1222
1251
rustdocflags,
1223
1252
hostflags,
1224
1253
allow_features,
1254
+ release_build,
1225
1255
}
1226
1256
}
1227
1257
}
0 commit comments