mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-27 01:04:03 +00:00
Lazily patch the standard library
This commit is contained in:
parent
d0ea8bbc5e
commit
bcac222013
@ -1,9 +1,9 @@
|
||||
use std::fs;
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::process::{self, Command};
|
||||
use std::process::Command;
|
||||
|
||||
use super::path::{Dirs, RelPath};
|
||||
use super::rustc_info::{get_file_name, get_rustc_version};
|
||||
use super::rustc_info::get_file_name;
|
||||
use super::utils::{
|
||||
maybe_incremental, remove_dir_if_exists, spawn_and_wait, try_hard_link, CargoProject, Compiler,
|
||||
};
|
||||
@ -158,7 +158,6 @@ impl SysrootTarget {
|
||||
}
|
||||
|
||||
pub(crate) static STDLIB_SRC: RelPath = RelPath::BUILD.join("stdlib");
|
||||
pub(crate) static SYSROOT_RUSTC_VERSION: RelPath = STDLIB_SRC.join("rustc_version");
|
||||
pub(crate) static STANDARD_LIBRARY: CargoProject =
|
||||
CargoProject::new(&STDLIB_SRC.join("library/sysroot"), "stdlib_target");
|
||||
pub(crate) static RTSTARTUP_SYSROOT: RelPath = RelPath::BUILD.join("rtstartup");
|
||||
@ -222,24 +221,6 @@ fn build_clif_sysroot_for_triple(
|
||||
mut compiler: Compiler,
|
||||
cg_clif_dylib_path: &CodegenBackend,
|
||||
) -> SysrootTarget {
|
||||
match fs::read_to_string(SYSROOT_RUSTC_VERSION.to_path(dirs)) {
|
||||
Err(e) => {
|
||||
eprintln!("Failed to get rustc version for patched sysroot source: {}", e);
|
||||
eprintln!("Hint: Try `./y.sh prepare` to patch the sysroot source");
|
||||
process::exit(1);
|
||||
}
|
||||
Ok(source_version) => {
|
||||
let rustc_version = get_rustc_version(&compiler.rustc);
|
||||
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.sh prepare` to update the patched sysroot source");
|
||||
process::exit(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let mut target_libs = SysrootTarget { triple: compiler.triple.clone(), libs: vec![] };
|
||||
|
||||
if let Some(rtstartup_target_libs) = build_rtstartup(dirs, &compiler) {
|
||||
@ -302,6 +283,10 @@ fn build_clif_sysroot_for_triple(
|
||||
}
|
||||
|
||||
fn build_rtstartup(dirs: &Dirs, compiler: &Compiler) -> Option<SysrootTarget> {
|
||||
if !super::config::get_bool("keep_sysroot") {
|
||||
super::prepare::prepare_stdlib(dirs, &compiler.rustc);
|
||||
}
|
||||
|
||||
if !compiler.triple.ends_with("windows-gnu") {
|
||||
return None;
|
||||
}
|
||||
|
@ -126,6 +126,22 @@ fn main() {
|
||||
}
|
||||
}
|
||||
|
||||
let current_dir = std::env::current_dir().unwrap();
|
||||
out_dir = current_dir.join(out_dir);
|
||||
|
||||
if command == Command::Prepare {
|
||||
prepare::prepare(&path::Dirs {
|
||||
source_dir: current_dir.clone(),
|
||||
download_dir: download_dir
|
||||
.map(|dir| current_dir.join(dir))
|
||||
.unwrap_or_else(|| out_dir.join("download")),
|
||||
build_dir: PathBuf::from("dummy_do_not_use"),
|
||||
dist_dir: PathBuf::from("dummy_do_not_use"),
|
||||
frozen,
|
||||
});
|
||||
process::exit(0);
|
||||
}
|
||||
|
||||
let rustup_toolchain_name = match (env::var("CARGO"), env::var("RUSTC"), env::var("RUSTDOC")) {
|
||||
(Ok(_), Ok(_), Ok(_)) => None,
|
||||
(Err(_), Err(_), Err(_)) => Some(rustc_info::get_toolchain_name()),
|
||||
@ -158,8 +174,6 @@ fn main() {
|
||||
.unwrap_or_else(|| bootstrap_host_compiler.triple.clone());
|
||||
|
||||
// FIXME allow changing the location of these dirs using cli arguments
|
||||
let current_dir = std::env::current_dir().unwrap();
|
||||
out_dir = current_dir.join(out_dir);
|
||||
let dirs = path::Dirs {
|
||||
source_dir: current_dir.clone(),
|
||||
download_dir: download_dir
|
||||
@ -181,11 +195,6 @@ fn main() {
|
||||
std::fs::File::create(target).unwrap();
|
||||
}
|
||||
|
||||
if command == Command::Prepare {
|
||||
prepare::prepare(&dirs, &bootstrap_host_compiler.rustc);
|
||||
process::exit(0);
|
||||
}
|
||||
|
||||
env::set_var("RUSTC", "rustc_should_be_set_explicitly");
|
||||
env::set_var("RUSTDOC", "rustdoc_should_be_set_explicitly");
|
||||
|
||||
|
@ -3,24 +3,21 @@ use std::fs;
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::process::Command;
|
||||
|
||||
use super::build_sysroot::{STDLIB_SRC, SYSROOT_RUSTC_VERSION};
|
||||
use super::build_sysroot::STDLIB_SRC;
|
||||
use super::path::{Dirs, RelPath};
|
||||
use super::rustc_info::{get_default_sysroot, get_rustc_version};
|
||||
use super::rustc_info::get_default_sysroot;
|
||||
use super::utils::{
|
||||
copy_dir_recursively, git_command, remove_dir_if_exists, retry_spawn_and_wait, spawn_and_wait,
|
||||
};
|
||||
|
||||
pub(crate) fn prepare(dirs: &Dirs, rustc: &Path) {
|
||||
pub(crate) fn prepare(dirs: &Dirs) {
|
||||
RelPath::DOWNLOAD.ensure_exists(dirs);
|
||||
super::tests::RAND_REPO.fetch(dirs);
|
||||
super::tests::REGEX_REPO.fetch(dirs);
|
||||
super::tests::PORTABLE_SIMD_REPO.fetch(dirs);
|
||||
|
||||
// FIXME do this on the fly?
|
||||
prepare_stdlib(dirs, rustc);
|
||||
}
|
||||
|
||||
fn prepare_stdlib(dirs: &Dirs, rustc: &Path) {
|
||||
pub(crate) fn prepare_stdlib(dirs: &Dirs, rustc: &Path) {
|
||||
let sysroot_src_orig = get_default_sysroot(rustc).join("lib/rustlib/src/rust");
|
||||
assert!(sysroot_src_orig.exists());
|
||||
|
||||
@ -50,9 +47,6 @@ codegen-units = 10000
|
||||
"#,
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
let rustc_version = get_rustc_version(rustc);
|
||||
fs::write(SYSROOT_RUSTC_VERSION.to_path(dirs), &rustc_version).unwrap();
|
||||
}
|
||||
|
||||
pub(crate) struct GitRepo {
|
||||
|
@ -1,12 +1,6 @@
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::process::{Command, Stdio};
|
||||
|
||||
pub(crate) fn get_rustc_version(rustc: &Path) -> 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(rustc: &Path) -> String {
|
||||
let version_info =
|
||||
Command::new(rustc).stderr(Stdio::inherit()).args(&["-vV"]).output().unwrap().stdout;
|
||||
|
Loading…
Reference in New Issue
Block a user