Avoid fingerprint invalidation when reordering the declared features

This commit is contained in:
Urgau 2023-12-01 22:05:17 +01:00
parent 7d1fc45a29
commit f32f43d879
2 changed files with 22 additions and 1 deletions

View File

@ -1443,7 +1443,9 @@ fn calculate_normal(cx: &mut Context<'_, '_>, unit: &Unit) -> CargoResult<Finger
allow_features.hash(&mut config);
}
let compile_kind = unit.kind.fingerprint_hash();
let declared_features = unit.pkg.summary().features().keys().collect::<Vec<_>>();
let mut declared_features = unit.pkg.summary().features().keys().collect::<Vec<_>>();
declared_features.sort(); // to avoid useless rebuild if the user orders it's features
// differently
Ok(Fingerprint {
rustc: util::hash_u64(&cx.bcx.rustc().verbose_version),
target: util::hash_u64(&unit.target),

View File

@ -165,6 +165,25 @@ fn features_fingerprint() {
.with_stderr_does_not_contain("[..]unexpected_cfgs[..]")
.run();
p.cargo("check -v -Zcheck-cfg")
.masquerade_as_nightly_cargo(&["check-cfg"])
.with_stderr_does_not_contain("[..]rustc[..]")
.run();
// checking that re-ordering the features does not invalid the fingerprint
p.change_file(
"Cargo.toml",
r#"
[package]
name = "foo"
version = "0.1.0"
[features]
f_b = []
f_a = []
"#,
);
p.cargo("check -v -Zcheck-cfg")
.masquerade_as_nightly_cargo(&["check-cfg"])
.with_stderr_does_not_contain("[..]rustc[..]")