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

fix(env): dont track envs set by cargo in dep-info file #14811

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

weihanglo
Copy link
Member

What does this PR try to resolve?

Don't track environment variables set by Cargo1 in Cargo's dep-info file.

This patch is quite hacky since the "set-by-Cargo" env vars are
hardcoded. However, not all environment variables set by Cargo are
statically known. To prevent the actual environment variables applied to
rustc invocation get out of sync from what we hard-code, a debug time
assertion is put to help discover missing environment variables earlier.

Fixes #14798

How should we test and review this PR?

A new test is added to show no rebuild triggered.

Try adding a random new env here and see if a debug build fails.

@rustbot
Copy link
Collaborator

rustbot commented Nov 12, 2024

r? @epage

rustbot has assigned @epage.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added A-build-execution Area: anything dealing with executing the compiler A-rebuild-detection Area: rebuild detection and fingerprinting S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Nov 12, 2024
Comment on lines +576 to +583
#[cfg(debug_assertions)]
pub(crate) fn assert_only_envs_set_by_cargo<'a>(
keys: impl Iterator<Item = impl AsRef<str>>,
env_config: &HashMap<String, OsString>,
) {
for key in keys {
let key = key.as_ref();
// When running Cargo's test suite,
// we're fine if it is from the `[env]` table
if env_config.contains_key(key) {
continue;
}
assert!(
is_env_set_by_cargo(key),
"`{key}` is not tracked as an environment variable set by Cargo\n\
Add it to `ENV_VARS_SET_FOR_CRATES` if you intend to introduce a new one"
);
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This patch is quite hacky since the "set-by-Cargo" env vars are
hardcoded. However, not all environment variables set by Cargo are
statically known. To prevent the actual environment variables applied to
rustc invocation get out of sync from what we hard-code, a debug time
assertion is put to help discover missing environment variables earlier.

@ehuss I'm curious about your thoughts on this

github-merge-queue bot pushed a commit that referenced this pull request Nov 13, 2024
### What does this PR try to resolve?

This was found when doing #14811.

Other counterparts display environment variables,
but rustdoc does not.
This patch makes rustdoc follow suit.

### How should we test and review this PR?

Run `cargo doc -vv`
@@ -529,3 +529,98 @@ fn target_linker(bcx: &BuildContext<'_, '_>, kind: CompileKind) -> CargoResult<O
}
Ok(matching_linker.map(|(_k, linker)| linker.val.clone().resolve_program(bcx.gctx)))
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In order to better discover these variables, whether to put this part of the content in a separate file management is better?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A simple search for ENV_VARS_SET_FOR_CRATES could lead the way, though no objection to this proposal, just lacking of a better module name (naming is hard 😆).

@bors
Copy link
Contributor

bors commented Nov 16, 2024

☔ The latest upstream changes (presumably 69e5959) made this pull request unmergeable. Please resolve the merge conflicts.

This is a side effect when fixing 13280 via PR 14701.
This patch is quite hacky since the "set-by-Cargo" env vars are
hardcoded. However, not all environment variables set by Cargo are
statically known. To prevent the actual environment variables applied to
rustc invocation get out of sync from what we hard-code, a debug time
assertion is put to help discover missing environment variables earlier.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-build-execution Area: anything dealing with executing the compiler 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.

CARGO_RUSTC_CURRENT_DIR is causing forced rebuilds
5 participants