diff --git a/.gitignore b/.gitignore index 3e010204655..12e779fe7c7 100644 --- a/.gitignore +++ b/.gitignore @@ -10,6 +10,7 @@ perf.data.old /build /build_sysroot/sysroot_src /build_sysroot/compiler-builtins +/build_sysroot/rustc_version /rust /rand /regex diff --git a/build_system/build_sysroot.rs b/build_system/build_sysroot.rs index 72d6a0265ef..e7946aa36ad 100644 --- a/build_system/build_sysroot.rs +++ b/build_system/build_sysroot.rs @@ -3,7 +3,7 @@ use std::fs; use std::path::Path; use std::process::{self, Command}; -use crate::rustc_info::get_file_name; +use crate::rustc_info::{get_file_name, get_rustc_version}; use crate::utils::{spawn_and_wait, try_hard_link}; use crate::SysrootKind; @@ -145,6 +145,24 @@ fn build_clif_sysroot_for_triple( triple: &str, linker: Option<&str>, ) { + match fs::read_to_string(Path::new("build_sysroot").join("rustc_version")) { + Err(e) => { + eprintln!("Failed to get rustc version for patched sysroot source: {}", e); + eprintln!("Hint: Try `./y.rs prepare` to patch the sysroot source"); + process::exit(1); + } + Ok(source_version) => { + let rustc_version = get_rustc_version(); + if source_version != rustc_version { + eprintln!("The patched sysroot source is outdated"); + eprintln!("Source version: {}", source_version.trim()); + eprintln!("Rustc version: {}", rustc_version.trim()); + eprintln!("Hint: Try `./y.rs prepare` to update the patched sysroot source"); + process::exit(1); + } + } + } + let build_dir = Path::new("build_sysroot").join("target").join(triple).join(channel); let keep_sysroot = diff --git a/build_system/prepare.rs b/build_system/prepare.rs index 1f4ec825e1e..401b8271abc 100644 --- a/build_system/prepare.rs +++ b/build_system/prepare.rs @@ -5,7 +5,7 @@ use std::fs; use std::path::Path; use std::process::Command; -use crate::rustc_info::{get_file_name, get_rustc_path}; +use crate::rustc_info::{get_file_name, get_rustc_path, get_rustc_version}; use crate::utils::{copy_dir_recursively, spawn_and_wait}; pub(crate) fn prepare() { @@ -59,6 +59,13 @@ fn prepare_sysroot() { eprintln!("[COPY] sysroot src"); copy_dir_recursively(&sysroot_src_orig.join("library"), &sysroot_src.join("library")); + let rustc_version = get_rustc_version(); + fs::write( + Path::new("build_sysroot").join("rustc_version"), + &rustc_version, + ) + .unwrap(); + eprintln!("[GIT] init"); let mut git_init_cmd = Command::new("git"); git_init_cmd.arg("init").arg("-q").current_dir(&sysroot_src); diff --git a/build_system/rustc_info.rs b/build_system/rustc_info.rs index 3bf86d9a114..9206bb02bd3 100644 --- a/build_system/rustc_info.rs +++ b/build_system/rustc_info.rs @@ -1,6 +1,12 @@ use std::path::{Path, PathBuf}; use std::process::{Command, Stdio}; +pub(crate) fn get_rustc_version() -> String { + let version_info = + Command::new("rustc").stderr(Stdio::inherit()).args(&["-V"]).output().unwrap().stdout; + String::from_utf8(version_info).unwrap() +} + pub(crate) fn get_host_triple() -> String { let version_info = Command::new("rustc").stderr(Stdio::inherit()).args(&["-vV"]).output().unwrap().stdout; diff --git a/clean_all.sh b/clean_all.sh index a7bbeb05cac..f4f8c82d69f 100755 --- a/clean_all.sh +++ b/clean_all.sh @@ -1,5 +1,6 @@ #!/usr/bin/env bash set -e -rm -rf target/ build/ build_sysroot/{sysroot_src/,target/,compiler-builtins/} perf.data{,.old} +rm -rf build_sysroot/{sysroot_src/,target/,compiler-builtins/,rustc_version} +rm -rf target/ build/ perf.data{,.old} rm -rf rand/ regex/ simple-raytracer/