Return Compiler from build_sysroot

This commit is contained in:
bjorn3 2023-01-14 13:04:40 +00:00
parent bbb7a3b9b9
commit 4dbafefe74
4 changed files with 43 additions and 36 deletions

View File

@ -32,7 +32,7 @@ pub(crate) fn run(
sysroot_kind, sysroot_kind,
cg_clif_dylib, cg_clif_dylib,
bootstrap_host_compiler, bootstrap_host_compiler,
&bootstrap_host_compiler.triple, bootstrap_host_compiler.triple.clone(),
); );
eprintln!("Running abi-cafe"); eprintln!("Running abi-cafe");

View File

@ -18,14 +18,16 @@ pub(crate) fn build_sysroot(
sysroot_kind: SysrootKind, sysroot_kind: SysrootKind,
cg_clif_dylib_src: &Path, cg_clif_dylib_src: &Path,
bootstrap_host_compiler: &Compiler, bootstrap_host_compiler: &Compiler,
target_triple: &str, target_triple: String,
) { ) -> Compiler {
eprintln!("[BUILD] sysroot {:?}", sysroot_kind); eprintln!("[BUILD] sysroot {:?}", sysroot_kind);
DIST_DIR.ensure_fresh(dirs); DIST_DIR.ensure_fresh(dirs);
BIN_DIR.ensure_exists(dirs); BIN_DIR.ensure_exists(dirs);
LIB_DIR.ensure_exists(dirs); LIB_DIR.ensure_exists(dirs);
let is_native = bootstrap_host_compiler.triple == target_triple;
// Copy the backend // Copy the backend
let cg_clif_dylib_path = if cfg!(windows) { let cg_clif_dylib_path = if cfg!(windows) {
// Windows doesn't have rpath support, so the cg_clif dylib needs to be next to the // Windows doesn't have rpath support, so the cg_clif dylib needs to be next to the
@ -55,12 +57,12 @@ pub(crate) fn build_sysroot(
let host_rustlib_lib = let host_rustlib_lib =
RUSTLIB_DIR.to_path(dirs).join(&bootstrap_host_compiler.triple).join("lib"); RUSTLIB_DIR.to_path(dirs).join(&bootstrap_host_compiler.triple).join("lib");
let target_rustlib_lib = RUSTLIB_DIR.to_path(dirs).join(target_triple).join("lib"); let target_rustlib_lib = RUSTLIB_DIR.to_path(dirs).join(&target_triple).join("lib");
fs::create_dir_all(&host_rustlib_lib).unwrap(); fs::create_dir_all(&host_rustlib_lib).unwrap();
fs::create_dir_all(&target_rustlib_lib).unwrap(); fs::create_dir_all(&target_rustlib_lib).unwrap();
if target_triple == "x86_64-pc-windows-gnu" { if target_triple == "x86_64-pc-windows-gnu" {
if !default_sysroot.join("lib").join("rustlib").join(target_triple).join("lib").exists() { if !default_sysroot.join("lib").join("rustlib").join(&target_triple).join("lib").exists() {
eprintln!( eprintln!(
"The x86_64-pc-windows-gnu target needs to be installed first before it is possible \ "The x86_64-pc-windows-gnu target needs to be installed first before it is possible \
to compile a sysroot for it.", to compile a sysroot for it.",
@ -68,7 +70,7 @@ pub(crate) fn build_sysroot(
process::exit(1); process::exit(1);
} }
for file in fs::read_dir( for file in fs::read_dir(
default_sysroot.join("lib").join("rustlib").join(target_triple).join("lib"), default_sysroot.join("lib").join("rustlib").join(&target_triple).join("lib"),
) )
.unwrap() .unwrap()
{ {
@ -108,9 +110,9 @@ pub(crate) fn build_sysroot(
try_hard_link(&file, host_rustlib_lib.join(file.file_name().unwrap())); try_hard_link(&file, host_rustlib_lib.join(file.file_name().unwrap()));
} }
if target_triple != bootstrap_host_compiler.triple { if !is_native {
for file in fs::read_dir( for file in fs::read_dir(
default_sysroot.join("lib").join("rustlib").join(target_triple).join("lib"), default_sysroot.join("lib").join("rustlib").join(&target_triple).join("lib"),
) )
.unwrap() .unwrap()
{ {
@ -127,13 +129,13 @@ pub(crate) fn build_sysroot(
&cg_clif_dylib_path, &cg_clif_dylib_path,
); );
if bootstrap_host_compiler.triple != target_triple { if !is_native {
build_clif_sysroot_for_triple( build_clif_sysroot_for_triple(
dirs, dirs,
channel, channel,
{ {
let mut bootstrap_target_compiler = bootstrap_host_compiler.clone(); let mut bootstrap_target_compiler = bootstrap_host_compiler.clone();
bootstrap_target_compiler.triple = target_triple.to_owned(); bootstrap_target_compiler.triple = target_triple.clone();
bootstrap_target_compiler.set_cross_linker_and_runner(); bootstrap_target_compiler.set_cross_linker_and_runner();
bootstrap_target_compiler bootstrap_target_compiler
}, },
@ -152,6 +154,12 @@ pub(crate) fn build_sysroot(
} }
} }
} }
let mut target_compiler = Compiler::clif_with_triple(&dirs, target_triple);
if !is_native {
target_compiler.set_cross_linker_and_runner();
}
target_compiler
} }
pub(crate) static ORIG_BUILD_SYSROOT: RelPath = RelPath::SOURCE.join("build_sysroot"); pub(crate) static ORIG_BUILD_SYSROOT: RelPath = RelPath::SOURCE.join("build_sysroot");

View File

@ -154,7 +154,7 @@ pub fn main() {
sysroot_kind, sysroot_kind,
&cg_clif_dylib, &cg_clif_dylib,
&bootstrap_host_compiler, &bootstrap_host_compiler,
&target_triple, target_triple.clone(),
); );
if bootstrap_host_compiler.triple == target_triple { if bootstrap_host_compiler.triple == target_triple {
@ -177,7 +177,7 @@ pub fn main() {
sysroot_kind, sysroot_kind,
&cg_clif_dylib, &cg_clif_dylib,
&bootstrap_host_compiler, &bootstrap_host_compiler,
&target_triple, target_triple,
); );
} }
Command::Bench => { Command::Bench => {
@ -187,7 +187,7 @@ pub fn main() {
sysroot_kind, sysroot_kind,
&cg_clif_dylib, &cg_clif_dylib,
&bootstrap_host_compiler, &bootstrap_host_compiler,
&target_triple, target_triple,
); );
bench::benchmark(&dirs, &bootstrap_host_compiler); bench::benchmark(&dirs, &bootstrap_host_compiler);
} }

View File

@ -242,21 +242,21 @@ pub(crate) fn run_tests(
sysroot_kind: SysrootKind, sysroot_kind: SysrootKind,
cg_clif_dylib: &Path, cg_clif_dylib: &Path,
bootstrap_host_compiler: &Compiler, bootstrap_host_compiler: &Compiler,
target_triple: &str, target_triple: String,
) { ) {
let runner =
TestRunner::new(dirs.clone(), target_triple.to_owned(), get_host_triple() == target_triple);
if config::get_bool("testsuite.no_sysroot") { if config::get_bool("testsuite.no_sysroot") {
build_sysroot::build_sysroot( let target_compiler = build_sysroot::build_sysroot(
dirs, dirs,
channel, channel,
SysrootKind::None, SysrootKind::None,
cg_clif_dylib, cg_clif_dylib,
bootstrap_host_compiler, bootstrap_host_compiler,
&target_triple, target_triple.clone(),
); );
let runner =
TestRunner::new(dirs.clone(), target_compiler, get_host_triple() == target_triple);
BUILD_EXAMPLE_OUT_DIR.ensure_fresh(dirs); BUILD_EXAMPLE_OUT_DIR.ensure_fresh(dirs);
runner.run_testsuite(NO_SYSROOT_SUITE); runner.run_testsuite(NO_SYSROOT_SUITE);
} else { } else {
@ -267,26 +267,29 @@ pub(crate) fn run_tests(
let run_extended_sysroot = config::get_bool("testsuite.extended_sysroot"); let run_extended_sysroot = config::get_bool("testsuite.extended_sysroot");
if run_base_sysroot || run_extended_sysroot { if run_base_sysroot || run_extended_sysroot {
build_sysroot::build_sysroot( let target_compiler = build_sysroot::build_sysroot(
dirs, dirs,
channel, channel,
sysroot_kind, sysroot_kind,
cg_clif_dylib, cg_clif_dylib,
bootstrap_host_compiler, bootstrap_host_compiler,
&target_triple, target_triple.clone(),
); );
}
if run_base_sysroot { let runner =
runner.run_testsuite(BASE_SYSROOT_SUITE); TestRunner::new(dirs.clone(), target_compiler, get_host_triple() == target_triple);
} else {
eprintln!("[SKIP] base_sysroot tests");
}
if run_extended_sysroot { if run_base_sysroot {
runner.run_testsuite(EXTENDED_SYSROOT_SUITE); runner.run_testsuite(BASE_SYSROOT_SUITE);
} else { } else {
eprintln!("[SKIP] extended_sysroot tests"); eprintln!("[SKIP] base_sysroot tests");
}
if run_extended_sysroot {
runner.run_testsuite(EXTENDED_SYSROOT_SUITE);
} else {
eprintln!("[SKIP] extended_sysroot tests");
}
} }
} }
@ -298,11 +301,7 @@ struct TestRunner {
} }
impl TestRunner { impl TestRunner {
pub fn new(dirs: Dirs, target_triple: String, is_native: bool) -> Self { pub fn new(dirs: Dirs, mut target_compiler: Compiler, is_native: bool) -> Self {
let mut target_compiler = Compiler::clif_with_triple(&dirs, target_triple);
if !is_native {
target_compiler.set_cross_linker_and_runner();
}
if let Ok(rustflags) = env::var("RUSTFLAGS") { if let Ok(rustflags) = env::var("RUSTFLAGS") {
target_compiler.rustflags.push(' '); target_compiler.rustflags.push(' ');
target_compiler.rustflags.push_str(&rustflags); target_compiler.rustflags.push_str(&rustflags);