mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-22 10:02:58 +00:00
Add some sysroot logging
This commit is contained in:
parent
9d3e616f82
commit
653dafa7b1
2 changed files with 18 additions and 8 deletions
|
@ -64,14 +64,15 @@ impl Sysroot {
|
||||||
self.by_name("proc_macro")
|
self.by_name("proc_macro")
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn crates<'a>(&'a self) -> impl Iterator<Item = SysrootCrate> + ExactSizeIterator + 'a {
|
pub fn crates(&self) -> impl Iterator<Item = SysrootCrate> + ExactSizeIterator + '_ {
|
||||||
self.crates.iter().map(|(id, _data)| id)
|
self.crates.iter().map(|(id, _data)| id)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Sysroot {
|
impl Sysroot {
|
||||||
|
/// Attempts to discover the toolchain's sysroot from the given `dir`.
|
||||||
pub fn discover(dir: &AbsPath, extra_env: &FxHashMap<String, String>) -> Result<Sysroot> {
|
pub fn discover(dir: &AbsPath, extra_env: &FxHashMap<String, String>) -> Result<Sysroot> {
|
||||||
tracing::debug!("Discovering sysroot for {}", dir.display());
|
tracing::debug!("discovering sysroot for {}", dir.display());
|
||||||
let sysroot_dir = discover_sysroot_dir(dir, extra_env)?;
|
let sysroot_dir = discover_sysroot_dir(dir, extra_env)?;
|
||||||
let sysroot_src_dir =
|
let sysroot_src_dir =
|
||||||
discover_sysroot_src_dir_or_add_component(&sysroot_dir, dir, extra_env)?;
|
discover_sysroot_src_dir_or_add_component(&sysroot_dir, dir, extra_env)?;
|
||||||
|
@ -83,11 +84,10 @@ impl Sysroot {
|
||||||
cargo_toml: &ManifestPath,
|
cargo_toml: &ManifestPath,
|
||||||
extra_env: &FxHashMap<String, String>,
|
extra_env: &FxHashMap<String, String>,
|
||||||
) -> Option<ManifestPath> {
|
) -> Option<ManifestPath> {
|
||||||
tracing::debug!("Discovering rustc source for {}", cargo_toml.display());
|
tracing::debug!("discovering rustc source for {}", cargo_toml.display());
|
||||||
let current_dir = cargo_toml.parent();
|
let current_dir = cargo_toml.parent();
|
||||||
discover_sysroot_dir(current_dir, extra_env)
|
let sysroot_dir = discover_sysroot_dir(current_dir, extra_env).ok()?;
|
||||||
.ok()
|
get_rustc_src(&sysroot_dir)
|
||||||
.and_then(|sysroot_dir| get_rustc_src(&sysroot_dir))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn with_sysroot_dir(sysroot_dir: AbsPathBuf) -> Result<Sysroot> {
|
pub fn with_sysroot_dir(sysroot_dir: AbsPathBuf) -> Result<Sysroot> {
|
||||||
|
@ -200,6 +200,7 @@ fn discover_sysroot_src_dir_or_add_component(
|
||||||
let mut rustup = Command::new(toolchain::rustup());
|
let mut rustup = Command::new(toolchain::rustup());
|
||||||
rustup.envs(extra_env);
|
rustup.envs(extra_env);
|
||||||
rustup.current_dir(current_dir).args(&["component", "add", "rust-src"]);
|
rustup.current_dir(current_dir).args(&["component", "add", "rust-src"]);
|
||||||
|
tracing::info!("adding rust-src component by {:?}", rustup);
|
||||||
utf8_stdout(rustup).ok()?;
|
utf8_stdout(rustup).ok()?;
|
||||||
get_rust_src(sysroot_path)
|
get_rust_src(sysroot_path)
|
||||||
})
|
})
|
||||||
|
@ -218,7 +219,7 @@ try installing the Rust source the same way you installed rustc",
|
||||||
fn get_rustc_src(sysroot_path: &AbsPath) -> Option<ManifestPath> {
|
fn get_rustc_src(sysroot_path: &AbsPath) -> Option<ManifestPath> {
|
||||||
let rustc_src = sysroot_path.join("lib/rustlib/rustc-src/rust/compiler/rustc/Cargo.toml");
|
let rustc_src = sysroot_path.join("lib/rustlib/rustc-src/rust/compiler/rustc/Cargo.toml");
|
||||||
let rustc_src = ManifestPath::try_from(rustc_src).ok()?;
|
let rustc_src = ManifestPath::try_from(rustc_src).ok()?;
|
||||||
tracing::debug!("Checking for rustc source code: {}", rustc_src.display());
|
tracing::debug!("checking for rustc source code: {}", rustc_src.display());
|
||||||
if fs::metadata(&rustc_src).is_ok() {
|
if fs::metadata(&rustc_src).is_ok() {
|
||||||
Some(rustc_src)
|
Some(rustc_src)
|
||||||
} else {
|
} else {
|
||||||
|
@ -228,7 +229,7 @@ fn get_rustc_src(sysroot_path: &AbsPath) -> Option<ManifestPath> {
|
||||||
|
|
||||||
fn get_rust_src(sysroot_path: &AbsPath) -> Option<AbsPathBuf> {
|
fn get_rust_src(sysroot_path: &AbsPath) -> Option<AbsPathBuf> {
|
||||||
let rust_src = sysroot_path.join("lib/rustlib/src/rust/library");
|
let rust_src = sysroot_path.join("lib/rustlib/src/rust/library");
|
||||||
tracing::debug!("Checking sysroot: {}", rust_src.display());
|
tracing::debug!("checking sysroot library: {}", rust_src.display());
|
||||||
if fs::metadata(&rust_src).is_ok() {
|
if fs::metadata(&rust_src).is_ok() {
|
||||||
Some(rust_src)
|
Some(rust_src)
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -209,6 +209,9 @@ impl ProjectWorkspace {
|
||||||
),
|
),
|
||||||
None => None,
|
None => None,
|
||||||
};
|
};
|
||||||
|
if let Some(sysroot) = &sysroot {
|
||||||
|
tracing::info!(src_root = %sysroot.src_root().display(), root = %sysroot.root().display(), "Using sysroot");
|
||||||
|
}
|
||||||
|
|
||||||
let rustc_dir = match &config.rustc_source {
|
let rustc_dir = match &config.rustc_source {
|
||||||
Some(RustcSource::Path(path)) => ManifestPath::try_from(path.clone()).ok(),
|
Some(RustcSource::Path(path)) => ManifestPath::try_from(path.clone()).ok(),
|
||||||
|
@ -217,6 +220,9 @@ impl ProjectWorkspace {
|
||||||
}
|
}
|
||||||
None => None,
|
None => None,
|
||||||
};
|
};
|
||||||
|
if let Some(rustc_dir) = &rustc_dir {
|
||||||
|
tracing::info!(rustc_dir = %rustc_dir.display(), "Using rustc source");
|
||||||
|
}
|
||||||
|
|
||||||
let rustc = match rustc_dir {
|
let rustc = match rustc_dir {
|
||||||
Some(rustc_dir) => Some({
|
Some(rustc_dir) => Some({
|
||||||
|
@ -277,6 +283,9 @@ impl ProjectWorkspace {
|
||||||
}
|
}
|
||||||
(None, None) => None,
|
(None, None) => None,
|
||||||
};
|
};
|
||||||
|
if let Some(sysroot) = &sysroot {
|
||||||
|
tracing::info!(src_root = %sysroot.src_root().display(), root = %sysroot.root().display(), "Using sysroot");
|
||||||
|
}
|
||||||
|
|
||||||
let rustc_cfg = rustc_cfg::get(None, target, extra_env);
|
let rustc_cfg = rustc_cfg::get(None, target, extra_env);
|
||||||
Ok(ProjectWorkspace::Json { project: project_json, sysroot, rustc_cfg })
|
Ok(ProjectWorkspace::Json { project: project_json, sysroot, rustc_cfg })
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue