-
Notifications
You must be signed in to change notification settings - Fork 13k
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 define environment vars #39656
Comments
Also relevent: rust-lang/rust-roadmap-2017#12 |
This is a feature request to override the environment available at build-time. I'm wondering if build scripts could help here -- perhaps they could clear the environment? I worry though that wouldn't affect dependencies, presumably. |
I don't think a build script would work, because that would imply that the build script is invoking rustc rather than cargo itself. (It also doesn't cope with the case of setting the env for the build script itself). An alternative is that cargo could override the environment before invoking rustc, but it's not possible to override the entire environment so long as the build process itself needs some environment set ( There's are two distinct (but related) issues here:
In practice, these amount to the same problem (Rust code has unconstrained access to the environment, which forms undeclared dependencies), and can be controlled in the same way (only allow the rust compilation environment access to a completely "synthetic" environment). |
Triage: this feels like a big enough thing that it maybe is RFC-worthy; regardless, it's not clear to me what team to assign this to. |
I tend to agree that an RFC would be necessary here, though perhaps a small one. We could also plausibly start by adding |
I had an RFC underway but as I implemented it I realized it didn't really work the way I wanted it to. I need to get back to it. |
Right now, code can use
env!()
andoption_env!()
to query arbitrary environment variables set at the time rustc is invoked. This is a subtle leak of the compilation environment into the generated code, which can cause issues with build reproducibility, and could conceivably be considered a security problem.I'd like to have the option to completely define the "environment" that's available to
env!()
on the compiler command line to an explicitly delimited set of names and valuesFor example:
--override-env
- disable querying of real environment--set-env name=val
- define an environment variable (added to existing env if--override-env
not set)--unset-env name
- make a name unsetcc @luser - this seems pertinent to caching rust-lang/cargo#3066
The text was updated successfully, but these errors were encountered: