Skip to content

Tracking issue for --env-set flag #118372

Closed as not planned
Closed as not planned

Description

@GuillaumeGomez

Adds a new --env-set command line option on rustc. It allows to set environment variables value at compile-time to be used by env! and option_env! macros.

When retrieving and environment variable value, the one specified by --env-set will take precedence. For example if you want have PATH=a in your environment and pass --env-set PATH=env, then you will have:

assert_eq!(env!("PATH"), "env");

Steps

Unresolved questions

  • What is the desired behavior if the same --env variable is passed twice?

Activity

  1. added
    C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFC
    on Nov 27, 2023
  2. GuillaumeGomez commented on Jan 13, 2024

    @GuillaumeGomez
    MemberAuthor

    We discussed about how it might impact rust-lang/rfcs#2794 and decided to rename it into --env-set to prevent potential future issues.

  3. changed the title [-]Tracking issue for `--env` flag[/-] [+]Tracking issue for `--env-set` flag[/+] on Mar 8, 2024
  4. fenollp commented on Aug 23, 2024

    @fenollp

    Hi! I see the stabilization PR was closed. What's the state of this then?

    My 2cents on a couple points:

    • I need this so my $RUSTC_WRAPPER knows which envs to forward to rustc. Can't just forward all the envs.
    • same keys in duplicate --env-set KEY=.. should be an error. It resolves that point and allows forward compatibility

    If help is needed here I'd like to provide some!

  5. xclaesse commented on Jun 5, 2025

    @xclaesse

    Hi, is there anything preventing this to be stabilized? It's pretty important as ninja cannot set env when running rustc commands. It makes using rustc outside of cargo (e.g. Meson) harder.

  6. added a commit that references this issue on Dec 1, 2025
  7. Urgau commented on Aug 31, 2026

    @Urgau
    Member

    Removed in #161831

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-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFC

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions