Skip to content

Commit 6737249

Browse files
authored
Unrolled build for rust-lang#125273
Rollup merge of rust-lang#125273 - onur-ozkan:bootstrap-self-test, r=albertlarsan68 bootstrap: implement new feature `bootstrap-self-test` Some of the bootstrap logics should be ignored during unit tests because they either make the tests take longer or cause them to fail. Therefore we need to be able to exclude them from the bootstrap when it's called by unit tests. This change introduces a new feature called `bootstrap-self-test`, which is enabled on bootstrap unit tests by default. This allows us to keep the logic separate between compiler builds and bootstrap tests without needing messy workarounds (like checking if target names match those in the unit tests). Also, resolves rust-lang#122090 (without having to create separate modules)
2 parents 5ee2dfd + 8f677e8 commit 6737249

File tree

6 files changed

+49
-38
lines changed

6 files changed

+49
-38
lines changed

src/bootstrap/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ default-run = "bootstrap"
77

88
[features]
99
build-metrics = ["sysinfo"]
10+
bootstrap-self-test = [] # enabled in the bootstrap unit tests
1011

1112
[lib]
1213
path = "src/lib.rs"

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

+1
Original file line numberDiff line numberDiff line change
@@ -3053,6 +3053,7 @@ impl Step for Bootstrap {
30533053

30543054
let mut cmd = Command::new(&builder.initial_cargo);
30553055
cmd.arg("test")
3056+
.args(["--features", "bootstrap-self-test"])
30563057
.current_dir(builder.src.join("src/bootstrap"))
30573058
.env("RUSTFLAGS", "-Cdebuginfo=2")
30583059
.env("CARGO_TARGET_DIR", builder.out.join("bootstrap"))

src/bootstrap/src/core/config/config.rs

+12-7
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@ use crate::utils::cache::{Interned, INTERNER};
2222
use crate::utils::channel::{self, GitInfo};
2323
use crate::utils::helpers::{exe, output, t};
2424
use build_helper::exit;
25-
use build_helper::util::fail;
26-
use semver::Version;
2725
use serde::{Deserialize, Deserializer};
2826
use serde_derive::Deserialize;
2927

@@ -2382,8 +2380,14 @@ impl Config {
23822380
}
23832381
}
23842382

2385-
// check rustc/cargo version is same or lower with 1 apart from the building one
2383+
#[cfg(feature = "bootstrap-self-test")]
2384+
pub fn check_stage0_version(&self, _program_path: &Path, _component_name: &'static str) {}
2385+
2386+
/// check rustc/cargo version is same or lower with 1 apart from the building one
2387+
#[cfg(not(feature = "bootstrap-self-test"))]
23862388
pub fn check_stage0_version(&self, program_path: &Path, component_name: &'static str) {
2389+
use build_helper::util::fail;
2390+
23872391
if self.dry_run() {
23882392
return;
23892393
}
@@ -2400,11 +2404,12 @@ impl Config {
24002404
}
24012405

24022406
let stage0_version =
2403-
Version::parse(stage0_output.next().unwrap().split('-').next().unwrap().trim())
2404-
.unwrap();
2405-
let source_version =
2406-
Version::parse(fs::read_to_string(self.src.join("src/version")).unwrap().trim())
2407+
semver::Version::parse(stage0_output.next().unwrap().split('-').next().unwrap().trim())
24072408
.unwrap();
2409+
let source_version = semver::Version::parse(
2410+
fs::read_to_string(self.src.join("src/version")).unwrap().trim(),
2411+
)
2412+
.unwrap();
24082413
if !(source_version == stage0_version
24092414
|| (source_version.major == stage0_version.major
24102415
&& (source_version.minor == stage0_version.minor

src/bootstrap/src/core/config/tests.rs

+5-23
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,9 @@ use std::{
1414
};
1515

1616
fn parse(config: &str) -> Config {
17-
Config::parse_inner(
18-
&[
19-
"check".to_string(),
20-
"--set=build.rustc=/does/not/exist".to_string(),
21-
"--set=build.cargo=/does/not/exist".to_string(),
22-
"--config=/does/not/exist".to_string(),
23-
"--skip-stage0-validation".to_string(),
24-
],
25-
|&_| toml::from_str(&config).unwrap(),
26-
)
17+
Config::parse_inner(&["check".to_string(), "--config=/does/not/exist".to_string()], |&_| {
18+
toml::from_str(&config).unwrap()
19+
})
2720
}
2821

2922
#[test]
@@ -212,10 +205,7 @@ fn override_toml_duplicate() {
212205
Config::parse_inner(
213206
&[
214207
"check".to_owned(),
215-
"--set=build.rustc=/does/not/exist".to_string(),
216-
"--set=build.cargo=/does/not/exist".to_string(),
217-
"--config=/does/not/exist".to_owned(),
218-
"--skip-stage0-validation".to_owned(),
208+
"--config=/does/not/exist".to_string(),
219209
"--set=change-id=1".to_owned(),
220210
"--set=change-id=2".to_owned(),
221211
],
@@ -238,15 +228,7 @@ fn profile_user_dist() {
238228
.and_then(|table: toml::Value| TomlConfig::deserialize(table))
239229
.unwrap()
240230
}
241-
Config::parse_inner(
242-
&[
243-
"check".to_owned(),
244-
"--set=build.rustc=/does/not/exist".to_string(),
245-
"--set=build.cargo=/does/not/exist".to_string(),
246-
"--skip-stage0-validation".to_string(),
247-
],
248-
get_toml,
249-
);
231+
Config::parse_inner(&["check".to_owned()], get_toml);
250232
}
251233

252234
#[test]

src/bootstrap/src/core/download.rs

+20-2
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,10 @@ use std::{
99
};
1010

1111
use build_helper::ci::CiEnv;
12-
use build_helper::stage0_parser::VersionMetadata;
1312
use xz2::bufread::XzDecoder;
1413

14+
use crate::utils::helpers::hex_encode;
1515
use crate::utils::helpers::{check_run, exe, move_file, program_out_of_date};
16-
use crate::{core::build_steps::llvm::detect_llvm_sha, utils::helpers::hex_encode};
1716
use crate::{t, Config};
1817

1918
static SHOULD_FIX_BINS_AND_DYLIBS: OnceLock<bool> = OnceLock::new();
@@ -405,9 +404,17 @@ impl Config {
405404
cargo_clippy
406405
}
407406

407+
#[cfg(feature = "bootstrap-self-test")]
408+
pub(crate) fn maybe_download_rustfmt(&self) -> Option<PathBuf> {
409+
None
410+
}
411+
408412
/// NOTE: rustfmt is a completely different toolchain than the bootstrap compiler, so it can't
409413
/// reuse target directories or artifacts
414+
#[cfg(not(feature = "bootstrap-self-test"))]
410415
pub(crate) fn maybe_download_rustfmt(&self) -> Option<PathBuf> {
416+
use build_helper::stage0_parser::VersionMetadata;
417+
411418
let VersionMetadata { date, version } = self.stage0_metadata.rustfmt.as_ref()?;
412419
let channel = format!("{version}-{date}");
413420

@@ -487,6 +494,10 @@ impl Config {
487494
);
488495
}
489496

497+
#[cfg(feature = "bootstrap-self-test")]
498+
pub(crate) fn download_beta_toolchain(&self) {}
499+
500+
#[cfg(not(feature = "bootstrap-self-test"))]
490501
pub(crate) fn download_beta_toolchain(&self) {
491502
self.verbose(|| println!("downloading stage0 beta artifacts"));
492503

@@ -665,7 +676,13 @@ download-rustc = false
665676
self.unpack(&tarball, &bin_root, prefix);
666677
}
667678

679+
#[cfg(feature = "bootstrap-self-test")]
680+
pub(crate) fn maybe_download_ci_llvm(&self) {}
681+
682+
#[cfg(not(feature = "bootstrap-self-test"))]
668683
pub(crate) fn maybe_download_ci_llvm(&self) {
684+
use crate::core::build_steps::llvm::detect_llvm_sha;
685+
669686
if !self.llvm_from_ci {
670687
return;
671688
}
@@ -707,6 +724,7 @@ download-rustc = false
707724
}
708725
}
709726

727+
#[cfg(not(feature = "bootstrap-self-test"))]
710728
fn download_ci_llvm(&self, llvm_sha: &str) {
711729
let llvm_assertions = self.llvm_assertions;
712730

src/bootstrap/src/core/sanity.rs

+10-6
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,15 @@
88
//! In theory if we get past this phase it's a bug if a build fails, but in
99
//! practice that's likely not true!
1010
11-
use std::collections::{HashMap, HashSet};
11+
use std::collections::HashMap;
1212
use std::env;
1313
use std::ffi::{OsStr, OsString};
1414
use std::fs;
1515
use std::path::PathBuf;
1616
use std::process::Command;
17-
use walkdir::WalkDir;
17+
18+
#[cfg(not(feature = "bootstrap-self-test"))]
19+
use std::collections::HashSet;
1820

1921
use crate::builder::Kind;
2022
use crate::core::config::Target;
@@ -31,6 +33,7 @@ pub struct Finder {
3133
// it might not yet be included in stage0. In such cases, we handle the targets missing from stage0 in this list.
3234
//
3335
// Targets can be removed from this list once they are present in the stage0 compiler (usually by updating the beta compiler of the bootstrap).
36+
#[cfg(not(feature = "bootstrap-self-test"))]
3437
const STAGE0_MISSING_TARGETS: &[&str] = &[
3538
// just a dummy comment so the list doesn't get onelined
3639
];
@@ -167,6 +170,7 @@ than building it.
167170
.map(|p| cmd_finder.must_have(p))
168171
.or_else(|| cmd_finder.maybe_have("reuse"));
169172

173+
#[cfg(not(feature = "bootstrap-self-test"))]
170174
let stage0_supported_target_list: HashSet<String> =
171175
output(Command::new(&build.config.initial_rustc).args(["--print", "target-list"]))
172176
.lines()
@@ -193,11 +197,11 @@ than building it.
193197
continue;
194198
}
195199

196-
let target_str = target.to_string();
197-
198200
// Ignore fake targets that are only used for unit tests in bootstrap.
199-
if !["A-A", "B-B", "C-C"].contains(&target_str.as_str()) {
201+
#[cfg(not(feature = "bootstrap-self-test"))]
202+
{
200203
let mut has_target = false;
204+
let target_str = target.to_string();
201205

202206
let missing_targets_hashset: HashSet<_> =
203207
STAGE0_MISSING_TARGETS.iter().map(|t| t.to_string()).collect();
@@ -226,7 +230,7 @@ than building it.
226230
target_filename.push(".json");
227231

228232
// Recursively traverse through nested directories.
229-
let walker = WalkDir::new(custom_target_path).into_iter();
233+
let walker = walkdir::WalkDir::new(custom_target_path).into_iter();
230234
for entry in walker.filter_map(|e| e.ok()) {
231235
has_target |= entry.file_name() == target_filename;
232236
}

0 commit comments

Comments
 (0)