From 1e7c81b2d9a20ad6cae8b938a4d8fb1b34c83808 Mon Sep 17 00:00:00 2001 From: Chris Denton Date: Fri, 3 Jul 2026 17:44:58 +0000 Subject: [PATCH] Look for cdb location in the registry first This is more robust then assuming it's in Program Files. We still fallback to Program Files as a last resort. --- src/bootstrap/Cargo.lock | 12 +++++++++ src/bootstrap/Cargo.toml | 3 +++ src/bootstrap/src/core/debuggers/cdb.rs | 35 ++++++++++++++++--------- 3 files changed, 38 insertions(+), 12 deletions(-) diff --git a/src/bootstrap/Cargo.lock b/src/bootstrap/Cargo.lock index 7c890e3f2004c..f988d207529b6 100644 --- a/src/bootstrap/Cargo.lock +++ b/src/bootstrap/Cargo.lock @@ -71,6 +71,7 @@ dependencies = [ "tracing-subscriber", "walkdir", "windows 0.61.1", + "windows-registry", "xz2", ] @@ -1095,6 +1096,17 @@ dependencies = [ "windows-link 0.2.1", ] +[[package]] +name = "windows-registry" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "02752bf7fbdcce7f2a27a742f798510f3e5ad88dbe84871e5168e2120c3d5720" +dependencies = [ + "windows-link 0.2.1", + "windows-result 0.4.1", + "windows-strings 0.5.1", +] + [[package]] name = "windows-result" version = "0.3.2" diff --git a/src/bootstrap/Cargo.toml b/src/bootstrap/Cargo.toml index 60e52102dc46b..b2e8c42adf48b 100644 --- a/src/bootstrap/Cargo.toml +++ b/src/bootstrap/Cargo.toml @@ -66,6 +66,9 @@ tracing = { version = "0.1", optional = true, features = ["attributes"] } tracing-chrome = { version = "0.7", optional = true } tracing-subscriber = { version = "0.3", optional = true, features = ["env-filter", "fmt", "registry", "std"] } +[target.'cfg(windows)'.dependencies.windows-registry] +version = "0.6" + [target.'cfg(windows)'.dependencies.junction] version = "1.3.0" diff --git a/src/bootstrap/src/core/debuggers/cdb.rs b/src/bootstrap/src/core/debuggers/cdb.rs index a19b70477ecfe..7f835f3618724 100644 --- a/src/bootstrap/src/core/debuggers/cdb.rs +++ b/src/bootstrap/src/core/debuggers/cdb.rs @@ -7,15 +7,12 @@ pub(crate) struct Cdb { pub(crate) cdb: PathBuf, } -/// FIXME: This CDB discovery code was very questionable when it was in -/// compiletest, and it's just as questionable now that it's in bootstrap. +/// We consult the registry to find the installed cdb.exe and try "Program Files" if that fails. pub(crate) fn discover_cdb(target: TargetSelection) -> Option { if !cfg!(windows) || !target.ends_with("-pc-windows-msvc") { return None; } - let pf86 = - PathBuf::from(env::var_os("ProgramFiles(x86)").or_else(|| env::var_os("ProgramFiles"))?); let cdb_arch = if cfg!(target_arch = "x86") { "x86" } else if cfg!(target_arch = "x86_64") { @@ -28,14 +25,28 @@ pub(crate) fn discover_cdb(target: TargetSelection) -> Option { return None; // No compatible CDB.exe in the Windows 10 SDK }; - let mut path = pf86; - path.push(r"Windows Kits\10\Debuggers"); // We could check 8.1 etc. too? - path.push(cdb_arch); - path.push(r"cdb.exe"); + let path = discover_cdb_registry(cdb_arch).or_else(|| discover_cdb_program_files(cdb_arch))?; + Some(Cdb { cdb: path }) +} - if !path.exists() { - return None; - } +#[cfg(windows)] +fn discover_cdb_registry(cdb_arch: &'static str) -> Option { + use windows_registry::LOCAL_MACHINE; + let roots = LOCAL_MACHINE.open(r"SOFTWARE\Microsoft\Windows Kits\Installed Roots").ok()?; + // "KitsRoot10" is used by both the Windows 10 and 11 SDKs. + let mut path: PathBuf = roots.get_string("KitsRoot10").ok()?.into(); + path.extend([r"Debuggers", cdb_arch, r"cdb.exe"]); + path.exists().then_some(path) +} - Some(Cdb { cdb: path }) +#[cfg(not(windows))] +fn discover_cdb_registry(_cdb_arch: &'static str) -> Option { + None +} + +fn discover_cdb_program_files(cdb_arch: &'static str) -> Option { + let mut path = + PathBuf::from(env::var_os("ProgramFiles(x86)").or_else(|| env::var_os("ProgramFiles"))?); + path.extend([r"Windows Kits\10\Debuggers", cdb_arch, r"cdb.exe"]); + path.exists().then_some(path) }