Skip to content

Commit d4f87d1

Browse files
authored
Rollup merge of #112231 - chenyukang:yukang-fix-110067-version-issue, r=jyn514
Make sure the build.rustc version is either the same or 1 apart (revised) #111538 is reverted in #112023. This PR will only check `build.rustc` to confirm the correct version.
2 parents 20cbbbb + bff5ecd commit d4f87d1

File tree

3 files changed

+51
-2
lines changed

3 files changed

+51
-2
lines changed

Diff for: src/bootstrap/Cargo.lock

+7
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.160"

Diff for: src/bootstrap/Cargo.toml

+1
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]

Diff for: src/bootstrap/config.rs

+43-2
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ use crate::flags::{Color, Flags, Warnings};
2525
use crate::util::{exe, output, t};
2626
use build_helper::detail_exit_macro;
2727
use once_cell::sync::OnceCell;
28+
use semver::Version;
2829
use serde::{Deserialize, Deserializer};
2930
use serde_derive::Deserialize;
3031

@@ -1114,10 +1115,14 @@ impl Config {
11141115
config.out = crate::util::absolute(&config.out);
11151116
}
11161117

1117-
config.initial_rustc = build.rustc.map(PathBuf::from).unwrap_or_else(|| {
1118+
config.initial_rustc = if let Some(rustc) = build.rustc {
1119+
config.check_build_rustc_version(&rustc);
1120+
PathBuf::from(rustc)
1121+
} else {
11181122
config.download_beta_toolchain();
11191123
config.out.join(config.build.triple).join("stage0/bin/rustc")
1120-
});
1124+
};
1125+
11211126
config.initial_cargo = build
11221127
.cargo
11231128
.map(|cargo| {
@@ -1779,6 +1784,42 @@ impl Config {
17791784
self.rust_codegen_backends.get(0).cloned()
17801785
}
17811786

1787+
pub fn check_build_rustc_version(&self, rustc_path: &str) {
1788+
if self.dry_run() {
1789+
return;
1790+
}
1791+
1792+
// check rustc version is same or lower with 1 apart from the building one
1793+
let mut cmd = Command::new(rustc_path);
1794+
cmd.arg("--version");
1795+
let rustc_output = output(&mut cmd)
1796+
.lines()
1797+
.next()
1798+
.unwrap()
1799+
.split(' ')
1800+
.nth(1)
1801+
.unwrap()
1802+
.split('-')
1803+
.next()
1804+
.unwrap()
1805+
.to_owned();
1806+
let rustc_version = Version::parse(&rustc_output.trim()).unwrap();
1807+
let source_version =
1808+
Version::parse(&fs::read_to_string(self.src.join("src/version")).unwrap().trim())
1809+
.unwrap();
1810+
if !(source_version == rustc_version
1811+
|| (source_version.major == rustc_version.major
1812+
&& source_version.minor == rustc_version.minor + 1))
1813+
{
1814+
let prev_version = format!("{}.{}.x", source_version.major, source_version.minor - 1);
1815+
eprintln!(
1816+
"Unexpected rustc version: {}, we should use {}/{} to build source with {}",
1817+
rustc_version, prev_version, source_version, source_version
1818+
);
1819+
detail_exit_macro!(1);
1820+
}
1821+
}
1822+
17821823
/// Returns the commit to download, or `None` if we shouldn't download CI artifacts.
17831824
fn download_ci_rustc_commit(&self, download_rustc: Option<StringOrBool>) -> Option<String> {
17841825
// If `download-rustc` is not set, default to rebuilding.

0 commit comments

Comments
 (0)