From 69c7d82f42eb91354dbbe83ce4ffed63c8e65ee7 Mon Sep 17 00:00:00 2001 From: yukang Date: Sun, 14 May 2023 01:03:37 +0800 Subject: [PATCH 1/4] Make sure the build.rustc version is either the same or 1 apart --- src/bootstrap/Cargo.lock | 7 +++++++ src/bootstrap/Cargo.toml | 1 + src/bootstrap/config.rs | 34 ++++++++++++++++++++++++++++++++++ 3 files changed, 42 insertions(+) diff --git a/src/bootstrap/Cargo.lock b/src/bootstrap/Cargo.lock index e13157a11ae..9420c4fec5f 100644 --- a/src/bootstrap/Cargo.lock +++ b/src/bootstrap/Cargo.lock @@ -58,6 +58,7 @@ dependencies = [ "once_cell", "opener", "pretty_assertions", + "semver", "serde", "serde_derive", "serde_json", @@ -645,6 +646,12 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" +[[package]] +name = "semver" +version = "1.0.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bebd363326d05ec3e2f532ab7660680f3b02130d780c299bca73469d521bc0ed" + [[package]] name = "serde" version = "1.0.137" diff --git a/src/bootstrap/Cargo.toml b/src/bootstrap/Cargo.toml index 55675a2315c..746c8dcfce0 100644 --- a/src/bootstrap/Cargo.toml +++ b/src/bootstrap/Cargo.toml @@ -57,6 +57,7 @@ walkdir = "2" sysinfo = { version = "0.26.0", optional = true } clap = { version = "4.2.4", default-features = false, features = ["std", "usage", "help", "derive", "error-context"] } clap_complete = "4.2.2" +semver = "1.0.17" # Solaris doesn't support flock() and thus fd-lock is not option now [target.'cfg(not(target_os = "solaris"))'.dependencies] diff --git a/src/bootstrap/config.rs b/src/bootstrap/config.rs index bf3bc3247ac..2828ebc3567 100644 --- a/src/bootstrap/config.rs +++ b/src/bootstrap/config.rs @@ -24,6 +24,7 @@ use crate::flags::{Color, Flags, Warnings}; use crate::util::{exe, output, t}; use once_cell::sync::OnceCell; +use semver::Version; use serde::{Deserialize, Deserializer}; use serde_derive::Deserialize; @@ -1019,6 +1020,8 @@ fn parse_inner<'a>(args: &[String], get_toml: impl 'a + Fn(&Path) -> TomlConfig) config.download_beta_toolchain(); config.out.join(config.build.triple).join("stage0/bin/rustc") }); + config.check_build_rustc_version(); + config.initial_cargo = build .cargo .map(|cargo| { @@ -1680,6 +1683,37 @@ pub fn default_codegen_backend(&self) -> Option> { self.rust_codegen_backends.get(0).cloned() } + fn check_build_rustc_version(&self) { + // check rustc version is same or lower with 1 apart from the building one + let mut cmd = Command::new(&self.initial_rustc); + cmd.arg("--version"); + let rustc_output = output(&mut cmd) + .lines() + .next() + .unwrap() + .split(' ') + .nth(1) + .unwrap() + .split('-') + .next() + .unwrap() + .to_owned(); + let rustc_version = Version::parse(&rustc_output.trim()).unwrap(); + let source_version = + Version::parse(&fs::read_to_string(self.src.join("src/version")).unwrap().trim()) + .unwrap(); + if !(source_version == rustc_version + || (source_version.major == rustc_version.major + && source_version.minor == rustc_version.minor + 1)) + { + let prev_version = format!("{}.{}.x", source_version.major, source_version.minor - 1); + panic!( + "Unexpected rustc version: {}, we should use {}/{} to build source with {}", + rustc_version, prev_version, source_version, source_version + ); + } + } + /// Returns the commit to download, or `None` if we shouldn't download CI artifacts. fn download_ci_rustc_commit(&self, download_rustc: Option) -> Option { // If `download-rustc` is not set, default to rebuilding. From 3c1c2c03fc194fc5a22c9b29aca560167ba0fdc7 Mon Sep 17 00:00:00 2001 From: yukang Date: Sun, 14 May 2023 08:02:21 +0800 Subject: [PATCH 2/4] skip rustc version check in dry_run --- src/bootstrap/config.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/bootstrap/config.rs b/src/bootstrap/config.rs index 2828ebc3567..23543938999 100644 --- a/src/bootstrap/config.rs +++ b/src/bootstrap/config.rs @@ -1684,6 +1684,10 @@ pub fn default_codegen_backend(&self) -> Option> { } fn check_build_rustc_version(&self) { + if self.dry_run() { + return; + } + // check rustc version is same or lower with 1 apart from the building one let mut cmd = Command::new(&self.initial_rustc); cmd.arg("--version"); From 46489040e6e83d9603cec646219a640338de7056 Mon Sep 17 00:00:00 2001 From: yukang Date: Sun, 14 May 2023 12:43:08 +0800 Subject: [PATCH 3/4] fix --- src/bootstrap/config.rs | 3 +-- src/bootstrap/lib.rs | 1 + 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/bootstrap/config.rs b/src/bootstrap/config.rs index 23543938999..3694c51d194 100644 --- a/src/bootstrap/config.rs +++ b/src/bootstrap/config.rs @@ -1020,7 +1020,6 @@ fn parse_inner<'a>(args: &[String], get_toml: impl 'a + Fn(&Path) -> TomlConfig) config.download_beta_toolchain(); config.out.join(config.build.triple).join("stage0/bin/rustc") }); - config.check_build_rustc_version(); config.initial_cargo = build .cargo @@ -1683,7 +1682,7 @@ pub fn default_codegen_backend(&self) -> Option> { self.rust_codegen_backends.get(0).cloned() } - fn check_build_rustc_version(&self) { + pub fn check_build_rustc_version(&self) { if self.dry_run() { return; } diff --git a/src/bootstrap/lib.rs b/src/bootstrap/lib.rs index 994336977dc..3756976dee0 100644 --- a/src/bootstrap/lib.rs +++ b/src/bootstrap/lib.rs @@ -414,6 +414,7 @@ pub fn new(mut config: Config) -> Build { bootstrap_out.display() ) } + config.check_build_rustc_version(); if rust_info.is_from_tarball() && config.description.is_none() { config.description = Some("built from a source tarball".to_owned()); From 5e2969e7d5b98717bf681b3f0ab30ffd3595395a Mon Sep 17 00:00:00 2001 From: yukang Date: Sun, 14 May 2023 17:41:53 +0800 Subject: [PATCH 4/4] comment feedback --- src/bootstrap/config.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/bootstrap/config.rs b/src/bootstrap/config.rs index 3694c51d194..710c8b52194 100644 --- a/src/bootstrap/config.rs +++ b/src/bootstrap/config.rs @@ -1710,10 +1710,11 @@ pub fn check_build_rustc_version(&self) { && source_version.minor == rustc_version.minor + 1)) { let prev_version = format!("{}.{}.x", source_version.major, source_version.minor - 1); - panic!( + eprintln!( "Unexpected rustc version: {}, we should use {}/{} to build source with {}", rustc_version, prev_version, source_version, source_version ); + crate::detail_exit(1); } }