Skip to content

Commit a75c9d4

Browse files
committed
Don't print env vars repeatedly
Use an internal cache to avoid printing repeatedly what env vars are loaded, hopefully only doing this once-per-`Build`!
1 parent ee6daa7 commit a75c9d4

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

src/lib.rs

+7
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ pub struct Build {
118118
warnings_into_errors: bool,
119119
warnings: Option<bool>,
120120
extra_warnings: Option<bool>,
121+
env_cache: Arc<Mutex<HashMap<String, Option<String>>>>,
121122
}
122123

123124
/// Represents the types of errors that may occur while using cc-rs.
@@ -322,6 +323,7 @@ impl Build {
322323
warnings: None,
323324
extra_warnings: None,
324325
warnings_into_errors: false,
326+
env_cache: Arc::new(Mutex::new(HashMap::new())),
325327
}
326328
}
327329

@@ -1963,8 +1965,13 @@ impl Build {
19631965
}
19641966

19651967
fn getenv(&self, v: &str) -> Option<String> {
1968+
let mut cache = self.env_cache.lock().unwrap();
1969+
if let Some(val) = cache.get(v) {
1970+
return val.clone()
1971+
}
19661972
let r = env::var(v).ok();
19671973
self.print(&format!("{} = {:?}", v, r));
1974+
cache.insert(v.to_string(), r.clone());
19681975
r
19691976
}
19701977

0 commit comments

Comments
 (0)