Skip to content

Commit

Permalink
Include lints.rust.unexpected_cfgs.check-cfg into the fingerprint
Browse files Browse the repository at this point in the history
  • Loading branch information
Urgau committed May 24, 2024
1 parent 3ca2120 commit bb3af49
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 3 deletions.
25 changes: 25 additions & 0 deletions src/cargo/core/compiler/fingerprint/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@
//! config settings[^5] | ✓ |
//! is_std | | ✓
//! `[lints]` table[^6] | ✓ |
//! `[lints.rust.unexpected_cfgs.check-cfg]` | ✓ |
//!
//! [^1]: Build script and bin dependencies are not included.
//!
Expand Down Expand Up @@ -1420,12 +1421,36 @@ fn calculate_normal(
}
.to_vec();

// Include all the args from `[lints.rust.unexpected_cfgs.check-cfg]`
//
// FIXME(Urgau): move this lookup directly in `toml::lints_to_rustflags`
// when check-cfg support is no longer gated, so that when calling
// `Manifest::lint_rustflags` we get those arguments for free
// (ie. without having to manually retrive the lint config here).
let mut lint_check_cfg = Vec::new();
if let Ok(Some(lints)) = unit.pkg.manifest().resolved_toml().resolved_lints() {
if let Some(rust_lints) = lints.get("rust") {
if let Some(unexpected_cfgs) = rust_lints.get("unexpected_cfgs") {
if let Some(config) = unexpected_cfgs.config() {
if let Some(check_cfg) = config.get("check-cfg") {
if let Ok(check_cfgs) =
toml::Value::try_into::<Vec<String>>(check_cfg.clone())
{
lint_check_cfg = check_cfgs;
}
}
}
}
}
}

let profile_hash = util::hash_u64((
&unit.profile,
unit.mode,
build_runner.bcx.extra_args_for(unit),
build_runner.lto[unit],
unit.pkg.manifest().lint_rustflags(),
lint_check_cfg,
));
// Include metadata since it is exposed as environment variables.
let m = unit.pkg.manifest().metadata();
Expand Down
9 changes: 6 additions & 3 deletions tests/testsuite/check_cfg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -851,8 +851,7 @@ fn config_fingerprint() {
.with_stderr_does_not_contain("[..]rustc[..]")
.run();

// checking that changing the `-check-cfg` config does not invalid the fingerprint
// FIXME: This should change the fingerprint
// checking that changing the `check-cfg` config does invalid the fingerprint
p.change_file(
"Cargo.toml",
r#"
Expand All @@ -867,6 +866,10 @@ fn config_fingerprint() {
);

p.cargo("check -v")
.with_stderr_does_not_contain("[..]rustc[..]")
// we check that the fingerprint is indeed dirty
.with_stderr_contains("[..]Dirty[..]the profile configuration changed")
// that cause rustc to be called again with the new check-cfg args
.with_stderr_contains(x!("rustc" => "cfg" of "bar"))
.with_stderr_contains(x!("rustc" => "cfg" of "foo"))
.run();
}

0 comments on commit bb3af49

Please sign in to comment.