Skip to content

Commit 757112c

Browse files
committed
Auto merge of #5490 - alexcrichton:fix-thrash, r=matklad
Factor in `used_in_plugin` to target filenames This prevents thrashing the cache of compiled libraries for when they're used in a plugin or not.
2 parents 2912a58 + 9df7370 commit 757112c

File tree

3 files changed

+71
-2
lines changed

3 files changed

+71
-2
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -427,6 +427,7 @@ fn compute_metadata<'a, 'cfg>(
427427
// panic=abort and panic=unwind artifacts, additionally with various
428428
// settings like debuginfo and whatnot.
429429
unit.profile.hash(&mut hasher);
430+
cx.used_in_plugin.contains(unit).hash(&mut hasher);
430431
unit.mode.hash(&mut hasher);
431432
if let Some(ref args) = bcx.extra_args_for(unit) {
432433
args.hash(&mut hasher);

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,6 @@ impl<'a, 'cfg> Context<'a, 'cfg> {
123123
let mut queue = JobQueue::new(self.bcx);
124124
self.prepare_units(export_dir, units)?;
125125
self.prepare()?;
126-
self.build_used_in_plugin_map(units)?;
127126
custom_build::build_map(&mut self, units)?;
128127

129128
for unit in units.iter() {
@@ -261,6 +260,7 @@ impl<'a, 'cfg> Context<'a, 'cfg> {
261260
};
262261

263262
build_unit_dependencies(units, self.bcx, &mut self.unit_dependencies)?;
263+
self.build_used_in_plugin_map(units)?;
264264
let files = CompilationFiles::new(
265265
units,
266266
host_layout,
@@ -302,7 +302,7 @@ impl<'a, 'cfg> Context<'a, 'cfg> {
302302
///
303303
/// This will recursively walk `units` and all of their dependencies to
304304
/// determine which crate are going to be used in plugins or not.
305-
pub fn build_used_in_plugin_map(&mut self, units: &[Unit<'a>]) -> CargoResult<()> {
305+
fn build_used_in_plugin_map(&mut self, units: &[Unit<'a>]) -> CargoResult<()> {
306306
let mut visited = HashSet::new();
307307
for unit in units {
308308
self.walk_used_in_plugin_map(unit, unit.target.for_host(), &mut visited)?;

tests/testsuite/freshness.rs

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1164,3 +1164,71 @@ fn change_panic_mode() {
11641164
assert_that(p.cargo("build -p foo"), execs().with_status(0));
11651165
assert_that(p.cargo("build -p bar"), execs().with_status(0));
11661166
}
1167+
1168+
#[test]
1169+
fn dont_rebuild_based_on_plugins() {
1170+
let p = project("p")
1171+
.file(
1172+
"Cargo.toml",
1173+
r#"
1174+
[package]
1175+
name = "foo"
1176+
version = "0.1.1"
1177+
1178+
[workspace]
1179+
members = ['bar']
1180+
1181+
[dependencies]
1182+
proc-macro-thing = { path = 'proc-macro-thing' }
1183+
"#,
1184+
)
1185+
.file("src/lib.rs", "")
1186+
.file(
1187+
"proc-macro-thing/Cargo.toml",
1188+
r#"
1189+
[package]
1190+
name = "proc-macro-thing"
1191+
version = "0.1.1"
1192+
1193+
[lib]
1194+
proc-macro = true
1195+
1196+
[dependencies]
1197+
baz = { path = '../baz' }
1198+
"#,
1199+
)
1200+
.file("proc-macro-thing/src/lib.rs", "")
1201+
.file(
1202+
"bar/Cargo.toml",
1203+
r#"
1204+
[package]
1205+
name = "bar"
1206+
version = "0.1.1"
1207+
1208+
[dependencies]
1209+
baz = { path = '../baz' }
1210+
"#,
1211+
)
1212+
.file("bar/src/main.rs", "fn main() {}")
1213+
.file(
1214+
"baz/Cargo.toml",
1215+
r#"
1216+
[package]
1217+
name = "baz"
1218+
version = "0.1.1"
1219+
"#,
1220+
)
1221+
.file("baz/src/lib.rs", "")
1222+
.build();
1223+
1224+
assert_that(p.cargo("build"), execs().with_status(0));
1225+
assert_that(p.cargo("build -p bar"), execs().with_status(0));
1226+
assert_that(
1227+
p.cargo("build"),
1228+
execs().with_status(0).with_stderr("[FINISHED] [..]\n"),
1229+
);
1230+
assert_that(
1231+
p.cargo("build -p bar"),
1232+
execs().with_status(0).with_stderr("[FINISHED] [..]\n"),
1233+
);
1234+
}

0 commit comments

Comments
 (0)