Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/bootstrap/Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ dependencies = [
"tracing-subscriber",
"walkdir",
"windows 0.61.1",
"windows-registry",
"xz2",
]

Expand Down Expand Up @@ -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"
Expand Down
3 changes: 3 additions & 0 deletions src/bootstrap/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Comment on lines +69 to +70

@ChrisDenton ChrisDenton Jul 3, 2026

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This does add a new dependency to bootstrap. Technically we could reuse the windows crate (it's only a couple of functions) but at the cost of doing the FFI ourselves.

View changes since the review


[target.'cfg(windows)'.dependencies.junction]
version = "1.3.0"

Expand Down
35 changes: 23 additions & 12 deletions src/bootstrap/src/core/debuggers/cdb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Cdb> {
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") {
Expand All @@ -28,14 +25,28 @@ pub(crate) fn discover_cdb(target: TargetSelection) -> Option<Cdb> {
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<PathBuf> {
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<PathBuf> {
None
}

fn discover_cdb_program_files(cdb_arch: &'static str) -> Option<PathBuf> {
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)
}
Loading