-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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 support for --env
on tracked_env::var
#118830
Conversation
rust-analyzer is developed in its own repository. If possible, consider making this change to rust-lang/rust-analyzer instead. cc @rust-lang/rust-analyzer |
@@ -1503,7 +1503,8 @@ 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 value = crate::bridge::client::FreeFunctions::injected_env_var(key) | |||
.map_or_else(|| env::var(key), Ok); | |||
crate::bridge::client::FreeFunctions::track_env_var(key, value.as_deref().ok()); |
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.
Is it correct to track --env
here? I don't think it is. Tracked env vars end up in depinfo, implying that the compiler invocation depended on this environment variable, but it didn't, there is no environment variable and even if there is, the compiler didn't care, it just depended on a flag. I think it should only track when env::var
is used.
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.
Well, if this function is called, it means the environment variable was used no? Or did I misunderstand what you meant?
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.
From an outside perspective, no "environment variable" was used. It just took a value for the flag. A build system doesn't have to check whether an environment variables changes to figure out whether a rebuild is needed, it needs to look at arguments instead (which it of course already does).
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.
Well, I'm fine with removing this call to track_env_var
. Please just confirm it's what you want I do do it. :)
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.
Yes
I also just checked your previous PR and I missed that there:
https://github.com/rust-lang/rust/pull/118368/files#diff-0eaa1095d59f2f3d9c015005d15fd8f7cda13121a8404d77b2955fc5fcd40449R37
The name here also makes it more clear what tracking is for: it's for depinfo which is used by builds systems or other consumers to figure out what went into the compilation (for example when things need to be rebuilt). It's essential that rustc records env variables it reads with env::var
. But --env
are not actually env variables in the build environment, so they don't need to be tracked. I'd also be happy to review a PR changing the behavior for the macros to not track when the var is read from --env
>
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.
That's a flag though and not an environment variable. A build system already needs to handle flags changing. Depinfo tells the build system "hey, I read this environment variable, check it again next time" but in reality it didn't read any environment variable, it got it from the flag.
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.
If it is not tracked in the dep info, any change to a --env
argument would need to trigger recompilation of all crates even if they don't use those env!()
at all.
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 see, for build systems that pass env vars explicitly like that it would be nice if they could detect whether it was actually used. But I don't think the normal env depinfo is the right place for that. The case I was thinking about was for example having A=x
in the environment and using --env A=x
. Then, changing A=y
should not cause any rebuilds as it wasn't used, only the --env A=x
value was.
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.
The case I was thinking about was for example having
A=x
in the environment and using--env A=x
. Then, changingA=y
should not cause any rebuilds as it wasn't used, only the--env A=x
value was.
And in this case it won't trigger a rebuild because the value is same. The --env
option uses the same mechanism as the env!
macro: variables are tracked if used and will trigger a rebuild if their value changed. So unless I missed something, I think it's doing exactly what we want?
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.
So we're relying on build systems correctly doing the "dep info env -> when I passed --env" translation themselves, since they know they passed the flag.
That makes sense, I didn't think of that, I was too focused on the env depinfo meaning actual environment variable, but I guess the build system is supposed to know what it's doing.
In that case, sounds good. Maybe it should be documented explicitly in the documentation for --env
that it ends up in depinfo as env vars.
My point was cleared up, thanks! |
…Nilstrieb Add support for `--env` on `tracked_env::var` Follow-up of rust-lang#118368. Part of Part of rust-lang#80792. It adds support of the `--env` option for proc-macros through `tracked_env::var`. r? `@Nilstrieb`
…llaumeGomez Rollup of 5 pull requests Successful merges: - rust-lang#118644 (Add test for Apple's `-weak_framework` linker argument) - rust-lang#118828 (Remove dead codes in rustc_codegen_gcc) - rust-lang#118830 (Add support for `--env` on `tracked_env::var`) - rust-lang#119001 (rustdoc-search: remove parallel searchWords array) - rust-lang#119020 (remove `hex` dependency in bootstrap) r? `@ghost` `@rustbot` modify labels: rollup
…Nilstrieb Add support for `--env` on `tracked_env::var` Follow-up of rust-lang#118368. Part of Part of rust-lang#80792. It adds support of the `--env` option for proc-macros through `tracked_env::var`. r? ``@Nilstrieb``
…llaumeGomez Rollup of 5 pull requests Successful merges: - rust-lang#118828 (Remove dead codes in rustc_codegen_gcc) - rust-lang#118830 (Add support for `--env` on `tracked_env::var`) - rust-lang#119001 (rustdoc-search: remove parallel searchWords array) - rust-lang#119011 (coverage: Regression test for `assert!(!false)`) - rust-lang#119020 (remove `hex` dependency in bootstrap) r? `@ghost` `@rustbot` modify labels: rollup
☀️ Test successful - checks-actions |
Finished benchmarking commit (5e70254): comparison URL. Overall result: ✅ improvements - no action needed@rustbot label: -perf-regression Instruction countThis is a highly reliable metric that was used to determine the overall result at the top of this comment.
Max RSS (memory usage)ResultsThis is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
CyclesThis benchmark run did not return any relevant results for this metric. Binary sizeThis benchmark run did not return any relevant results for this metric. Bootstrap: 672.2s -> 674.824s (0.39%) |
Update documentation for `--env` compilation flag Part of rust-lang#80792. As mentioned in rust-lang#118830. It adds a mention to `tracked_env::var` and also clarifies what triggers a new compilation. r? `@Nilstrieb`
Rollup merge of rust-lang#119115 - GuillaumeGomez:env-docs, r=Nilstrieb Update documentation for `--env` compilation flag Part of rust-lang#80792. As mentioned in rust-lang#118830. It adds a mention to `tracked_env::var` and also clarifies what triggers a new compilation. r? `@Nilstrieb`
…lstrieb Add support for `--env` on `tracked_env::var` Follow-up of rust-lang#118368. Part of Part of rust-lang#80792. It adds support of the `--env` option for proc-macros through `tracked_env::var`. r? `@Nilstrieb`
Follow-up of #118368.
Part of #80792 and of #118372.
It adds support of the
--env
option for proc-macros throughtracked_env::var
.r? @Nilstrieb