From 7bd36fb02a6a2de1d00939caec5aabc8a3cc37be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20K=C3=A5re=20Alsaker?= Date: Mon, 3 Dec 2018 01:14:35 +0100 Subject: [PATCH] Build system fixes --- Cargo.lock | 5 ++++ src/bootstrap/check.rs | 14 ++++++++--- src/bootstrap/compile.rs | 53 +++++++++++++++++++++++++++++++++------- 3 files changed, 59 insertions(+), 13 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index d22a91073394a..91afab0cea10f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2368,6 +2368,7 @@ version = "0.0.0" dependencies = [ "bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.81 (registry+https://github.com/rust-lang/crates.io-index)", "unicode-width 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -2433,6 +2434,8 @@ dependencies = [ "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", "rustc_cratesio_shim 0.0.0", "rustc_data_structures 0.0.0", + "serde 1.0.81 (registry+https://github.com/rust-lang/crates.io-index)", + "serde_derive 1.0.81 (registry+https://github.com/rust-lang/crates.io-index)", "serialize 0.0.0", "syntax_pos 0.0.0", "termcolor 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", @@ -3027,6 +3030,8 @@ dependencies = [ "cfg-if 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", "rustc_data_structures 0.0.0", "scoped-tls 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.81 (registry+https://github.com/rust-lang/crates.io-index)", + "serde_derive 1.0.81 (registry+https://github.com/rust-lang/crates.io-index)", "serialize 0.0.0", "unicode-width 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", ] diff --git a/src/bootstrap/check.rs b/src/bootstrap/check.rs index 0c6dbb06bb882..9470ccaa51b25 100644 --- a/src/bootstrap/check.rs +++ b/src/bootstrap/check.rs @@ -52,7 +52,7 @@ impl Step for Std { true); let libdir = builder.sysroot_libdir(compiler, target); - add_to_sysroot(&builder, &libdir, &libstd_stamp(builder, compiler, target)); + add_to_sysroot(&builder, &libdir, &libstd_stamp(builder, compiler, target), None); } } @@ -98,8 +98,14 @@ impl Step for Rustc { &librustc_stamp(builder, compiler, target), true); + let stage_out = builder.build.stage_out(compiler, Mode::Rustc); let libdir = builder.sysroot_libdir(compiler, target); - add_to_sysroot(&builder, &libdir, &librustc_stamp(builder, compiler, target)); + add_to_sysroot( + &builder, + &libdir, + &librustc_stamp(builder, compiler, target), + Some(&stage_out), + ); } } @@ -188,7 +194,7 @@ impl Step for Test { true); let libdir = builder.sysroot_libdir(compiler, target); - add_to_sysroot(builder, &libdir, &libtest_stamp(builder, compiler, target)); + add_to_sysroot(builder, &libdir, &libtest_stamp(builder, compiler, target), None); } } @@ -236,7 +242,7 @@ impl Step for Rustdoc { true); let libdir = builder.sysroot_libdir(compiler, target); - add_to_sysroot(&builder, &libdir, &rustdoc_stamp(builder, compiler, target)); + add_to_sysroot(&builder, &libdir, &rustdoc_stamp(builder, compiler, target), None); builder.cargo(compiler, Mode::ToolRustc, target, "clean"); } } diff --git a/src/bootstrap/compile.rs b/src/bootstrap/compile.rs index 899997c4d8646..3146a950a0612 100644 --- a/src/bootstrap/compile.rs +++ b/src/bootstrap/compile.rs @@ -219,7 +219,7 @@ impl Step for StdLink { target_compiler.host, target)); let libdir = builder.sysroot_libdir(target_compiler, target); - add_to_sysroot(builder, &libdir, &libstd_stamp(builder, compiler, target)); + add_to_sysroot(builder, &libdir, &libstd_stamp(builder, compiler, target), None); if builder.config.sanitizers && compiler.stage != 0 && target == "x86_64-apple-darwin" { // The sanitizers are only built in stage1 or above, so the dylibs will @@ -423,7 +423,7 @@ impl Step for TestLink { target_compiler.host, target)); add_to_sysroot(builder, &builder.sysroot_libdir(target_compiler, target), - &libtest_stamp(builder, compiler, target)); + &libtest_stamp(builder, compiler, target), None); builder.cargo(target_compiler, Mode::ToolTest, target, "clean"); } @@ -584,8 +584,13 @@ impl Step for RustcLink { &compiler.host, target_compiler.host, target)); - add_to_sysroot(builder, &builder.sysroot_libdir(target_compiler, target), - &librustc_stamp(builder, compiler, target)); + let stage_out = builder.build.stage_out(target_compiler, Mode::Rustc); + add_to_sysroot( + builder, + &builder.sysroot_libdir(target_compiler, target), + &librustc_stamp(builder, compiler, target), + Some(&stage_out), + ); builder.cargo(target_compiler, Mode::ToolRustc, target, "clean"); } } @@ -1014,10 +1019,26 @@ impl Step for Assemble { /// /// For a particular stage this will link the file listed in `stamp` into the /// `sysroot_dst` provided. -pub fn add_to_sysroot(builder: &Builder, sysroot_dst: &Path, stamp: &Path) { +pub fn add_to_sysroot( + builder: &Builder, + sysroot_dst: &Path, + stamp: &Path, + stage_out: Option<&Path>) { t!(fs::create_dir_all(&sysroot_dst)); for path in builder.read_stamp_file(stamp) { - builder.copy(&path, &sysroot_dst.join(path.file_name().unwrap())); + let file_dir = path.parent().unwrap() // chop off base name + .parent().unwrap() // chop off `release` + .parent().unwrap(); // chop off `release` + if stage_out == Some(file_dir) { + // We are copying a build file. We need to add the build triple to it + let rustlib_dir = sysroot_dst.parent().unwrap() // chop off `lib` + .parent().unwrap(); // chop off `$target` + let build_dir = rustlib_dir.join(builder.build.build).join("lib"); + t!(fs::create_dir_all(&build_dir)); + builder.copy(&path, &build_dir.join(path.file_name().unwrap())); + } else { + builder.copy(&path, &sysroot_dst.join(path.file_name().unwrap())); + } } } @@ -1047,8 +1068,12 @@ pub fn run_cargo(builder: &Builder, let mut deps = Vec::new(); let mut toplevel = Vec::new(); let ok = stream_cargo(builder, cargo, tail_args, &mut |msg| { - let filenames = match msg { - CargoMessage::CompilerArtifact { filenames, .. } => filenames, + let (filenames, package_id) = match msg { + CargoMessage::CompilerArtifact { + filenames, + package_id, + .. + } => (filenames, package_id), _ => return, }; for filename in filenames { @@ -1062,9 +1087,19 @@ pub fn run_cargo(builder: &Builder, let filename = Path::new(&*filename); + // If this was an output file in the "host dir" we don't actually + // worry about it, it's not relevant for us + if filename.starts_with(&host_root_dir) { + // Unless it's a proc macro used in the compiler + if package_id.starts_with("serde_derive ") { + deps.push(filename.to_path_buf()); + } + continue; + } + // If this was output in the `deps` dir then this is a precise file // name (hash included) so we start tracking it. - if filename.starts_with(&host_root_dir) || filename.starts_with(&target_deps_dir) { + if filename.starts_with(&target_deps_dir) { deps.push(filename.to_path_buf()); continue; }