-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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 environment variable query #130883
base: master
Are you sure you want to change the base?
Add environment variable query #130883
Conversation
@@ -336,6 +337,20 @@ fn early_lint_checks(tcx: TyCtxt<'_>, (): ()) { | |||
) | |||
} | |||
|
|||
fn env_var(tcx: TyCtxt<'_>, key: Symbol) -> Option<Symbol> { |
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 was unsure where to put the query definition, so I just put it in the same file as some other general queries.
@@ -336,6 +337,20 @@ fn early_lint_checks(tcx: TyCtxt<'_>, (): ()) { | |||
) | |||
} | |||
|
|||
fn env_var(tcx: TyCtxt<'_>, key: Symbol) -> Option<Symbol> { | |||
let var = match std::env::var(key.as_str()) { |
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 there something similar to Clippy's disallowed-methods
that I could use to lint against usage of std::env::var
in the compiler, and direct users towards the query instead?
See also rust-lang/cargo#11588.
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.
There's some rustc-internal lints in https://github.com/rust-lang/rust/blob/master/compiler/rustc_lint/src/internal.rs
This comment has been minimized.
This comment has been minimized.
506b0df
to
af26a40
Compare
This comment has been minimized.
This comment has been minimized.
dee9b61
to
0ef9570
Compare
This comment has been minimized.
This comment has been minimized.
0ef9570
to
455e468
Compare
This comment has been minimized.
This comment has been minimized.
455e468
to
46276c8
Compare
// Also add the variable to Cargo's dependency tracking | ||
tcx.sess.psess.env_depinfo.borrow_mut().insert((key, var)); |
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.
Hmm, a complication here is that this query will only work with the dependency info files that Cargo reads if it's called before passes::write_dep_info
at:
rust/compiler/rustc_driver_impl/src/lib.rs
Line 437 in a3f76a2
passes::write_dep_info(tcx); |
So everything done during passes::analysis
and Linker::codegen_and_build_linker
will need some other mechanism for populating ParseSess::env_depinfo
.
Is it possible for us to move the write_dep_info
pass to the very end, or just before linking? Or is it important that it happens as soon as possible for parallelizing Cargo, or something?
Generally,
rustc
prefers command-line arguments, but in some cases, an environment variable really is the most sensible option. We should make sure that this works properly with the compiler's change-tracking mechanisms, such that changing the relevant environment variable causes a rebuild.This PR is a first step forwards in doing that.
Part of the work needed to do #118204, see #129342 for some discussion.
r? @petrochenkov