Visitar URL original
fix(fingerprint): prioritize manifest metadata over host env vars by Verlaluz · Pull Request #17656 · rust-lang/cargo · GitHub
Skip to content

fix(fingerprint): prioritize manifest metadata over host env vars - #17656

Open
Verlaluz wants to merge 2 commits into
rust-lang:masterfrom
Verlaluz:fix-17635-pkg-description-rebuild
Open

Verlaluz wants to merge 2 commits into
rust-lang:masterfrom
Verlaluz:fix-17635-pkg-description-rebuild

Conversation

@Verlaluz

Copy link
Copy Markdown

Cargo could miss changes to manifest metadata variables such as CARGO_PKG_DESCRIPTION during rebuild checks. This happened when an older value was already set in the host environment, causing Cargo to overlook the updated manifest value and skip recompilation.

This fix checks manifest metadata first and falls back to the host environment only when needed. A regression test has also been added to prevent this issue from happening again.

Fixes #17635

What does this PR try to resolve?

When Cargo checks whether a target needs to be rebuilt, LocalFingerprint::CheckDepInfo goes through the environment variables recorded in the dep-info file.

Previously, when a manifest metadata value such as CARGO_PKG_DESCRIPTION changed in Cargo.toml, Cargo could end up checking the host environment instead of using the updated value. If the host environment still contained the old value, Cargo incorrectly assumed that nothing had changed and skipped recompilation.

This PR fixes the issue by resolving environment variables in step by step order:

CARGO_ENV — the path to the Cargo binary.

Manifest metadata from Cargo.toml, retrieved through pkg.manifest().metadata().env_var(...).

Environment variables defined in Cargo's [env] configuration, accessed through gctx.env_config().

The host environment, used as a fallback through gctx.get_env(...).

With this change, Cargo checks manifest metadata before falling back to the host environment, preventing outdated host values from hiding changes in Cargo.toml.

Notes to reviewers

I ran the regression test locally using cargo test --test testsuite freshness::rebuild_metadata_env_var_overrides_host_env. The test passed, and all freshness tests completed successfully.

🤖 LLM involvement: How an LLM was used in preparing this change.
I used an LLM assistant as a pair-programming mentor to better understand Cargo's fingerprinting system, discuss different implementation approaches, and improve the structure of the regression test. All code changes were reviewed, implemented, and verified manually.

@rustbot rustbot added A-rebuild-detection Area: rebuild detection and fingerprinting S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Oct 28, 2026
@rustbot

rustbot commented Oct 28, 2026

Copy link
Copy Markdown
Collaborator

Thanks for the pull request, and welcome! The Rust Project has assigned @epage (or someone else) to review your changes, you should hear from them (or someone else) within the next two weeks.

Please see the contribution instructions and our LLM policy for more information.

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: @Muscraft, @epage, @weihanglo
  • @Muscraft, @epage, @weihanglo expanded to Muscraft, epage, weihanglo
  • Random selection from Muscraft, epage, weihanglo

Comment thread tests/testsuite/freshness.rs Resolved
Cargo could miss changes to manifest metadata variables such as
CARGO_PKG_DESCRIPTION during rebuild checks. This happened when an
older value was already set in the host environment, causing Cargo
to overlook the updated manifest value and skip recompilation.

This fix checks manifest metadata first and falls back to the host
environment only when needed.

Fixes rust-lang#17635
@Verlaluz
Verlaluz force-pushed the fix-17635-pkg-description-rebuild branch from 1505aed to e65e668 Compare October 29, 2026 11:18

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-rebuild-detection Area: rebuild detection and fingerprinting S-waiting-on-review Status: Awaiting review from the assignee but also interested parties.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Exported CARGO_PKG_DESCRIPTION can miss a change to package.description

4 participants