Repository navigation
Add option to pass environment variables to rustc with a flag #80792
Copy link
Copy link
Open
Labels
C-feature-requestCategory: A feature request, i.e: not implemented / a PR.Category: A feature request, i.e: not implemented / a PR.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Description
Activity
As such, we have no way to set environment variables at build time without resorting to something ugly like wrapping rustc in a script to proxy the variables.
For what it's worth, this is exactly what x.py does: https://github.com/rust-lang/rust/blob/master/src/bootstrap/bin/rustc.rs
What would be nice is the ability to pass environment variables to rustc directly, much like --cfg, something like --env "OUT_DIR=/some/dir".
To be clear, you only need this to support
env!, right, not actual environment variables?- addedC-feature-requestCategory: A feature request, i.e: not implemented / a PR.Category: A feature request, i.e: not implemented / a PR.
on Jan 7, 2021 Yes exactly, just
env!.Reacted by jynThanks, I'm new in these parts and don't know all of the process yet :)
- addedT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
on Jan 7, 2021 Opened an MCP about it: rust-lang/compiler-team#653
- added a commit that references this issue
on Dec 12, 2023 - added a commit that references this issue
on Dec 18, 2023 - added a commit that references this issue
on Dec 19, 2023 - added a commit that references this issue
on Dec 20, 2023 The option is now available in nightly.
Reacted by Dylan Baker- added 2 commits that reference this issue
on Apr 7, 2024 - added 2 commits that reference this issue
on Apr 27, 2024 - added a commit that references this issue
on Feb 3, 2026
Metadata
Metadata
Assignees
Labels
C-feature-requestCategory: A feature request, i.e: not implemented / a PR.Category: A feature request, i.e: not implemented / a PR.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
See #78913 for more background.
I'm a meson developer, working to make rust work better with meson. I know that cargo is the official build system for rust, but for me and the projects I work on cargo is unacceptable, we have a massive C/C++ codebase already using meson, with interest in migrating some (but not all) of our code to rust. Mostly things work fine, but one problem we do have is including generated code.
Cargo handles generated code by setting an
OUT_DIRenvironment variable, this works for cargo because it has a number of unique design decisions compared to most build systems. For Cmake and meson and particular this is problematic because we generate a declarative build system which the user invokes, visual-studio, ninja, make, etc; so there are separate "configure" and "build" stages. For ninja in particular environment variables are problematic because it's made an explicit design choice not to support them. As such, we have no way to set environment variables at build time without resorting to something ugly like wrapping rustc in a script to proxy the variables.What would be nice is the ability to pass environment variables to rustc directly, much like
--cfg, something like--env "OUT_DIR=/some/dir". This would allow us to makeinclude()work like cargo, but without needing to resort to wrapping rustc and making things slower than they need to be.