cargo_fixit/core/sysroot.rs
1use std::{path::PathBuf, process::Command, sync::OnceLock};
2
3static SYSROOT: OnceLock<Option<PathBuf>> = OnceLock::new();
4
5pub(crate) fn get_sysroot() -> &'static Option<PathBuf> {
6 SYSROOT.get_or_init(|| {
7 Command::new("rustc")
8 .arg("--print=sysroot")
9 .output()
10 .map(|x| String::from_utf8_lossy(&x.stdout).trim().to_owned())
11 .map(PathBuf::from)
12 .ok()
13 })
14}