Skip to content

Commit 69c7d82

Browse files
committed
Make sure the build.rustc version is either the same or 1 apart
1 parent 2e18605 commit 69c7d82

File tree

3 files changed

+42
-0
lines changed

3 files changed

+42
-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: 34 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,8 @@ impl Config {
10191020
config.download_beta_toolchain();
10201021
config.out.join(config.build.triple).join("stage0/bin/rustc")
10211022
});
1023+
config.check_build_rustc_version();
1024+
10221025
config.initial_cargo = build
10231026
.cargo
10241027
.map(|cargo| {
@@ -1680,6 +1683,37 @@ impl Config {
16801683
self.rust_codegen_backends.get(0).cloned()
16811684
}
16821685

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

0 commit comments

Comments
 (0)