aboutsummaryrefslogtreecommitdiff
path: root/crates/proc_macro_srv/src/proc_macro/mod.rs
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2020-10-08 15:27:30 +0100
committerGitHub <[email protected]>2020-10-08 15:27:30 +0100
commite6a05e6566014d95cec416b5203fdf52bb8ac09c (patch)
tree6a2b183ddbcf674c7503b5646548610ee223a470 /crates/proc_macro_srv/src/proc_macro/mod.rs
parente95e666b106b2f63ab2b350e656c9e8b96441fa7 (diff)
parent3d169bd3f4cdc2dc3dd09eadbbc17c19214d69f3 (diff)
Merge #5651
5651: Add track_env_var to the proc macro server r=kjeremy a=lnicola See https://github.com/rust-lang/rust/pull/74653. Fixes #6054. Fixes #5640, maybe. Should be merged when 1.47 is released. Proc macros still don't work for me, but it no longer crashes. Co-authored-by: LaurenČ›iu Nicola <[email protected]>
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}