Skip to content

Commit 8a3fb55

Browse files
committed
Lazily patch the standard library
1 parent 1850b36 commit 8a3fb55

File tree

4 files changed

+26
-44
lines changed

4 files changed

+26
-44
lines changed

build_system/build_sysroot.rs

+6-21
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
use std::fs;
22
use std::path::{Path, PathBuf};
3-
use std::process::{self, Command};
3+
use std::process::Command;
44

55
use super::path::{Dirs, RelPath};
6-
use super::rustc_info::{get_file_name, get_rustc_version};
6+
use super::rustc_info::get_file_name;
77
use super::utils::{
88
maybe_incremental, remove_dir_if_exists, spawn_and_wait, try_hard_link, CargoProject, Compiler,
99
};
@@ -158,7 +158,6 @@ impl SysrootTarget {
158158
}
159159

160160
pub(crate) static STDLIB_SRC: RelPath = RelPath::BUILD.join("stdlib");
161-
pub(crate) static SYSROOT_RUSTC_VERSION: RelPath = STDLIB_SRC.join("rustc_version");
162161
pub(crate) static STANDARD_LIBRARY: CargoProject =
163162
CargoProject::new(&STDLIB_SRC.join("library/sysroot"), "stdlib_target");
164163
pub(crate) static RTSTARTUP_SYSROOT: RelPath = RelPath::BUILD.join("rtstartup");
@@ -222,24 +221,6 @@ fn build_clif_sysroot_for_triple(
222221
mut compiler: Compiler,
223222
cg_clif_dylib_path: &CodegenBackend,
224223
) -> SysrootTarget {
225-
match fs::read_to_string(SYSROOT_RUSTC_VERSION.to_path(dirs)) {
226-
Err(e) => {
227-
eprintln!("Failed to get rustc version for patched sysroot source: {}", e);
228-
eprintln!("Hint: Try `./y.sh prepare` to patch the sysroot source");
229-
process::exit(1);
230-
}
231-
Ok(source_version) => {
232-
let rustc_version = get_rustc_version(&compiler.rustc);
233-
if source_version != rustc_version {
234-
eprintln!("The patched sysroot source is outdated");
235-
eprintln!("Source version: {}", source_version.trim());
236-
eprintln!("Rustc version: {}", rustc_version.trim());
237-
eprintln!("Hint: Try `./y.sh prepare` to update the patched sysroot source");
238-
process::exit(1);
239-
}
240-
}
241-
}
242-
243224
let mut target_libs = SysrootTarget { triple: compiler.triple.clone(), libs: vec![] };
244225

245226
if let Some(rtstartup_target_libs) = build_rtstartup(dirs, &compiler) {
@@ -302,6 +283,10 @@ fn build_clif_sysroot_for_triple(
302283
}
303284

304285
fn build_rtstartup(dirs: &Dirs, compiler: &Compiler) -> Option<SysrootTarget> {
286+
if !super::config::get_bool("keep_sysroot") {
287+
super::prepare::prepare_stdlib(dirs, &compiler.rustc);
288+
}
289+
305290
if !compiler.triple.ends_with("windows-gnu") {
306291
return None;
307292
}

build_system/main.rs

+16-7
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,22 @@ fn main() {
126126
}
127127
}
128128

129+
let current_dir = std::env::current_dir().unwrap();
130+
out_dir = current_dir.join(out_dir);
131+
132+
if command == Command::Prepare {
133+
prepare::prepare(&path::Dirs {
134+
source_dir: current_dir.clone(),
135+
download_dir: download_dir
136+
.map(|dir| current_dir.join(dir))
137+
.unwrap_or_else(|| out_dir.join("download")),
138+
build_dir: PathBuf::from("dummy_do_not_use"),
139+
dist_dir: PathBuf::from("dummy_do_not_use"),
140+
frozen,
141+
});
142+
process::exit(0);
143+
}
144+
129145
let rustup_toolchain_name = match (env::var("CARGO"), env::var("RUSTC"), env::var("RUSTDOC")) {
130146
(Ok(_), Ok(_), Ok(_)) => None,
131147
(Err(_), Err(_), Err(_)) => Some(rustc_info::get_toolchain_name()),
@@ -158,8 +174,6 @@ fn main() {
158174
.unwrap_or_else(|| bootstrap_host_compiler.triple.clone());
159175

160176
// FIXME allow changing the location of these dirs using cli arguments
161-
let current_dir = std::env::current_dir().unwrap();
162-
out_dir = current_dir.join(out_dir);
163177
let dirs = path::Dirs {
164178
source_dir: current_dir.clone(),
165179
download_dir: download_dir
@@ -181,11 +195,6 @@ fn main() {
181195
std::fs::File::create(target).unwrap();
182196
}
183197

184-
if command == Command::Prepare {
185-
prepare::prepare(&dirs, &bootstrap_host_compiler.rustc);
186-
process::exit(0);
187-
}
188-
189198
env::set_var("RUSTC", "rustc_should_be_set_explicitly");
190199
env::set_var("RUSTDOC", "rustdoc_should_be_set_explicitly");
191200

build_system/prepare.rs

+4-10
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,21 @@ use std::fs;
33
use std::path::{Path, PathBuf};
44
use std::process::Command;
55

6-
use super::build_sysroot::{STDLIB_SRC, SYSROOT_RUSTC_VERSION};
6+
use super::build_sysroot::STDLIB_SRC;
77
use super::path::{Dirs, RelPath};
8-
use super::rustc_info::{get_default_sysroot, get_rustc_version};
8+
use super::rustc_info::get_default_sysroot;
99
use super::utils::{
1010
copy_dir_recursively, git_command, remove_dir_if_exists, retry_spawn_and_wait, spawn_and_wait,
1111
};
1212

13-
pub(crate) fn prepare(dirs: &Dirs, rustc: &Path) {
13+
pub(crate) fn prepare(dirs: &Dirs) {
1414
RelPath::DOWNLOAD.ensure_exists(dirs);
1515
super::tests::RAND_REPO.fetch(dirs);
1616
super::tests::REGEX_REPO.fetch(dirs);
1717
super::tests::PORTABLE_SIMD_REPO.fetch(dirs);
18-
19-
// FIXME do this on the fly?
20-
prepare_stdlib(dirs, rustc);
2118
}
2219

23-
fn prepare_stdlib(dirs: &Dirs, rustc: &Path) {
20+
pub(crate) fn prepare_stdlib(dirs: &Dirs, rustc: &Path) {
2421
let sysroot_src_orig = get_default_sysroot(rustc).join("lib/rustlib/src/rust");
2522
assert!(sysroot_src_orig.exists());
2623

@@ -50,9 +47,6 @@ codegen-units = 10000
5047
"#,
5148
)
5249
.unwrap();
53-
54-
let rustc_version = get_rustc_version(rustc);
55-
fs::write(SYSROOT_RUSTC_VERSION.to_path(dirs), &rustc_version).unwrap();
5650
}
5751

5852
pub(crate) struct GitRepo {

build_system/rustc_info.rs

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

4-
pub(crate) fn get_rustc_version(rustc: &Path) -> 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-
104
pub(crate) fn get_host_triple(rustc: &Path) -> String {
115
let version_info =
126
Command::new(rustc).stderr(Stdio::inherit()).args(&["-vV"]).output().unwrap().stdout;

0 commit comments

Comments
 (0)