diff options
| author | Stuart Cook <Zalathar@users.noreply.github.com> | 2025-03-27 15:57:21 +1100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-03-27 15:57:21 +1100 |
| commit | c45986ae61ed48e24720dd1fef0528873b8e356d (patch) | |
| tree | 4d9d44ffbdaf1ea2fb8a5b2516a9f2f2c4a85d8d /compiler/rustc_middle/src/query/mod.rs | |
| parent | 2216f269c53594087dafeb99b435f1c9e3f9b7dc (diff) | |
| parent | 632ce38c9a93a6ee890aedd99fcb1a61cabd0a46 (diff) | |
| download | rust-c45986ae61ed48e24720dd1fef0528873b8e356d.tar.gz rust-c45986ae61ed48e24720dd1fef0528873b8e356d.zip | |
Rollup merge of #130883 - madsmtm:env-var-query, r=petrochenkov
Add environment variable query 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 https://github.com/rust-lang/rust/issues/118204, see https://github.com/rust-lang/rust/pull/129342 for some discussion. r? ``@petrochenkov``
Diffstat (limited to 'compiler/rustc_middle/src/query/mod.rs')
| -rw-r--r-- | compiler/rustc_middle/src/query/mod.rs | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/compiler/rustc_middle/src/query/mod.rs b/compiler/rustc_middle/src/query/mod.rs index 527c18addbe..850de3f0c2a 100644 --- a/compiler/rustc_middle/src/query/mod.rs +++ b/compiler/rustc_middle/src/query/mod.rs @@ -6,6 +6,7 @@ #![allow(unused_parens)] +use std::ffi::OsStr; use std::mem; use std::path::PathBuf; use std::sync::Arc; @@ -119,6 +120,21 @@ rustc_queries! { desc { "perform lints prior to AST lowering" } } + /// Tracked access to environment variables. + /// + /// Useful for the implementation of `std::env!`, `proc-macro`s change + /// detection and other changes in the compiler's behaviour that is easier + /// to control with an environment variable than a flag. + /// + /// NOTE: This currently does not work with dependency info in the + /// analysis, codegen and linking passes, place extra code at the top of + /// `rustc_interface::passes::write_dep_info` to make that work. + query env_var_os(key: &'tcx OsStr) -> Option<&'tcx OsStr> { + // Environment variables are global state + eval_always + desc { "get the value of an environment variable" } + } + query resolutions(_: ()) -> &'tcx ty::ResolverGlobalCtxt { no_hash desc { "getting the resolver outputs" } |
