Skip to content

Commit 82ac6f7

Browse files
committed
Auto merge of rust-lang#13441 - Veykril:sysroot-logging, r=Veykril
Add some sysroot logging
2 parents 3392573 + 653dafa commit 82ac6f7

File tree

2 files changed

+18
-8
lines changed

2 files changed

+18
-8
lines changed

crates/project-model/src/sysroot.rs

+9-8
Original file line numberDiff line numberDiff line change
@@ -64,14 +64,15 @@ impl Sysroot {
6464
self.by_name("proc_macro")
6565
}
6666

67-
pub fn crates<'a>(&'a self) -> impl Iterator<Item = SysrootCrate> + ExactSizeIterator + 'a {
67+
pub fn crates(&self) -> impl Iterator<Item = SysrootCrate> + ExactSizeIterator + '_ {
6868
self.crates.iter().map(|(id, _data)| id)
6969
}
7070
}
7171

7272
impl Sysroot {
73+
/// Attempts to discover the toolchain's sysroot from the given `dir`.
7374
pub fn discover(dir: &AbsPath, extra_env: &FxHashMap<String, String>) -> Result<Sysroot> {
74-
tracing::debug!("Discovering sysroot for {}", dir.display());
75+
tracing::debug!("discovering sysroot for {}", dir.display());
7576
let sysroot_dir = discover_sysroot_dir(dir, extra_env)?;
7677
let sysroot_src_dir =
7778
discover_sysroot_src_dir_or_add_component(&sysroot_dir, dir, extra_env)?;
@@ -83,11 +84,10 @@ impl Sysroot {
8384
cargo_toml: &ManifestPath,
8485
extra_env: &FxHashMap<String, String>,
8586
) -> Option<ManifestPath> {
86-
tracing::debug!("Discovering rustc source for {}", cargo_toml.display());
87+
tracing::debug!("discovering rustc source for {}", cargo_toml.display());
8788
let current_dir = cargo_toml.parent();
88-
discover_sysroot_dir(current_dir, extra_env)
89-
.ok()
90-
.and_then(|sysroot_dir| get_rustc_src(&sysroot_dir))
89+
let sysroot_dir = discover_sysroot_dir(current_dir, extra_env).ok()?;
90+
get_rustc_src(&sysroot_dir)
9191
}
9292

9393
pub fn with_sysroot_dir(sysroot_dir: AbsPathBuf) -> Result<Sysroot> {
@@ -200,6 +200,7 @@ fn discover_sysroot_src_dir_or_add_component(
200200
let mut rustup = Command::new(toolchain::rustup());
201201
rustup.envs(extra_env);
202202
rustup.current_dir(current_dir).args(&["component", "add", "rust-src"]);
203+
tracing::info!("adding rust-src component by {:?}", rustup);
203204
utf8_stdout(rustup).ok()?;
204205
get_rust_src(sysroot_path)
205206
})
@@ -218,7 +219,7 @@ try installing the Rust source the same way you installed rustc",
218219
fn get_rustc_src(sysroot_path: &AbsPath) -> Option<ManifestPath> {
219220
let rustc_src = sysroot_path.join("lib/rustlib/rustc-src/rust/compiler/rustc/Cargo.toml");
220221
let rustc_src = ManifestPath::try_from(rustc_src).ok()?;
221-
tracing::debug!("Checking for rustc source code: {}", rustc_src.display());
222+
tracing::debug!("checking for rustc source code: {}", rustc_src.display());
222223
if fs::metadata(&rustc_src).is_ok() {
223224
Some(rustc_src)
224225
} else {
@@ -228,7 +229,7 @@ fn get_rustc_src(sysroot_path: &AbsPath) -> Option<ManifestPath> {
228229

229230
fn get_rust_src(sysroot_path: &AbsPath) -> Option<AbsPathBuf> {
230231
let rust_src = sysroot_path.join("lib/rustlib/src/rust/library");
231-
tracing::debug!("Checking sysroot: {}", rust_src.display());
232+
tracing::debug!("checking sysroot library: {}", rust_src.display());
232233
if fs::metadata(&rust_src).is_ok() {
233234
Some(rust_src)
234235
} else {

crates/project-model/src/workspace.rs

+9
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,9 @@ impl ProjectWorkspace {
209209
),
210210
None => None,
211211
};
212+
if let Some(sysroot) = &sysroot {
213+
tracing::info!(src_root = %sysroot.src_root().display(), root = %sysroot.root().display(), "Using sysroot");
214+
}
212215

213216
let rustc_dir = match &config.rustc_source {
214217
Some(RustcSource::Path(path)) => ManifestPath::try_from(path.clone()).ok(),
@@ -217,6 +220,9 @@ impl ProjectWorkspace {
217220
}
218221
None => None,
219222
};
223+
if let Some(rustc_dir) = &rustc_dir {
224+
tracing::info!(rustc_dir = %rustc_dir.display(), "Using rustc source");
225+
}
220226

221227
let rustc = match rustc_dir {
222228
Some(rustc_dir) => Some({
@@ -277,6 +283,9 @@ impl ProjectWorkspace {
277283
}
278284
(None, None) => None,
279285
};
286+
if let Some(sysroot) = &sysroot {
287+
tracing::info!(src_root = %sysroot.src_root().display(), root = %sysroot.root().display(), "Using sysroot");
288+
}
280289

281290
let rustc_cfg = rustc_cfg::get(None, target, extra_env);
282291
Ok(ProjectWorkspace::Json { project: project_json, sysroot, rustc_cfg })

0 commit comments

Comments
 (0)