project-model: when using rust-project.json, prefer the sysroot-defined rustc over an env-based one

This commit is contained in:
David Barsky 2023-09-05 15:21:14 -04:00
parent f29867bd26
commit 5b5bce8aaf
3 changed files with 41 additions and 12 deletions

View file

@ -115,10 +115,19 @@ impl Sysroot {
Ok(Sysroot::load(sysroot_dir, src))
}
pub fn discover_rustc(&self) -> Option<ManifestPath> {
pub fn discover_rustc_src(&self) -> Option<ManifestPath> {
get_rustc_src(&self.root)
}
pub fn discover_rustc(&self) -> Result<AbsPathBuf, std::io::Error> {
let rustc = self.root.join("bin/rustc");
tracing::debug!(?rustc, "checking for rustc binary at location");
match fs::metadata(&rustc) {
Ok(_) => Ok(rustc),
Err(e) => Err(e),
}
}
pub fn with_sysroot_dir(sysroot_dir: AbsPathBuf) -> Result<Sysroot> {
let sysroot_src_dir = discover_sysroot_src_dir(&sysroot_dir).ok_or_else(|| {
format_err!("can't load standard library from sysroot path {sysroot_dir}")