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

Add option to pass environment variables #653

Closed
1 of 3 tasks
GuillaumeGomez opened this issue Jul 13, 2023 · 16 comments
Closed
1 of 3 tasks

Add option to pass environment variables #653

GuillaumeGomez opened this issue Jul 13, 2023 · 16 comments
Labels
major-change A proposal to make a major change to rustc major-change-accepted A major change proposal that was accepted T-compiler Add this label so rfcbot knows to poll the compiler team

Comments

@GuillaumeGomez
Copy link
Member

Proposal

Add a new --env VAR=VALUE option which injects environment variables into the program, allowing them to be read by the env! and option_env! macros and from proc_macro_tracked_env.

An initial implementation (not merged) was done in rust-lang/rust#94387.

Mentors or Reviewers

@bjorn3 and @jyn514 were the ones who reviewed the original PR so at least tagging them here as potential mentors/reviewers.

Process

The main points of the Major Change Process are as follows:

  • File an issue describing the proposal.
  • A compiler team member or contributor who is knowledgeable in the area can second by writing @rustbot second.
    • Finding a "second" suffices for internal changes. If however, you are proposing a new public-facing feature, such as a -C flag, then full team check-off is required.
    • Compiler team members can initiate a check-off via @rfcbot fcp merge on either the MCP or the PR.
  • Once an MCP is seconded, the Final Comment Period begins. If no objections are raised after 10 days, the MCP is considered approved.

You can read more about Major Change Proposals on forge.

Comments

This issue is not meant to be used for technical discussion. There is a Zulip stream for that. Use this issue to leave procedural comments, such as volunteering to review, indicating that you second the proposal (or third, etc), or raising a concern that you would like to be addressed.

@GuillaumeGomez GuillaumeGomez added major-change A proposal to make a major change to rustc T-compiler Add this label so rfcbot knows to poll the compiler team labels Jul 13, 2023
@rustbot
Copy link
Collaborator

rustbot commented Jul 13, 2023

This issue is not meant to be used for technical discussion. There is a Zulip stream for that. Use this issue to leave procedural comments, such as volunteering to review, indicating that you second the proposal (or third, etc), or raising a concern that you would like to be addressed.

cc @rust-lang/compiler @rust-lang/compiler-contributors

@rustbot rustbot added the to-announce Announce this issue on triage meeting label Jul 13, 2023
@oli-obk
Copy link
Contributor

oli-obk commented Jul 13, 2023

@rustbot second

@rustbot rustbot added the final-comment-period The FCP has started, most (if not all) team members are in agreement label Jul 13, 2023
@jyn514
Copy link
Member

jyn514 commented Jul 13, 2023

I want to raise a concern that this doesn't support proc-macros in practice.

@apiraino apiraino removed the to-announce Announce this issue on triage meeting label Jul 13, 2023
@dtolnay
Copy link
Member

dtolnay commented Jul 21, 2023

Prior art: rust-lang/rfcs#2794

@jsgf
Copy link

jsgf commented Jul 23, 2023

Yeah very in favour of this, but it needs to have a way to also remove all process-environment variables, so that you can entirely specify the logical environment on the command line.

@GuillaumeGomez
Copy link
Member Author

GuillaumeGomez commented Jul 24, 2023

Your RFC seems more complete. Any idea why it was not approved yet?

@jsgf
Copy link

jsgf commented Jul 26, 2023

Any idea why it was [not?] approved yet?

It just needs to be driven. There are no objections, but I don't think it's got much attention. I'm happy to take it up again, esp if we have multiple independent use-cases for the functionality.

@jsgf
Copy link

jsgf commented Jul 28, 2023

@apiraino
Copy link
Contributor

apiraino commented Oct 2, 2023

@rustbot label -final-comment-period +major-change-accepted

@apiraino apiraino closed this as completed Oct 2, 2023
@rustbot rustbot added major-change-accepted A major change proposal that was accepted to-announce Announce this issue on triage meeting and removed final-comment-period The FCP has started, most (if not all) team members are in agreement labels Oct 2, 2023
@GuillaumeGomez
Copy link
Member Author

Going to start working on it next week probably.

@jsgf
Copy link

jsgf commented Oct 2, 2023

How does this relate with rust-lang/rfcs#2794? This seems like a strict subset, but it's not clear to me how the issues raised on my RFC are resolved here (eg interaction with tracked vars and proc macros). Also there's the question of how env vars containing paths are handled, though that's a broader question.

@apiraino apiraino removed the to-announce Announce this issue on triage meeting label Oct 12, 2023
@xclaesse
Copy link

xclaesse commented Nov 24, 2023

I'm working on Meson build system rust integration and this is something we absolutely need. Ninja (Meson's backend) cannot set environment variables when spawning rustc processes (for performance reasons AFAIK), which means that every rustc invocations would have to be wrapped with a script to set env which is really slow, especially on Windows.

Going to start working on it next week probably.

That would be awesome, what's your current status? I see this issue and rust-lang/rust#94387 have been closed, but I don't think the feature landed. Anything blocking it?

@GuillaumeGomez
Copy link
Member Author

I completely forgot about it since previous comment. I'll resume work on it as soon as possible as I said.

@the8472
Copy link
Member

the8472 commented Nov 24, 2023

(for performance reasons AFAIK)

The fork/vfork difference? I think glibc's posix_spawn will still use vfork even if a new environment is passed.

@eli-schwartz
Copy link

eli-schwartz commented Nov 24, 2023

I forget offhand the exact details, but I seem to recall that ninja did not want to commit to supporting this on Linux because it would be inconsistent with Windows, and they weren't sure it could be done fast on Windows and would rather not support it at all if it could not be done fast.

It was a strange argument to me personally, because I would have thought the answer is "support it everywhere, and document that if you actually make use of the functionality to set environment variables in the subprocess AND you are using Windows, it will result in minor performance penalties as opposed to fatally failing because the required variable was not set".

@Noratrieb
Copy link
Member

I kindly ask you to move to the zulip thread linked in the first comment instead of discussing it here to avoid sending out notifications to everyone :)

bors added a commit to rust-lang-ci/rust that referenced this issue Dec 10, 2023
Implement `--env` compiler flag (without `tracked_env` support)

Part of rust-lang#80792.
Implementation of rust-lang/compiler-team#653.
Not an implementation of rust-lang/rfcs#2794.

It adds the `--env` compiler flag option which allows to set environment values used by `env!` and `option_env!`.

Important to note: When trying to retrieve an environment variable value, it will first look into the ones defined with `--env`, and if there isn't one, then only it will look into the environment variables. So if you use `--env PATH=a`, then `env!("PATH")` will return `"a"` and not the actual `PATH` value.

As mentioned in the title, `tracked_env` support is not added here. I'll do it in a follow-up PR.

r? rust-lang/compiler
github-actions bot pushed a commit to rust-lang/miri that referenced this issue Dec 12, 2023
Implement `--env` compiler flag (without `tracked_env` support)

Part of rust-lang/rust#80792.
Implementation of rust-lang/compiler-team#653.
Not an implementation of rust-lang/rfcs#2794.

It adds the `--env` compiler flag option which allows to set environment values used by `env!` and `option_env!`.

Important to note: When trying to retrieve an environment variable value, it will first look into the ones defined with `--env`, and if there isn't one, then only it will look into the environment variables. So if you use `--env PATH=a`, then `env!("PATH")` will return `"a"` and not the actual `PATH` value.

As mentioned in the title, `tracked_env` support is not added here. I'll do it in a follow-up PR.

r? rust-lang/compiler
lnicola pushed a commit to lnicola/rust-analyzer that referenced this issue Apr 7, 2024
Implement `--env` compiler flag (without `tracked_env` support)

Part of rust-lang/rust#80792.
Implementation of rust-lang/compiler-team#653.
Not an implementation of rust-lang/rfcs#2794.

It adds the `--env` compiler flag option which allows to set environment values used by `env!` and `option_env!`.

Important to note: When trying to retrieve an environment variable value, it will first look into the ones defined with `--env`, and if there isn't one, then only it will look into the environment variables. So if you use `--env PATH=a`, then `env!("PATH")` will return `"a"` and not the actual `PATH` value.

As mentioned in the title, `tracked_env` support is not added here. I'll do it in a follow-up PR.

r? rust-lang/compiler
RalfJung pushed a commit to RalfJung/rust-analyzer that referenced this issue Apr 27, 2024
Implement `--env` compiler flag (without `tracked_env` support)

Part of rust-lang/rust#80792.
Implementation of rust-lang/compiler-team#653.
Not an implementation of rust-lang/rfcs#2794.

It adds the `--env` compiler flag option which allows to set environment values used by `env!` and `option_env!`.

Important to note: When trying to retrieve an environment variable value, it will first look into the ones defined with `--env`, and if there isn't one, then only it will look into the environment variables. So if you use `--env PATH=a`, then `env!("PATH")` will return `"a"` and not the actual `PATH` value.

As mentioned in the title, `tracked_env` support is not added here. I'll do it in a follow-up PR.

r? rust-lang/compiler
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
major-change A proposal to make a major change to rustc major-change-accepted A major change proposal that was accepted T-compiler Add this label so rfcbot knows to poll the compiler team
Projects
None yet
Development

No branches or pull requests