Skip to content

Commit 40be400

Browse files
authored
Rollup merge of rust-lang#61727 - Mark-Simulacrum:crate-deps-in-deps, r=alexcrichton
Add binary dependencies to dep-info files I'm not sure about the lack of incremental-tracking here, but since I'm pretty sure this runs on every compile anyway it might not matter? If there's a better place/way to get at the information I want, I'm happy to refactor the code to match. r? @alexcrichton
2 parents 03f19f7 + d749b5e commit 40be400

File tree

3 files changed

+27
-3
lines changed

3 files changed

+27
-3
lines changed

src/librustc/session/config.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1468,6 +1468,8 @@ options! {DebuggingOptions, DebuggingSetter, basic_debugging_options,
14681468
symbol_mangling_version: SymbolManglingVersion = (SymbolManglingVersion::Legacy,
14691469
parse_symbol_mangling_version, [TRACKED],
14701470
"which mangling version to use for symbol names"),
1471+
binary_dep_depinfo: bool = (false, parse_bool, [TRACKED],
1472+
"include artifacts (sysroot, crate dependencies) used during compilation in dep-info"),
14711473
}
14721474

14731475
pub fn default_lib_output() -> CrateType {

src/librustc/session/mod.rs

+3
Original file line numberDiff line numberDiff line change
@@ -545,6 +545,9 @@ impl Session {
545545
pub fn print_llvm_passes(&self) -> bool {
546546
self.opts.debugging_opts.print_llvm_passes
547547
}
548+
pub fn binary_dep_depinfo(&self) -> bool {
549+
self.opts.debugging_opts.binary_dep_depinfo
550+
}
548551

549552
/// Gets the features enabled for the current compilation session.
550553
/// DO NOT USE THIS METHOD if there is a TyCtxt available, as it circumvents

src/librustc_interface/passes.rs

+22-3
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use rustc::hir::lowering::lower_crate;
99
use rustc::hir::def_id::{CrateNum, LOCAL_CRATE};
1010
use rustc::lint;
1111
use rustc::middle::{self, reachable, resolve_lifetime, stability};
12+
use rustc::middle::cstore::CrateStore;
1213
use rustc::middle::privacy::AccessLevels;
1314
use rustc::ty::{self, AllArenas, Resolutions, TyCtxt, GlobalCtxt};
1415
use rustc::ty::steal::Steal;
@@ -657,7 +658,8 @@ fn escape_dep_filename(filename: &FileName) -> String {
657658
filename.to_string().replace(" ", "\\ ")
658659
}
659660

660-
fn write_out_deps(sess: &Session, outputs: &OutputFilenames, out_filenames: &[PathBuf]) {
661+
fn write_out_deps(compiler: &Compiler, outputs: &OutputFilenames, out_filenames: &[PathBuf]) {
662+
let sess = &compiler.sess;
661663
// Write out dependency rules to the dep-info file if requested
662664
if !sess.opts.output_types.contains_key(&OutputType::DepInfo) {
663665
return;
@@ -667,13 +669,30 @@ fn write_out_deps(sess: &Session, outputs: &OutputFilenames, out_filenames: &[Pa
667669
let result = (|| -> io::Result<()> {
668670
// Build a list of files used to compile the output and
669671
// write Makefile-compatible dependency rules
670-
let files: Vec<String> = sess.source_map()
672+
let mut files: Vec<String> = sess.source_map()
671673
.files()
672674
.iter()
673675
.filter(|fmap| fmap.is_real_file())
674676
.filter(|fmap| !fmap.is_imported())
675677
.map(|fmap| escape_dep_filename(&fmap.name))
676678
.collect();
679+
680+
if sess.binary_dep_depinfo() {
681+
for cnum in compiler.cstore.crates_untracked() {
682+
let metadata = compiler.cstore.crate_data_as_rc_any(cnum);
683+
let metadata = metadata.downcast_ref::<cstore::CrateMetadata>().unwrap();
684+
if let Some((path, _)) = &metadata.source.dylib {
685+
files.push(escape_dep_filename(&FileName::Real(path.clone())));
686+
}
687+
if let Some((path, _)) = &metadata.source.rlib {
688+
files.push(escape_dep_filename(&FileName::Real(path.clone())));
689+
}
690+
if let Some((path, _)) = &metadata.source.rmeta {
691+
files.push(escape_dep_filename(&FileName::Real(path.clone())));
692+
}
693+
}
694+
}
695+
677696
let mut file = fs::File::create(&deps_filename)?;
678697
for path in out_filenames {
679698
writeln!(file, "{}: {}\n", path.display(), files.join(" "))?;
@@ -750,7 +769,7 @@ pub fn prepare_outputs(
750769
}
751770
}
752771

753-
write_out_deps(sess, &outputs, &output_paths);
772+
write_out_deps(compiler, &outputs, &output_paths);
754773

755774
let only_dep_info = sess.opts.output_types.contains_key(&OutputType::DepInfo)
756775
&& sess.opts.output_types.len() == 1;

0 commit comments

Comments
 (0)