aboutsummaryrefslogtreecommitdiff
path: root/crates/proc_macro_srv/src/proc_macro/mod.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/proc_macro_srv/src/proc_macro/mod.rs')
-rw-r--r--crates/proc_macro_srv/src/proc_macro/mod.rs22
1 files changed, 22 insertions, 0 deletions
diff --git a/crates/proc_macro_srv/src/proc_macro/mod.rs b/crates/proc_macro_srv/src/proc_macro/mod.rs
index ee0dc9722..fc6e7344f 100644
--- a/crates/proc_macro_srv/src/proc_macro/mod.rs
+++ b/crates/proc_macro_srv/src/proc_macro/mod.rs
@@ -924,3 +924,25 @@ impl fmt::Debug for Literal {
924 self.0.fmt(f) 924 self.0.fmt(f)
925 } 925 }
926} 926}
927
928pub mod tracked_env {
929 use std::env::{self, VarError};
930 use std::ffi::OsStr;
931
932 /// Retrieve an environment variable and add it to build dependency info.
933 /// Build system executing the compiler will know that the variable was accessed during
934 /// compilation, and will be able to rerun the build when the value of that variable changes.
935 /// Besides the dependency tracking this function should be equivalent to `env::var` from the
936 /// standard library, except that the argument must be UTF-8.
937 pub fn var<K: AsRef<OsStr> + AsRef<str>>(key: K) -> Result<String, VarError> {
938 use std::ops::Deref;
939
940 let key: &str = key.as_ref();
941 let value = env::var(key);
942 super::bridge::client::FreeFunctions::track_env_var(
943 key,
944 value.as_ref().map(|t| t.deref()).ok(),
945 );
946 value
947 }
948}