Skip to content

Commit 9267843

Browse files
authored
Rollup merge of #111538 - chenyukang:yukang-fix-110067-version-issue, r=jyn514
Make sure the build.rustc version is either the same or 1 apart Fixes #110067 r? `@jyn514`
2 parents e52fbff + 5e2969e commit 9267843

File tree

4 files changed

+47
-0
lines changed

4 files changed

+47
-0
lines changed

src/bootstrap/Cargo.lock

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ dependencies = [
5858
"once_cell",
5959
"opener",
6060
"pretty_assertions",
61+
"semver",
6162
"serde",
6263
"serde_derive",
6364
"serde_json",
@@ -645,6 +646,12 @@ version = "1.1.0"
645646
source = "registry+https://github.com/rust-lang/crates.io-index"
646647
checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd"
647648

649+
[[package]]
650+
name = "semver"
651+
version = "1.0.17"
652+
source = "registry+https://github.com/rust-lang/crates.io-index"
653+
checksum = "bebd363326d05ec3e2f532ab7660680f3b02130d780c299bca73469d521bc0ed"
654+
648655
[[package]]
649656
name = "serde"
650657
version = "1.0.137"

src/bootstrap/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ walkdir = "2"
5757
sysinfo = { version = "0.26.0", optional = true }
5858
clap = { version = "4.2.4", default-features = false, features = ["std", "usage", "help", "derive", "error-context"] }
5959
clap_complete = "4.2.2"
60+
semver = "1.0.17"
6061

6162
# Solaris doesn't support flock() and thus fd-lock is not option now
6263
[target.'cfg(not(target_os = "solaris"))'.dependencies]

src/bootstrap/config.rs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ pub use crate::flags::Subcommand;
2424
use crate::flags::{Color, Flags, Warnings};
2525
use crate::util::{exe, output, t};
2626
use once_cell::sync::OnceCell;
27+
use semver::Version;
2728
use serde::{Deserialize, Deserializer};
2829
use serde_derive::Deserialize;
2930

@@ -1019,6 +1020,7 @@ impl Config {
10191020
config.download_beta_toolchain();
10201021
config.out.join(config.build.triple).join("stage0/bin/rustc")
10211022
});
1023+
10221024
config.initial_cargo = build
10231025
.cargo
10241026
.map(|cargo| {
@@ -1680,6 +1682,42 @@ impl Config {
16801682
self.rust_codegen_backends.get(0).cloned()
16811683
}
16821684

1685+
pub fn check_build_rustc_version(&self) {
1686+
if self.dry_run() {
1687+
return;
1688+
}
1689+
1690+
// check rustc version is same or lower with 1 apart from the building one
1691+
let mut cmd = Command::new(&self.initial_rustc);
1692+
cmd.arg("--version");
1693+
let rustc_output = output(&mut cmd)
1694+
.lines()
1695+
.next()
1696+
.unwrap()
1697+
.split(' ')
1698+
.nth(1)
1699+
.unwrap()
1700+
.split('-')
1701+
.next()
1702+
.unwrap()
1703+
.to_owned();
1704+
let rustc_version = Version::parse(&rustc_output.trim()).unwrap();
1705+
let source_version =
1706+
Version::parse(&fs::read_to_string(self.src.join("src/version")).unwrap().trim())
1707+
.unwrap();
1708+
if !(source_version == rustc_version
1709+
|| (source_version.major == rustc_version.major
1710+
&& source_version.minor == rustc_version.minor + 1))
1711+
{
1712+
let prev_version = format!("{}.{}.x", source_version.major, source_version.minor - 1);
1713+
eprintln!(
1714+
"Unexpected rustc version: {}, we should use {}/{} to build source with {}",
1715+
rustc_version, prev_version, source_version, source_version
1716+
);
1717+
crate::detail_exit(1);
1718+
}
1719+
}
1720+
16831721
/// Returns the commit to download, or `None` if we shouldn't download CI artifacts.
16841722
fn download_ci_rustc_commit(&self, download_rustc: Option<StringOrBool>) -> Option<String> {
16851723
// If `download-rustc` is not set, default to rebuilding.

src/bootstrap/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -414,6 +414,7 @@ impl Build {
414414
bootstrap_out.display()
415415
)
416416
}
417+
config.check_build_rustc_version();
417418

418419
if rust_info.is_from_tarball() && config.description.is_none() {
419420
config.description = Some("built from a source tarball".to_owned());

0 commit comments

Comments
 (0)