Skip to content

Commit 417f9ea

Browse files
Utilize -Zbinary-dep-depinfo for dependency tracking
1 parent 60960a2 commit 417f9ea

File tree

3 files changed

+23
-100
lines changed

3 files changed

+23
-100
lines changed

src/bootstrap/builder.rs

+22-65
Original file line numberDiff line numberDiff line change
@@ -754,76 +754,20 @@ impl<'a> Builder<'a> {
754754
let mut cargo = Command::new(&self.initial_cargo);
755755
let out_dir = self.stage_out(compiler, mode);
756756

757-
// command specific path, we call clear_if_dirty with this
758-
let mut my_out = match cmd {
759-
"build" => self.cargo_out(compiler, mode, target),
760-
761-
// This is the intended out directory for crate documentation.
762-
"doc" | "rustdoc" => self.crate_doc_out(target),
763-
764-
_ => self.stage_out(compiler, mode),
765-
};
766-
767-
// This is for the original compiler, but if we're forced to use stage 1, then
768-
// std/test/rustc stamps won't exist in stage 2, so we need to get those from stage 1, since
769-
// we copy the libs forward.
770-
let cmp = self.compiler_for(compiler.stage, compiler.host, target);
771-
772-
let libstd_stamp = match cmd {
773-
"check" | "clippy" | "fix" => check::libstd_stamp(self, cmp, target),
774-
_ => compile::libstd_stamp(self, cmp, target),
775-
};
776-
777-
let libtest_stamp = match cmd {
778-
"check" | "clippy" | "fix" => check::libtest_stamp(self, cmp, target),
779-
_ => compile::libtest_stamp(self, cmp, target),
780-
};
781-
782-
let librustc_stamp = match cmd {
783-
"check" | "clippy" | "fix" => check::librustc_stamp(self, cmp, target),
784-
_ => compile::librustc_stamp(self, cmp, target),
785-
};
757+
// Codegen backends are not yet tracked by -Zbinary-dep-depinfo,
758+
// so we need to explicitly clear out if they've been updated.
759+
for backend in self.codegen_backends(compiler) {
760+
self.clear_if_dirty(&out_dir, &backend);
761+
}
786762

787763
if cmd == "doc" || cmd == "rustdoc" {
788-
if mode == Mode::Rustc || mode == Mode::ToolRustc || mode == Mode::Codegen {
764+
let my_out = match mode {
789765
// This is the intended out directory for compiler documentation.
790-
my_out = self.compiler_doc_out(target);
791-
}
766+
Mode::Rustc | Mode::ToolRustc | Mode::Codegen => self.compiler_doc_out(target),
767+
_ => self.crate_doc_out(target),
768+
};
792769
let rustdoc = self.rustdoc(compiler);
793770
self.clear_if_dirty(&my_out, &rustdoc);
794-
} else if cmd != "test" {
795-
match mode {
796-
Mode::Std => {
797-
self.clear_if_dirty(&my_out, &self.rustc(compiler));
798-
for backend in self.codegen_backends(compiler) {
799-
self.clear_if_dirty(&my_out, &backend);
800-
}
801-
},
802-
Mode::Test => {
803-
self.clear_if_dirty(&my_out, &libstd_stamp);
804-
},
805-
Mode::Rustc => {
806-
self.clear_if_dirty(&my_out, &self.rustc(compiler));
807-
self.clear_if_dirty(&my_out, &libstd_stamp);
808-
self.clear_if_dirty(&my_out, &libtest_stamp);
809-
},
810-
Mode::Codegen => {
811-
self.clear_if_dirty(&my_out, &librustc_stamp);
812-
},
813-
Mode::ToolBootstrap => { },
814-
Mode::ToolStd => {
815-
self.clear_if_dirty(&my_out, &libstd_stamp);
816-
},
817-
Mode::ToolTest => {
818-
self.clear_if_dirty(&my_out, &libstd_stamp);
819-
self.clear_if_dirty(&my_out, &libtest_stamp);
820-
},
821-
Mode::ToolRustc => {
822-
self.clear_if_dirty(&my_out, &libstd_stamp);
823-
self.clear_if_dirty(&my_out, &libtest_stamp);
824-
self.clear_if_dirty(&my_out, &librustc_stamp);
825-
},
826-
}
827771
}
828772

829773
cargo
@@ -861,6 +805,19 @@ impl<'a> Builder<'a> {
861805
},
862806
}
863807

808+
// This tells Cargo (and in turn, rustc) to output more complete
809+
// dependency information. Most importantly for rustbuild, this
810+
// includes sysroot artifacts, like libstd, which means that we don't
811+
// need to track those in rustbuild (an error prone process!). This
812+
// feature is currently unstable as there may be some bugs and such, but
813+
// it represents a big improvement in rustbuild's reliability on
814+
// rebuilds, so we're using it here.
815+
//
816+
// For some additional context, see #63470 (the PR originally adding
817+
// this), as well as #63012 which is the tracking issue for this
818+
// feature on the rustc side.
819+
cargo.arg("-Zbinary-dep-depinfo");
820+
864821
cargo.arg("-j").arg(self.jobs().to_string());
865822
// Remove make-related flags to ensure Cargo can correctly set things up
866823
cargo.env_remove("MAKEFLAGS");

src/bootstrap/check.rs

-1
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,6 @@ impl Step for Rustdoc {
245245
let libdir = builder.sysroot_libdir(compiler, target);
246246
let hostdir = builder.sysroot_libdir(compiler, compiler.host);
247247
add_to_sysroot(&builder, &libdir, &hostdir, &rustdoc_stamp(builder, compiler, target));
248-
builder.cargo(compiler, Mode::ToolRustc, target, "clean");
249248
}
250249
}
251250

src/bootstrap/compile.rs

+1-34
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use std::path::{Path, PathBuf};
1515
use std::process::{Command, Stdio, exit};
1616
use std::str;
1717

18-
use build_helper::{output, mtime, t, up_to_date};
18+
use build_helper::{output, t, up_to_date};
1919
use filetime::FileTime;
2020
use serde::Deserialize;
2121
use serde_json;
@@ -274,8 +274,6 @@ impl Step for StdLink {
274274
// for reason why the sanitizers are not built in stage0.
275275
copy_apple_sanitizer_dylibs(builder, &builder.native_dir(target), "osx", &libdir);
276276
}
277-
278-
builder.cargo(target_compiler, Mode::ToolStd, target, "clean");
279277
}
280278
}
281279

@@ -480,8 +478,6 @@ impl Step for TestLink {
480478
&builder.sysroot_libdir(target_compiler, compiler.host),
481479
&libtest_stamp(builder, compiler, target)
482480
);
483-
484-
builder.cargo(target_compiler, Mode::ToolTest, target, "clean");
485481
}
486482
}
487483

@@ -639,7 +635,6 @@ impl Step for RustcLink {
639635
&builder.sysroot_libdir(target_compiler, compiler.host),
640636
&librustc_stamp(builder, compiler, target)
641637
);
642-
builder.cargo(target_compiler, Mode::ToolRustc, target, "clean");
643638
}
644639
}
645640

@@ -1206,41 +1201,13 @@ pub fn run_cargo(builder: &Builder<'_>,
12061201
deps.push((path_to_add.into(), false));
12071202
}
12081203

1209-
// Now we want to update the contents of the stamp file, if necessary. First
1210-
// we read off the previous contents along with its mtime. If our new
1211-
// contents (the list of files to copy) is different or if any dep's mtime
1212-
// is newer then we rewrite the stamp file.
12131204
deps.sort();
1214-
let stamp_contents = fs::read(stamp);
1215-
let stamp_mtime = mtime(&stamp);
12161205
let mut new_contents = Vec::new();
1217-
let mut max = None;
1218-
let mut max_path = None;
12191206
for (dep, proc_macro) in deps.iter() {
1220-
let mtime = mtime(dep);
1221-
if Some(mtime) > max {
1222-
max = Some(mtime);
1223-
max_path = Some(dep.clone());
1224-
}
12251207
new_contents.extend(if *proc_macro { b"h" } else { b"t" });
12261208
new_contents.extend(dep.to_str().unwrap().as_bytes());
12271209
new_contents.extend(b"\0");
12281210
}
1229-
let max = max.unwrap();
1230-
let max_path = max_path.unwrap();
1231-
let contents_equal = stamp_contents
1232-
.map(|contents| contents == new_contents)
1233-
.unwrap_or_default();
1234-
if contents_equal && max <= stamp_mtime {
1235-
builder.verbose(&format!("not updating {:?}; contents equal and {:?} <= {:?}",
1236-
stamp, max, stamp_mtime));
1237-
return deps.into_iter().map(|(d, _)| d).collect()
1238-
}
1239-
if max > stamp_mtime {
1240-
builder.verbose(&format!("updating {:?} as {:?} changed", stamp, max_path));
1241-
} else {
1242-
builder.verbose(&format!("updating {:?} as deps changed", stamp));
1243-
}
12441211
t!(fs::write(&stamp, &new_contents));
12451212
deps.into_iter().map(|(d, _)| d).collect()
12461213
}

0 commit comments

Comments
 (0)