-
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 pass environment variables #94387
Changes from all commits
f64a0b3
53a64d2
34d71d9
5fad881
223942d
8a9edfd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,8 @@ use rustc_target::spec::{ | |
RelocModel, RelroLevel, SplitDebuginfo, StackProtector, TargetTriple, TlsModel, | ||
}; | ||
|
||
use rustc_data_structures::fx::FxHashMap; | ||
|
||
use rustc_feature::UnstableFeatures; | ||
use rustc_span::edition::Edition; | ||
use rustc_span::RealFileName; | ||
|
@@ -210,6 +212,9 @@ top_level_options!( | |
|
||
/// The (potentially remapped) working directory | ||
working_dir: RealFileName [TRACKED], | ||
|
||
/// Overridden env vars used for `env!` and `option_env!` | ||
injected_env_vars: FxHashMap<String, String> [UNTRACKED], | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this needs to be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shouldn't the tracking be based on the actual use of the env vars? If an env var is specified but the crate never references it, changing it shouldn't require a crate recompile. |
||
} | ||
); | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1505,7 +1505,10 @@ pub mod tracked_env { | |
#[unstable(feature = "proc_macro_tracked_env", issue = "99515")] | ||
pub fn var<K: AsRef<OsStr> + AsRef<str>>(key: K) -> Result<String, VarError> { | ||
let key: &str = key.as_ref(); | ||
let value = env::var(key); | ||
let injected_value = crate::bridge::client::FreeFunctions::injected_env_var(key); | ||
let env_value = env::var(key); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In my take on this - https://github.com/jsgf/rust/tree/env-sandbox - I just initialized the logical environment (equiv of injected vars) with all the env vars, and never used |
||
|
||
let value = injected_value.map_or(env_value, Ok); | ||
crate::bridge::client::FreeFunctions::track_env_var(key, value.as_deref().ok()); | ||
value | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
// run-pass | ||
// rustc_env: overridden=no | ||
// compile-flags: -Z unstable-options --env x=y --env overridden=yes | ||
|
||
fn main() { | ||
assert_eq!(env!("x"), "y"); | ||
assert_eq!(env!("overridden"), "yes"); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this should be skipped in case
--env
mentions this env var. Otherwise changes to the actual env vars will cause a recompilation, even if they don't affect compilation at all.