Skip to content

Commit e5778f0

Browse files
committed
override build profile for bootstrap tests
Signed-off-by: onur-ozkan <work@onurozkan.dev>
1 parent 6365178 commit e5778f0

File tree

3 files changed

+45
-7
lines changed

3 files changed

+45
-7
lines changed

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

+3
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"))

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

+37-7
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,31 @@ 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+
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+
338369
let rustflags = &cargo.rustflags.0;
339370
if !rustflags.is_empty() {
340371
cargo.command.env("RUSTFLAGS", rustflags);
@@ -353,6 +384,7 @@ impl From<Cargo> for BootstrapCommand {
353384
if !cargo.allow_features.is_empty() {
354385
cargo.command.env("RUSTC_ALLOW_FEATURES", cargo.allow_features);
355386
}
387+
356388
cargo.command
357389
}
358390
}
@@ -422,13 +454,6 @@ impl Builder<'_> {
422454
assert_eq!(target, compiler.host);
423455
}
424456

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-
432457
// Remove make-related flags to ensure Cargo can correctly set things up
433458
cargo.env_remove("MAKEFLAGS");
434459
cargo.env_remove("MFLAGS");
@@ -1214,6 +1239,10 @@ impl Builder<'_> {
12141239
rustflags.arg("-Zmir_strip_debuginfo=locals-in-tiny-functions");
12151240
}
12161241

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+
12171246
Cargo {
12181247
command: cargo,
12191248
compiler,
@@ -1222,6 +1251,7 @@ impl Builder<'_> {
12221251
rustdocflags,
12231252
hostflags,
12241253
allow_features,
1254+
release_build,
12251255
}
12261256
}
12271257
}

src/bootstrap/src/utils/exec.rs

+5
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)