Skip to content

--env-set interaction with the compiler itself #161609

Closed as not planned
Closed as not planned

Description

@Urgau

The first attempt at stabilizing --env-set (#118372) in #119926 was blocked by a concern (#119926 (comment)):

I wonder how should all of them interact with --set-env.
Never interact? Always interact? Interact on a case-by-case basis?

I.e. should --env-set PATH=. have a impact on where rustc would search the linker and other tools that the compiler may use, or if it should be restricted to the Rust code it-self: env!, option_env!, ... as it's currently the case ?

For reference the current documentation: https://doc.rust-lang.org/beta/unstable-book/compiler-flags/env-set.html

Activity

  1. added
    T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
    C-discussionCategory: Discussion or questions that doesn't represent real issues.
    on Aug 23, 2026
  2. added
    needs-triageThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triaging
    on Aug 23, 2026
  3. removed
    needs-triageThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triaging
    on Aug 23, 2026
  4. Urgau commented on Aug 23, 2026

    @Urgau
    MemberAuthor

    @fenollp @xclaesse @dblsaiko @bonzini (cc-ing you since expressed interest in the feature before) could you share your opinion on the blocker to stabilization.

  5. bonzini commented on Aug 23, 2026

    @bonzini

    Even after stabilization it wouldn't be applicable for some time to procedural macros (because they currently use std::env and proc_macro::tracked::env_var is not stable, which is a chicken-and-egg situation); also, it doesn't apply to build.rs files that compute the env var's name, because of the difference between env! and env::var.

    These may not be huge issues (proc macros that read environment variables are relatively rare, and e.g. meson doesn't use build.rs at all), but there are some high profile cases like proc_macro_crate; and overall, they make the feature unortogonal.

    I think it should be considered a failed experiment.

  6. Urgau commented on Aug 24, 2026

    @Urgau
    MemberAuthor

    it doesn't apply to build.rs files that compute the env var's name, because of the difference between env! and env::var.

    Yeah, that's the difference between compile-time and runtime-time environment variables. The compiler can't do anything about runtime envs.

    Even after stabilization it wouldn't be applicable for some time to procedural macros

    As you said it, it a chicken-and-egg situation, we have to start somewhere, and I'm sure we can push #99515 forward as well.

    but there are some high profile cases like proc_macro_crate

    I'm not familar with the issues regarding this crate, could you explain them?

    I think it should be considered a failed experiment.

    How does mesonbuild/meson#15148 fall into this? Are you expecting mesonbuild/meson#15148 to reverted?

  7. bonzini commented on Aug 24, 2026

    @bonzini

    I'm not familar with the issues regarding this crate, could you explain them?

    It's an example of the chicken and egg situation.

    How does mesonbuild/meson#15148 fall into this? Are you expecting mesonbuild/meson#15148 to reverted?

    There is work in progress to use a wrapper program to invoke rustc with environment variables on Windows, at this point --env-set would be unnecessary. It is only used in connection with experimental parts of meson anyway.

  8. changed the title [-]`--env-set` interaction with the compiler it-self[/-] [+]`--env-set` interaction with the compiler itself[/+] on Aug 24, 2026
  9. Urgau commented on Aug 24, 2026

    @Urgau
    MemberAuthor

    @dtolnay I see that buck2 is also using --env-set in some places.

    As per above meson doesn't seems to be needed it anymore, what about buck2?

  10. dtolnay commented on Aug 24, 2026

    @dtolnay
    Member

    Buck does not pass --env-set to rustc, they are intercepted here.

  11. Urgau commented on Aug 26, 2026

    @Urgau
    MemberAuthor

    Thanks everyone for the feedback. There doesn't to be a future for the feature. I will propose removing it.

  12. added a commit that references this issue on Aug 31, 2026
  13. added a commit that references this issue on Aug 31, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-discussionCategory: Discussion or questions that doesn't represent real issues.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions