Skip to content

allow using null to unset an environment variable #19629

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

Merged
merged 1 commit into from
Apr 21, 2025

Conversation

jyn514
Copy link
Member

@jyn514 jyn514 commented Apr 19, 2025

this makes three changes:

  • all callsites of toolchain::command are changed to use command(path, extra_env), instead of manually adding the env after the fact.
  • all map<str, str> are changed to map<str, option<str>>.
  • command checks for None and calls env_remove if so.

this caught several places where environment variables weren't being propagated:

  • when running rustc --print=target-libdir
  • when running cargo rustc -- --print=target-spec-json
  • when running the custom DiscoverLinkedProjects config. I think this is for use with non-cargo build systems, so I didn't change it.

i verified locally that this actually works.

fixes #19626

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Apr 19, 2025
@jyn514
Copy link
Member Author

jyn514 commented Apr 19, 2025

cc @davidbarsky for the DiscoverCommand changes; should cargo.extraEnv or check.extraEnv apply there? right now they don’t.

this makes three changes:
- all callsites of `toolchain::command` are changed to use
  `command(path, extra_env)`, instead of manually adding the env after
  the fact.
- all `map<str, str>` are changed to `map<str, option<str>>`.
- `command` checks for None and calls `env_remove` if so.

this caught several places where environment variables weren't being
propagated:
- when running `rustc --print=target-libdir`
- when running `cargo rustc -- --print=target-spec-json`
- when running the custom DiscoverLinkedProjects config. I *think* this
  is for use with non-cargo build systems, so I didn't change it.
@davidbarsky
Copy link
Contributor

@jyn514 Sorry for the delay. I—weakly—don’t think that environment variables should apply to DiscoverCommand because that functionality was designed to be used with hermetic build systems like Bazel and Buck, where changing environment variables shouldn’t really have an impact on the first place.

I think if we do want to add environment variable support to DiscoverCommand (and that’s a big if!), it shouldn’t be through Cargo-scoped configuration.

Copy link
Member

@Veykril Veykril left a comment

Choose a reason for hiding this comment

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

Thanks!

@Veykril Veykril added this pull request to the merge queue Apr 21, 2025
Merged via the queue into rust-lang:master with commit 00887db Apr 21, 2025
14 checks passed
@jyn514 jyn514 deleted the unset-env branch April 21, 2025 12:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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.

setting rust-analyzer.cargo.extraEnv.key = null has no effect
4 participants