Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Include lints.rust.unexpected_cfgs.check-cfg in the fingerprint #13958

Merged
merged 2 commits into from
May 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 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,34 @@ fn calculate_normal(
}
.to_vec();

// Include all the args from `[lints.rust.unexpected_cfgs.check-cfg]`
//
// HACK(#13975): duplicating the lookup logic here until `--check-cfg` is supported
// on Cargo's MSRV and we can centralize the logic in `lints_to_rustflags`
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
49 changes: 49 additions & 0 deletions tests/testsuite/check_cfg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -824,3 +824,52 @@ fn config_features_and_build_script() {
.with_stderr_contains(x!("rustc" => "cfg" of "docsrs")) // Cargo well known
.run();
}

#[cargo_test(>=1.79, reason = "--check-cfg was stabilized in Rust 1.79")]
fn config_fingerprint() {
let p = project()
.file(
"Cargo.toml",
r#"
[package]
name = "foo"
version = "0.1.0"
edition = "2015"

[lints.rust]
unexpected_cfgs = { level = "warn", check-cfg = ["cfg(bar)"] }
"#,
)
.file("src/lib.rs", "fn entry() {}")
.build();

p.cargo("check -v")
.with_stderr_contains(x!("rustc" => "cfg" of "bar"))
.run();

p.cargo("check -v")
.with_stderr_does_not_contain("[..]rustc[..]")
.run();

// checking that changing the `check-cfg` config does invalid the fingerprint
p.change_file(
"Cargo.toml",
r#"
[package]
name = "foo"
version = "0.1.0"
edition = "2015"

[lints.rust]
unexpected_cfgs = { level = "warn", check-cfg = ["cfg(bar)", "cfg(foo)"] }
"#,
);

p.cargo("check -v")
// 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();
}