-
Notifications
You must be signed in to change notification settings - Fork 69
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
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. cc @rust-lang/compiler @rust-lang/compiler-contributors |
@rustbot second |
I want to raise a concern that this doesn't support proc-macros in practice. |
Prior art: rust-lang/rfcs#2794 |
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. |
Your RFC seems more complete. 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. |
I updated my impl in https://github.com/jsgf/rust/tree/env-sandbox |
@rustbot label -final-comment-period +major-change-accepted |
Going to start working on it next week probably. |
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. |
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.
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? |
I completely forgot about it since previous comment. I'll resume work on it as soon as possible as I said. |
The fork/vfork difference? I think glibc's posix_spawn will still use vfork even if a new environment is passed. |
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". |
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 :) |
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
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
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
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
Proposal
Add a new
--env VAR=VALUE
option which injects environment variables into the program, allowing them to be read by theenv!
andoption_env!
macros and fromproc_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:
@rustbot second
.-C flag
, then full team check-off is required.@rfcbot fcp merge
on either the MCP or the PR.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.
The text was updated successfully, but these errors were encountered: