Skip to content

Commit dbcabc7

Browse files
committed
Change metadata strategy to extract hash from nested compilation
1 parent b9b39a6 commit dbcabc7

File tree

3 files changed

+35
-16
lines changed

3 files changed

+35
-16
lines changed

src/cargo/core/compiler/context/compilation_files.rs

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -540,17 +540,7 @@ fn compute_metadata(
540540
// `panic=abort` and `panic=unwind` artifacts, additionally with various
541541
// settings like debuginfo and whatnot.
542542
unit.profile.hash(&mut hasher);
543-
544-
// For RFC #3123, we need the metadata of a Check and Doc unit of the same crate
545-
// to be the same. So we add a special case that ensures Doc and Check are hashed
546-
// to the same value.
547-
match unit.mode {
548-
CompileMode::Doc { .. } | CompileMode::Check { .. } => {
549-
(CompileMode::Check { test: false }).hash(&mut hasher)
550-
}
551-
mode => mode.hash(&mut hasher),
552-
};
553-
543+
unit.mode.hash(&mut hasher);
554544
cx.lto[unit].hash(&mut hasher);
555545

556546
// Artifacts compiled for the host should have a different metadata

src/cargo/core/compiler/mod.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ mod job;
1212
mod job_queue;
1313
mod layout;
1414
mod links;
15-
mod lto;
15+
pub mod lto;
1616
mod output_depinfo;
1717
pub mod rustdoc;
1818
pub mod standard_lib;
@@ -640,10 +640,6 @@ fn rustdoc(cx: &mut Context<'_, '_>, unit: &Unit) -> CargoResult<Work> {
640640
rustdoc.arg("--cfg").arg(&format!("feature=\"{}\"", feat));
641641
}
642642

643-
// This is needed so StableCrateId can be computed correctly.
644-
let meta = cx.files().metadata(unit);
645-
rustdoc.arg("-C").arg(&format!("metadata={}", meta));
646-
647643
add_error_format_and_color(cx, &mut rustdoc, false);
648644
add_allow_features(cx, &mut rustdoc);
649645

src/cargo/ops/cargo_compile.rs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,10 @@
2525
use std::collections::{BTreeSet, HashMap, HashSet};
2626
use std::ffi::OsString;
2727
use std::hash::{Hash, Hasher};
28+
use std::iter;
2829
use std::sync::Arc;
2930

31+
use crate::core::compiler::lto;
3032
use crate::core::compiler::unit_dependencies::build_unit_dependencies;
3133
use crate::core::compiler::unit_graph::{self, UnitDep, UnitGraph};
3234
use crate::core::compiler::Layout;
@@ -649,6 +651,37 @@ pub fn create_bcx<'a, 'cfg>(
649651
args.extend(crate_names);
650652
}
651653

654+
// Find the check unit corresponding to each documented crate, then add the -C metadata=...
655+
// flag to the doc unit for that crate
656+
{
657+
let mut cx = Context::new(&bcx)?;
658+
cx.lto = lto::generate(&bcx)?;
659+
cx.prepare_units()?;
660+
661+
for unit in units.iter() {
662+
let mut root_deps = bcx
663+
.unit_graph
664+
.iter()
665+
.map(|(k, v)| iter::once(k).chain(v.iter().map(|dep| &dep.unit)))
666+
.flatten();
667+
668+
let check_unit = root_deps.find(|dep| {
669+
dep.pkg == unit.pkg && dep.target == unit.target && dep.mode.is_check()
670+
});
671+
672+
if let Some(check_unit) = check_unit {
673+
let metadata = cx.files().metadata(check_unit);
674+
extra_compiler_args
675+
.entry(unit.clone())
676+
.or_default()
677+
.extend_from_slice(&[
678+
"-C".into(),
679+
OsString::from(format!("metadata={}", metadata)),
680+
]);
681+
}
682+
}
683+
}
684+
652685
// Invoke recursive Cargo
653686
let cx = Context::new(&bcx)?;
654687
cx.compile(&exec)?;

0 commit comments

Comments
 (0)