Skip to content

Commit 8bd44d7

Browse files
committed
override build profile for bootstrap tests
Signed-off-by: onur-ozkan <[email protected]>
1 parent 6365178 commit 8bd44d7

File tree

3 files changed

+50
-8
lines changed

3 files changed

+50
-8
lines changed

src/bootstrap/src/core/build_steps/test.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ impl Step for CrateBootstrap {
8686
SourceType::InTree,
8787
&[],
8888
);
89+
8990
let crate_name = path.rsplit_once('/').unwrap().1;
9091
run_cargo_test(cargo, &[], &[], crate_name, crate_name, bootstrap_host, builder);
9192
}
@@ -3099,6 +3100,8 @@ impl Step for Bootstrap {
30993100
&[],
31003101
);
31013102

3103+
cargo.release_build(false);
3104+
31023105
cargo
31033106
.rustflag("-Cdebuginfo=2")
31043107
.env("CARGO_TARGET_DIR", builder.out.join("bootstrap"))
@@ -3561,9 +3564,11 @@ impl Step for CodegenGCC {
35613564
.arg("gcc")
35623565
.arg("--out-dir")
35633566
.arg(builder.stage_out(compiler, Mode::ToolRustc).join("cg_gcc"))
3564-
.arg("--release")
35653567
.arg("--mini-tests")
35663568
.arg("--std-tests");
3569+
3570+
cargo.release_build(true);
3571+
35673572
cargo.args(builder.config.test_args());
35683573

35693574
cargo.into_cmd().run(builder);

src/bootstrap/src/core/builder/cargo.rs

Lines changed: 39 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use std::env;
22
use std::ffi::{OsStr, OsString};
33
use std::path::{Path, PathBuf};
4+
use std::process::Command;
45

56
use super::{Builder, Kind};
67
use crate::core::build_steps::tool::SourceType;
@@ -94,6 +95,7 @@ pub struct Cargo {
9495
rustdocflags: Rustflags,
9596
hostflags: HostFlags,
9697
allow_features: String,
98+
release_build: bool,
9799
}
98100

99101
impl 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
}
@@ -335,6 +341,33 @@ impl Cargo {
335341

336342
impl From<Cargo> for BootstrapCommand {
337343
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+
338371
let rustflags = &cargo.rustflags.0;
339372
if !rustflags.is_empty() {
340373
cargo.command.env("RUSTFLAGS", rustflags);
@@ -353,6 +386,7 @@ impl From<Cargo> for BootstrapCommand {
353386
if !cargo.allow_features.is_empty() {
354387
cargo.command.env("RUSTC_ALLOW_FEATURES", cargo.allow_features);
355388
}
389+
356390
cargo.command
357391
}
358392
}
@@ -422,13 +456,6 @@ impl Builder<'_> {
422456
assert_eq!(target, compiler.host);
423457
}
424458

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-
432459
// Remove make-related flags to ensure Cargo can correctly set things up
433460
cargo.env_remove("MAKEFLAGS");
434461
cargo.env_remove("MFLAGS");
@@ -1214,6 +1241,10 @@ impl Builder<'_> {
12141241
rustflags.arg("-Zmir_strip_debuginfo=locals-in-tiny-functions");
12151242
}
12161243

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+
12171248
Cargo {
12181249
command: cargo,
12191250
compiler,
@@ -1222,6 +1253,7 @@ impl Builder<'_> {
12221253
rustdocflags,
12231254
hostflags,
12241255
allow_features,
1256+
release_build,
12251257
}
12261258
}
12271259
}

src/bootstrap/src/utils/exec.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,11 @@ impl BootstrapCommand {
185185
self.env("TERM", "xterm").args(["--color", "always"]);
186186
}
187187
}
188+
189+
/// Replaces the wrapped `Command` instance inside
190+
pub fn replace_inner_command(&mut self, new_command: Command) {
191+
self.command = new_command;
192+
}
188193
}
189194

190195
impl Debug for BootstrapCommand {

0 commit comments

Comments
 (0)