Skip to content

Commit 55e0779

Browse files
committed
Check if the patched sysroot source is up to date before using it
Fixes rust-lang#1181
1 parent 4c440af commit 55e0779

File tree

5 files changed

+36
-3
lines changed

5 files changed

+36
-3
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ perf.data.old
1010
/build
1111
/build_sysroot/sysroot_src
1212
/build_sysroot/compiler-builtins
13+
/build_sysroot/rustc_version
1314
/rust
1415
/rand
1516
/regex

build_system/build_sysroot.rs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use std::fs;
33
use std::path::Path;
44
use std::process::{self, Command};
55

6-
use crate::rustc_info::get_file_name;
6+
use crate::rustc_info::{get_file_name, get_rustc_version};
77
use crate::utils::{spawn_and_wait, try_hard_link};
88
use crate::SysrootKind;
99

@@ -145,6 +145,24 @@ fn build_clif_sysroot_for_triple(
145145
triple: &str,
146146
linker: Option<&str>,
147147
) {
148+
match fs::read_to_string(Path::new("build_sysroot").join("rustc_version")) {
149+
Err(e) => {
150+
eprintln!("Failed to get rustc version for patched sysroot source: {}", e);
151+
eprintln!("Hint: Try `./y.rs prepare` to patch the sysroot source");
152+
process::exit(1);
153+
}
154+
Ok(source_version) => {
155+
let rustc_version = get_rustc_version();
156+
if source_version != rustc_version {
157+
eprintln!("The patched sysroot source is outdated");
158+
eprintln!("Source version: {}", source_version.trim());
159+
eprintln!("Rustc version: {}", rustc_version.trim());
160+
eprintln!("Hint: Try `./y.rs prepare` to update the patched sysroot source");
161+
process::exit(1);
162+
}
163+
}
164+
}
165+
148166
let build_dir = Path::new("build_sysroot").join("target").join(triple).join(channel);
149167

150168
let keep_sysroot =

build_system/prepare.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use std::fs;
55
use std::path::Path;
66
use std::process::Command;
77

8-
use crate::rustc_info::{get_file_name, get_rustc_path};
8+
use crate::rustc_info::{get_file_name, get_rustc_path, get_rustc_version};
99
use crate::utils::{copy_dir_recursively, spawn_and_wait};
1010

1111
pub(crate) fn prepare() {
@@ -59,6 +59,13 @@ fn prepare_sysroot() {
5959
eprintln!("[COPY] sysroot src");
6060
copy_dir_recursively(&sysroot_src_orig.join("library"), &sysroot_src.join("library"));
6161

62+
let rustc_version = get_rustc_version();
63+
fs::write(
64+
Path::new("build_sysroot").join("rustc_version"),
65+
&rustc_version,
66+
)
67+
.unwrap();
68+
6269
eprintln!("[GIT] init");
6370
let mut git_init_cmd = Command::new("git");
6471
git_init_cmd.arg("init").arg("-q").current_dir(&sysroot_src);

build_system/rustc_info.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
use std::path::{Path, PathBuf};
22
use std::process::{Command, Stdio};
33

4+
pub(crate) fn get_rustc_version() -> String {
5+
let version_info =
6+
Command::new("rustc").stderr(Stdio::inherit()).args(&["-V"]).output().unwrap().stdout;
7+
String::from_utf8(version_info).unwrap()
8+
}
9+
410
pub(crate) fn get_host_triple() -> String {
511
let version_info =
612
Command::new("rustc").stderr(Stdio::inherit()).args(&["-vV"]).output().unwrap().stdout;

clean_all.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#!/usr/bin/env bash
22
set -e
33

4-
rm -rf target/ build/ build_sysroot/{sysroot_src/,target/,compiler-builtins/} perf.data{,.old}
4+
rm -rf build_sysroot/{sysroot_src/,target/,compiler-builtins/,rustc_version}
5+
rm -rf target/ build/ perf.data{,.old}
56
rm -rf rand/ regex/ simple-raytracer/

0 commit comments

Comments
 (0)