Skip to content

Commit 3b7cb69

Browse files
committed
Fix build-std updating the index on every build.
1 parent a85ae1a commit 3b7cb69

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

src/cargo/ops/resolve.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -291,12 +291,13 @@ pub fn resolve_with_previous<'cfg>(
291291

292292
let keep = |p: &PackageId| pre_patch_keep(p) && !avoid_patch_ids.contains(p);
293293

294+
let dev_deps = ws.require_optional_deps() || has_dev_units == HasDevUnits::Yes;
294295
// In the case where a previous instance of resolve is available, we
295296
// want to lock as many packages as possible to the previous version
296297
// without disturbing the graph structure.
297298
if let Some(r) = previous {
298299
trace!("previous: {:?}", r);
299-
register_previous_locks(ws, registry, r, &keep);
300+
register_previous_locks(ws, registry, r, &keep, dev_deps);
300301
}
301302
// Everything in the previous lock file we want to keep is prioritized
302303
// in dependency selection if it comes up, aka we want to have
@@ -320,7 +321,6 @@ pub fn resolve_with_previous<'cfg>(
320321
registry.add_sources(Some(member.package_id().source_id()))?;
321322
}
322323

323-
let dev_deps = ws.require_optional_deps() || has_dev_units == HasDevUnits::Yes;
324324
let summaries: Vec<(Summary, ResolveOpts)> = ws
325325
.members_with_features(specs, cli_features)?
326326
.into_iter()
@@ -455,6 +455,7 @@ fn register_previous_locks(
455455
registry: &mut PackageRegistry<'_>,
456456
resolve: &Resolve,
457457
keep: &dyn Fn(&PackageId) -> bool,
458+
dev_deps: bool,
458459
) {
459460
let path_pkg = |id: SourceId| {
460461
if !id.is_path() {
@@ -564,6 +565,11 @@ fn register_previous_locks(
564565
continue;
565566
}
566567

568+
// If dev-dependencies aren't being resolved, skip them.
569+
if !dep.is_transitive() && !dev_deps {
570+
continue;
571+
}
572+
567573
// If this is a path dependency, then try to push it onto our
568574
// worklist.
569575
if let Some(pkg) = path_pkg(dep.source_id()) {

tests/build-std/main.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,16 @@ fn basic() {
105105
.build();
106106

107107
p.cargo("check").build_std().target_host().run();
108-
p.cargo("build").build_std().target_host().run();
108+
p.cargo("build")
109+
.build_std()
110+
.target_host()
111+
// Importantly, this should not say [UPDATING]
112+
// There have been multiple bugs where every build triggers and update.
113+
.with_stderr(
114+
"[COMPILING] foo v0.0.1 [..]\n\
115+
[FINISHED] dev [..]",
116+
)
117+
.run();
109118
p.cargo("run").build_std().target_host().run();
110119
p.cargo("test").build_std().target_host().run();
111120

0 commit comments

Comments
 (0)