From 15892e003c26b97e5502c46538ef10c9e673751a Mon Sep 17 00:00:00 2001
From: Ed Page <eopage@gmail.com>
Date: Mon, 9 Dec 2024 10:02:41 -0600
Subject: [PATCH 1/2] refactor(build-rs): Abstract `std::env::var_os`

I made a dedicated `Env::is_present` function in case we want to handle
`rerun-if-env-changed` differently in that case.
---
 crates/build-rs/src/input.rs | 95 ++++++++++++++++++++++++------------
 1 file changed, 63 insertions(+), 32 deletions(-)

diff --git a/crates/build-rs/src/input.rs b/crates/build-rs/src/input.rs
index 6cfdd3268a6..d0c694eb185 100644
--- a/crates/build-rs/src/input.rs
+++ b/crates/build-rs/src/input.rs
@@ -6,11 +6,41 @@
 //!
 //! Reference: <https://doc.rust-lang.org/stable/cargo/reference/environment-variables.html#environment-variables-cargo-sets-for-build-scripts>
 
-use std::env::var_os;
 use std::path::PathBuf;
 
 use crate::ident::{is_ascii_ident, is_crate_name, is_feature_name};
 
+/// Abstraction over environment variables
+trait Env {
+    /// Fetches the environment variable `key`, returning `None` if the variable isn’t set or if
+    /// there is another error.
+    ///
+    /// It may return `None` if the environment variable’s name contains the equal sign character
+    /// (`=`) or the NUL character.
+    ///
+    /// Note that this function will not check if the environment variable is valid Unicode.
+    fn get(&self, key: &str) -> Option<std::ffi::OsString>;
+
+    /// Checks the environment variable `key` is present
+    ///
+    /// It may not be considered present if the environment variable’s name contains the equal sign character
+    /// (`=`) or the NUL character.
+    fn is_present(&self, key: &str) -> bool;
+}
+
+/// Fetches environment variables from the current process
+struct ProcessEnv;
+
+impl Env for ProcessEnv {
+    fn get(&self, key: &str) -> Option<std::ffi::OsString> {
+        std::env::var_os(key)
+    }
+
+    fn is_present(&self, key: &str) -> bool {
+        self.get(key).is_some()
+    }
+}
+
 /// Path to the `cargo` binary performing the build.
 #[track_caller]
 pub fn cargo() -> PathBuf {
@@ -30,7 +60,8 @@ pub fn cargo_manifest_dir() -> PathBuf {
 /// The path to the manifest of your package.
 #[track_caller]
 pub fn cargo_manifest_path() -> PathBuf {
-    var_os("CARGO_MANIFEST_PATH")
+    ProcessEnv
+        .get("CARGO_MANIFEST_PATH")
         .map(to_path)
         .unwrap_or_else(|| {
             let mut path = cargo_manifest_dir();
@@ -42,7 +73,7 @@ pub fn cargo_manifest_path() -> PathBuf {
 /// The manifest `links` value.
 #[track_caller]
 pub fn cargo_manifest_links() -> Option<String> {
-    var_os("CARGO_MANIFEST_LINKS").map(to_string)
+    ProcessEnv.get("CARGO_MANIFEST_LINKS").map(to_string)
 }
 
 /// Contains parameters needed for Cargo’s [jobserver] implementation to parallelize
@@ -57,7 +88,7 @@ pub fn cargo_manifest_links() -> Option<String> {
 /// [jobserver]: https://www.gnu.org/software/make/manual/html_node/Job-Slots.html
 #[track_caller]
 pub fn cargo_makeflags() -> Option<String> {
-    var_os("CARGO_MAKEFLAGS").map(to_string)
+    ProcessEnv.get("CARGO_MAKEFLAGS").map(to_string)
 }
 
 /// For each activated feature of the package being built, this will be `true`.
@@ -68,7 +99,7 @@ pub fn cargo_feature(name: &str) -> bool {
     }
     let name = name.to_uppercase().replace('-', "_");
     let key = format!("CARGO_FEATURE_{name}");
-    is_present(&key)
+    ProcessEnv.is_present(&key)
 }
 
 /// For each [configuration option] of the package being built, this will contain
@@ -82,7 +113,7 @@ pub fn cargo_feature(name: &str) -> bool {
 #[track_caller]
 pub fn cargo_cfg(cfg: &str) -> Option<Vec<String>> {
     let var = cargo_cfg_var(cfg);
-    var_os(&var).map(|v| to_strings(v, ','))
+    ProcessEnv.get(&var).map(|v| to_strings(v, ','))
 }
 
 #[track_caller]
@@ -112,7 +143,7 @@ mod cfg {
     #[cfg(any())]
     #[track_caller]
     pub fn cargo_cfg_clippy() -> bool {
-        is_present("CARGO_CFG_CLIPPY")
+        ProcessEnv.is_present("CARGO_CFG_CLIPPY")
     }
 
     /// If we are compiling with debug assertions enabled.
@@ -123,25 +154,25 @@ mod cfg {
     #[cfg(any())]
     #[track_caller]
     pub fn cargo_cfg_debug_assertions() -> bool {
-        is_present("CARGO_CFG_DEBUG_ASSERTIONS")
+        ProcessEnv.is_present("CARGO_CFG_DEBUG_ASSERTIONS")
     }
 
     #[cfg(any())]
     #[track_caller]
     pub fn cargo_cfg_doc() -> bool {
-        is_present("CARGO_CFG_DOC")
+        ProcessEnv.is_present("CARGO_CFG_DOC")
     }
 
     #[cfg(any())]
     #[track_caller]
     pub fn cargo_cfg_docsrs() -> bool {
-        is_present("CARGO_CFG_DOCSRS")
+        ProcessEnv.is_present("CARGO_CFG_DOCSRS")
     }
 
     #[cfg(any())]
     #[track_caller]
     pub fn cargo_cfg_doctest() -> bool {
-        is_present("CARGO_CFG_DOCTEST")
+        ProcessEnv.is_present("CARGO_CFG_DOCTEST")
     }
 
     /// The level of detail provided by derived [`Debug`] implementations.
@@ -155,7 +186,7 @@ mod cfg {
     #[cfg(any())]
     #[track_caller]
     pub fn cargo_cfg_miri() -> bool {
-        is_present("CARGO_CFG_MIRI")
+        ProcessEnv.is_present("CARGO_CFG_MIRI")
     }
 
     /// If we are compiling with overflow checks enabled.
@@ -163,7 +194,7 @@ mod cfg {
     #[cfg(feature = "unstable")]
     #[track_caller]
     pub fn cargo_cfg_overflow_checks() -> bool {
-        is_present("CARGO_CFG_OVERFLOW_CHECKS")
+        ProcessEnv.is_present("CARGO_CFG_OVERFLOW_CHECKS")
     }
 
     /// The [panic strategy](https://doc.rust-lang.org/stable/reference/conditional-compilation.html#panic).
@@ -175,7 +206,7 @@ mod cfg {
     /// If the crate is being compiled as a procedural macro.
     #[track_caller]
     pub fn cargo_cfg_proc_macro() -> bool {
-        is_present("CARGO_CFG_PROC_MACRO")
+        ProcessEnv.is_present("CARGO_CFG_PROC_MACRO")
     }
 
     /// The target relocation model.
@@ -189,7 +220,7 @@ mod cfg {
     #[cfg(any())]
     #[track_caller]
     pub fn cargo_cfg_rustfmt() -> bool {
-        is_present("CARGO_CFG_RUSTFMT")
+        ProcessEnv.is_present("CARGO_CFG_RUSTFMT")
     }
 
     /// Sanitizers enabled for the crate being compiled.
@@ -197,7 +228,9 @@ mod cfg {
     #[cfg(feature = "unstable")]
     #[track_caller]
     pub fn cargo_cfg_sanitize() -> Option<Vec<String>> {
-        var_os("CARGO_CFG_SANITIZE").map(|v| to_strings(v, ','))
+        ProcessEnv
+            .get("CARGO_CFG_SANITIZE")
+            .map(|v| to_strings(v, ','))
     }
 
     /// If CFI sanitization is generalizing pointers.
@@ -205,7 +238,7 @@ mod cfg {
     #[cfg(feature = "unstable")]
     #[track_caller]
     pub fn cargo_cfg_sanitizer_cfi_generalize_pointers() -> bool {
-        is_present("CARGO_CFG_SANITIZER_CFI_GENERALIZE_POINTERS")
+        ProcessEnv.is_present("CARGO_CFG_SANITIZER_CFI_GENERALIZE_POINTERS")
     }
 
     /// If CFI sanitization is normalizing integers.
@@ -213,7 +246,7 @@ mod cfg {
     #[cfg(feature = "unstable")]
     #[track_caller]
     pub fn cargo_cfg_sanitizer_cfi_normalize_integers() -> bool {
-        is_present("CARGO_CFG_SANITIZER_CFI_NORMALIZE_INTEGERS")
+        ProcessEnv.is_present("CARGO_CFG_SANITIZER_CFI_NORMALIZE_INTEGERS")
     }
 
     /// Disambiguation of the [target ABI](https://doc.rust-lang.org/stable/reference/conditional-compilation.html#target_abi)
@@ -309,7 +342,7 @@ mod cfg {
     #[cfg(feature = "unstable")]
     #[track_caller]
     pub fn cargo_cfg_target_thread_local() -> bool {
-        is_present("CARGO_CFG_TARGET_THREAD_LOCAL")
+        ProcessEnv.is_present("CARGO_CFG_TARGET_THREAD_LOCAL")
     }
 
     /// The [target vendor](https://doc.rust-lang.org/stable/reference/conditional-compilation.html#target_vendor).
@@ -321,7 +354,7 @@ mod cfg {
     #[cfg(any())]
     #[track_caller]
     pub fn cargo_cfg_test() -> bool {
-        is_present("CARGO_CFG_TEST")
+        ProcessEnv.is_present("CARGO_CFG_TEST")
     }
 
     /// If we are compiling with UB checks enabled.
@@ -329,19 +362,19 @@ mod cfg {
     #[cfg(feature = "unstable")]
     #[track_caller]
     pub fn cargo_cfg_ub_checks() -> bool {
-        is_present("CARGO_CFG_UB_CHECKS")
+        ProcessEnv.is_present("CARGO_CFG_UB_CHECKS")
     }
 
     /// Set on [unix-like platforms](https://doc.rust-lang.org/stable/reference/conditional-compilation.html#unix-and-windows).
     #[track_caller]
     pub fn cargo_cfg_unix() -> bool {
-        is_present("CARGO_CFG_UNIX")
+        ProcessEnv.is_present("CARGO_CFG_UNIX")
     }
 
     /// Set on [windows-like platforms](https://doc.rust-lang.org/stable/reference/conditional-compilation.html#unix-and-windows).
     #[track_caller]
     pub fn cargo_cfg_windows() -> bool {
-        is_present("CARGO_CFG_WINDOWS")
+        ProcessEnv.is_present("CARGO_CFG_WINDOWS")
     }
 }
 
@@ -428,7 +461,7 @@ pub fn dep_metadata(name: &str, key: &str) -> Option<String> {
     let name = name.to_uppercase().replace('-', "_");
     let key = key.to_uppercase().replace('-', "_");
     let key = format!("DEP_{name}_{key}");
-    var_os(&key).map(to_string)
+    ProcessEnv.get(&key).map(to_string)
 }
 
 /// The compiler that Cargo has resolved to use.
@@ -448,7 +481,7 @@ pub fn rustdoc() -> PathBuf {
 /// [`build.rustc-wrapper`]: https://doc.rust-lang.org/stable/cargo/reference/config.html#buildrustc-wrapper
 #[track_caller]
 pub fn rustc_wrapper() -> Option<PathBuf> {
-    var_os("RUSTC_WRAPPER").map(to_path)
+    ProcessEnv.get("RUSTC_WRAPPER").map(to_path)
 }
 
 /// The rustc wrapper, if any, that Cargo is using for workspace members. See
@@ -457,7 +490,7 @@ pub fn rustc_wrapper() -> Option<PathBuf> {
 /// [`build.rustc-workspace-wrapper`]: https://doc.rust-lang.org/stable/cargo/reference/config.html#buildrustc-workspace-wrapper
 #[track_caller]
 pub fn rustc_workspace_wrapper() -> Option<PathBuf> {
-    var_os("RUSTC_WORKSPACE_WRAPPER").map(to_path)
+    ProcessEnv.get("RUSTC_WORKSPACE_WRAPPER").map(to_path)
 }
 
 /// The linker that Cargo has resolved to use for the current target, if specified.
@@ -465,7 +498,7 @@ pub fn rustc_workspace_wrapper() -> Option<PathBuf> {
 /// [`target.*.linker`]: https://doc.rust-lang.org/stable/cargo/reference/config.html#targettriplelinker
 #[track_caller]
 pub fn rustc_linker() -> Option<PathBuf> {
-    var_os("RUSTC_LINKER").map(to_path)
+    ProcessEnv.get("RUSTC_LINKER").map(to_path)
 }
 
 /// Extra flags that Cargo invokes rustc with. See [`build.rustflags`].
@@ -561,13 +594,11 @@ pub fn cargo_pkg_readme() -> Option<PathBuf> {
     to_opt(var_or_panic("CARGO_PKG_README")).map(to_path)
 }
 
-fn is_present(key: &str) -> bool {
-    var_os(key).is_some()
-}
-
 #[track_caller]
 fn var_or_panic(key: &str) -> std::ffi::OsString {
-    var_os(key).unwrap_or_else(|| panic!("cargo environment variable `{key}` is missing"))
+    ProcessEnv
+        .get(key)
+        .unwrap_or_else(|| panic!("cargo environment variable `{key}` is missing"))
 }
 
 fn to_path(value: std::ffi::OsString) -> PathBuf {

From 6c021e0ac815e0b30cd406a43c6d63fcc3d697ef Mon Sep 17 00:00:00 2001
From: Ed Page <eopage@gmail.com>
Date: Mon, 9 Dec 2024 10:28:52 -0600
Subject: [PATCH 2/2] fix(build-rs): Implicitly report `rerun-if-env-changed`
 for `input`

As we abstract aware the env variables, users can't do a good job of
reporting these, so we'll do it ourselves.

We could make the traits public and take and explicit `env` parameter.
I figured we can wait until there is a motivating use case.
`build_env` does have a fancier `Env` impl where you pass it HOST and
TARGET and it automatically looks up values for those with a fallback
scheme.
---
 crates/build-rs/src/input.rs | 84 +++++++++++++++++++++++-------------
 1 file changed, 53 insertions(+), 31 deletions(-)

diff --git a/crates/build-rs/src/input.rs b/crates/build-rs/src/input.rs
index d0c694eb185..c07264a4f76 100644
--- a/crates/build-rs/src/input.rs
+++ b/crates/build-rs/src/input.rs
@@ -9,6 +9,10 @@
 use std::path::PathBuf;
 
 use crate::ident::{is_ascii_ident, is_crate_name, is_feature_name};
+use crate::output::rerun_if_env_changed;
+
+/// [`ProcessEnv`] wrapper that implicit calls [`rerun_if_env_changed`]
+const ENV: RerunIfEnvChanged<ProcessEnv> = RerunIfEnvChanged::new();
 
 /// Abstraction over environment variables
 trait Env {
@@ -41,6 +45,28 @@ impl Env for ProcessEnv {
     }
 }
 
+/// [`Env`] wrapper that implicitly calls [`rerun_if_env_changed`]
+struct RerunIfEnvChanged<E: Env>(E);
+
+impl RerunIfEnvChanged<ProcessEnv> {
+    const fn new() -> Self {
+        Self(ProcessEnv)
+    }
+}
+
+impl<E: Env> Env for RerunIfEnvChanged<E> {
+    #[track_caller]
+    fn get(&self, key: &str) -> Option<std::ffi::OsString> {
+        rerun_if_env_changed(key);
+        self.0.get(key)
+    }
+
+    #[track_caller]
+    fn is_present(&self, key: &str) -> bool {
+        self.get(key).is_some()
+    }
+}
+
 /// Path to the `cargo` binary performing the build.
 #[track_caller]
 pub fn cargo() -> PathBuf {
@@ -60,8 +86,7 @@ pub fn cargo_manifest_dir() -> PathBuf {
 /// The path to the manifest of your package.
 #[track_caller]
 pub fn cargo_manifest_path() -> PathBuf {
-    ProcessEnv
-        .get("CARGO_MANIFEST_PATH")
+    ENV.get("CARGO_MANIFEST_PATH")
         .map(to_path)
         .unwrap_or_else(|| {
             let mut path = cargo_manifest_dir();
@@ -73,7 +98,7 @@ pub fn cargo_manifest_path() -> PathBuf {
 /// The manifest `links` value.
 #[track_caller]
 pub fn cargo_manifest_links() -> Option<String> {
-    ProcessEnv.get("CARGO_MANIFEST_LINKS").map(to_string)
+    ENV.get("CARGO_MANIFEST_LINKS").map(to_string)
 }
 
 /// Contains parameters needed for Cargo’s [jobserver] implementation to parallelize
@@ -88,7 +113,7 @@ pub fn cargo_manifest_links() -> Option<String> {
 /// [jobserver]: https://www.gnu.org/software/make/manual/html_node/Job-Slots.html
 #[track_caller]
 pub fn cargo_makeflags() -> Option<String> {
-    ProcessEnv.get("CARGO_MAKEFLAGS").map(to_string)
+    ENV.get("CARGO_MAKEFLAGS").map(to_string)
 }
 
 /// For each activated feature of the package being built, this will be `true`.
@@ -99,7 +124,7 @@ pub fn cargo_feature(name: &str) -> bool {
     }
     let name = name.to_uppercase().replace('-', "_");
     let key = format!("CARGO_FEATURE_{name}");
-    ProcessEnv.is_present(&key)
+    ENV.is_present(&key)
 }
 
 /// For each [configuration option] of the package being built, this will contain
@@ -113,7 +138,7 @@ pub fn cargo_feature(name: &str) -> bool {
 #[track_caller]
 pub fn cargo_cfg(cfg: &str) -> Option<Vec<String>> {
     let var = cargo_cfg_var(cfg);
-    ProcessEnv.get(&var).map(|v| to_strings(v, ','))
+    ENV.get(&var).map(|v| to_strings(v, ','))
 }
 
 #[track_caller]
@@ -143,7 +168,7 @@ mod cfg {
     #[cfg(any())]
     #[track_caller]
     pub fn cargo_cfg_clippy() -> bool {
-        ProcessEnv.is_present("CARGO_CFG_CLIPPY")
+        ENV.is_present("CARGO_CFG_CLIPPY")
     }
 
     /// If we are compiling with debug assertions enabled.
@@ -154,25 +179,25 @@ mod cfg {
     #[cfg(any())]
     #[track_caller]
     pub fn cargo_cfg_debug_assertions() -> bool {
-        ProcessEnv.is_present("CARGO_CFG_DEBUG_ASSERTIONS")
+        ENV.is_present("CARGO_CFG_DEBUG_ASSERTIONS")
     }
 
     #[cfg(any())]
     #[track_caller]
     pub fn cargo_cfg_doc() -> bool {
-        ProcessEnv.is_present("CARGO_CFG_DOC")
+        ENV.is_present("CARGO_CFG_DOC")
     }
 
     #[cfg(any())]
     #[track_caller]
     pub fn cargo_cfg_docsrs() -> bool {
-        ProcessEnv.is_present("CARGO_CFG_DOCSRS")
+        ENV.is_present("CARGO_CFG_DOCSRS")
     }
 
     #[cfg(any())]
     #[track_caller]
     pub fn cargo_cfg_doctest() -> bool {
-        ProcessEnv.is_present("CARGO_CFG_DOCTEST")
+        ENV.is_present("CARGO_CFG_DOCTEST")
     }
 
     /// The level of detail provided by derived [`Debug`] implementations.
@@ -186,7 +211,7 @@ mod cfg {
     #[cfg(any())]
     #[track_caller]
     pub fn cargo_cfg_miri() -> bool {
-        ProcessEnv.is_present("CARGO_CFG_MIRI")
+        ENV.is_present("CARGO_CFG_MIRI")
     }
 
     /// If we are compiling with overflow checks enabled.
@@ -194,7 +219,7 @@ mod cfg {
     #[cfg(feature = "unstable")]
     #[track_caller]
     pub fn cargo_cfg_overflow_checks() -> bool {
-        ProcessEnv.is_present("CARGO_CFG_OVERFLOW_CHECKS")
+        ENV.is_present("CARGO_CFG_OVERFLOW_CHECKS")
     }
 
     /// The [panic strategy](https://doc.rust-lang.org/stable/reference/conditional-compilation.html#panic).
@@ -206,7 +231,7 @@ mod cfg {
     /// If the crate is being compiled as a procedural macro.
     #[track_caller]
     pub fn cargo_cfg_proc_macro() -> bool {
-        ProcessEnv.is_present("CARGO_CFG_PROC_MACRO")
+        ENV.is_present("CARGO_CFG_PROC_MACRO")
     }
 
     /// The target relocation model.
@@ -220,7 +245,7 @@ mod cfg {
     #[cfg(any())]
     #[track_caller]
     pub fn cargo_cfg_rustfmt() -> bool {
-        ProcessEnv.is_present("CARGO_CFG_RUSTFMT")
+        ENV.is_present("CARGO_CFG_RUSTFMT")
     }
 
     /// Sanitizers enabled for the crate being compiled.
@@ -228,9 +253,7 @@ mod cfg {
     #[cfg(feature = "unstable")]
     #[track_caller]
     pub fn cargo_cfg_sanitize() -> Option<Vec<String>> {
-        ProcessEnv
-            .get("CARGO_CFG_SANITIZE")
-            .map(|v| to_strings(v, ','))
+        ENV.get("CARGO_CFG_SANITIZE").map(|v| to_strings(v, ','))
     }
 
     /// If CFI sanitization is generalizing pointers.
@@ -238,7 +261,7 @@ mod cfg {
     #[cfg(feature = "unstable")]
     #[track_caller]
     pub fn cargo_cfg_sanitizer_cfi_generalize_pointers() -> bool {
-        ProcessEnv.is_present("CARGO_CFG_SANITIZER_CFI_GENERALIZE_POINTERS")
+        ENV.is_present("CARGO_CFG_SANITIZER_CFI_GENERALIZE_POINTERS")
     }
 
     /// If CFI sanitization is normalizing integers.
@@ -246,7 +269,7 @@ mod cfg {
     #[cfg(feature = "unstable")]
     #[track_caller]
     pub fn cargo_cfg_sanitizer_cfi_normalize_integers() -> bool {
-        ProcessEnv.is_present("CARGO_CFG_SANITIZER_CFI_NORMALIZE_INTEGERS")
+        ENV.is_present("CARGO_CFG_SANITIZER_CFI_NORMALIZE_INTEGERS")
     }
 
     /// Disambiguation of the [target ABI](https://doc.rust-lang.org/stable/reference/conditional-compilation.html#target_abi)
@@ -342,7 +365,7 @@ mod cfg {
     #[cfg(feature = "unstable")]
     #[track_caller]
     pub fn cargo_cfg_target_thread_local() -> bool {
-        ProcessEnv.is_present("CARGO_CFG_TARGET_THREAD_LOCAL")
+        ENV.is_present("CARGO_CFG_TARGET_THREAD_LOCAL")
     }
 
     /// The [target vendor](https://doc.rust-lang.org/stable/reference/conditional-compilation.html#target_vendor).
@@ -354,7 +377,7 @@ mod cfg {
     #[cfg(any())]
     #[track_caller]
     pub fn cargo_cfg_test() -> bool {
-        ProcessEnv.is_present("CARGO_CFG_TEST")
+        ENV.is_present("CARGO_CFG_TEST")
     }
 
     /// If we are compiling with UB checks enabled.
@@ -362,19 +385,19 @@ mod cfg {
     #[cfg(feature = "unstable")]
     #[track_caller]
     pub fn cargo_cfg_ub_checks() -> bool {
-        ProcessEnv.is_present("CARGO_CFG_UB_CHECKS")
+        ENV.is_present("CARGO_CFG_UB_CHECKS")
     }
 
     /// Set on [unix-like platforms](https://doc.rust-lang.org/stable/reference/conditional-compilation.html#unix-and-windows).
     #[track_caller]
     pub fn cargo_cfg_unix() -> bool {
-        ProcessEnv.is_present("CARGO_CFG_UNIX")
+        ENV.is_present("CARGO_CFG_UNIX")
     }
 
     /// Set on [windows-like platforms](https://doc.rust-lang.org/stable/reference/conditional-compilation.html#unix-and-windows).
     #[track_caller]
     pub fn cargo_cfg_windows() -> bool {
-        ProcessEnv.is_present("CARGO_CFG_WINDOWS")
+        ENV.is_present("CARGO_CFG_WINDOWS")
     }
 }
 
@@ -461,7 +484,7 @@ pub fn dep_metadata(name: &str, key: &str) -> Option<String> {
     let name = name.to_uppercase().replace('-', "_");
     let key = key.to_uppercase().replace('-', "_");
     let key = format!("DEP_{name}_{key}");
-    ProcessEnv.get(&key).map(to_string)
+    ENV.get(&key).map(to_string)
 }
 
 /// The compiler that Cargo has resolved to use.
@@ -481,7 +504,7 @@ pub fn rustdoc() -> PathBuf {
 /// [`build.rustc-wrapper`]: https://doc.rust-lang.org/stable/cargo/reference/config.html#buildrustc-wrapper
 #[track_caller]
 pub fn rustc_wrapper() -> Option<PathBuf> {
-    ProcessEnv.get("RUSTC_WRAPPER").map(to_path)
+    ENV.get("RUSTC_WRAPPER").map(to_path)
 }
 
 /// The rustc wrapper, if any, that Cargo is using for workspace members. See
@@ -490,7 +513,7 @@ pub fn rustc_wrapper() -> Option<PathBuf> {
 /// [`build.rustc-workspace-wrapper`]: https://doc.rust-lang.org/stable/cargo/reference/config.html#buildrustc-workspace-wrapper
 #[track_caller]
 pub fn rustc_workspace_wrapper() -> Option<PathBuf> {
-    ProcessEnv.get("RUSTC_WORKSPACE_WRAPPER").map(to_path)
+    ENV.get("RUSTC_WORKSPACE_WRAPPER").map(to_path)
 }
 
 /// The linker that Cargo has resolved to use for the current target, if specified.
@@ -498,7 +521,7 @@ pub fn rustc_workspace_wrapper() -> Option<PathBuf> {
 /// [`target.*.linker`]: https://doc.rust-lang.org/stable/cargo/reference/config.html#targettriplelinker
 #[track_caller]
 pub fn rustc_linker() -> Option<PathBuf> {
-    ProcessEnv.get("RUSTC_LINKER").map(to_path)
+    ENV.get("RUSTC_LINKER").map(to_path)
 }
 
 /// Extra flags that Cargo invokes rustc with. See [`build.rustflags`].
@@ -596,8 +619,7 @@ pub fn cargo_pkg_readme() -> Option<PathBuf> {
 
 #[track_caller]
 fn var_or_panic(key: &str) -> std::ffi::OsString {
-    ProcessEnv
-        .get(key)
+    ENV.get(key)
         .unwrap_or_else(|| panic!("cargo environment variable `{key}` is missing"))
 }