facebook / buck2

Build system, successor to Buck
https://buck2.build/
Apache License 2.0
3.52k stars 215 forks source link

[Build Error][Getting Started] File Path Mismatch in Registry Value (value from `get_ucrt_dir` vs actual value) #405

Open miknai opened 1 year ago

miknai commented 1 year ago

TL;DR The file path from get_ucrt_dir didn't match the file path from the used registry value in my PC (Windows OS).

I was stepping through the Getting Started page as a new Buck2 user. Even though followed every step, I encountered the error saying FileNotFoundError: [WinError 3] The system cannot find the path specified: 'C:\\Program Files\\Windows Kits\\10\\Lib' while doing buck2 build //:main. I took a look at vswhere.py code below and found out that the file path that get_ucrt_dir function finds with KitsRoot10 registry key was different from the actual file path that has the library folder it looks for in my PC.

Expected file path from `get_ucrt_dir`: C:\Program Files\Windows Kits\10
The actual file path for the Windows Kits: C:\Program Files (x86)\Windows Kits\10

I updated the registry value on my PC, so now the buck2 build works fine. Maybe, a warning should be added in the Getting Started instruction in case other folks get into a similar situation.

# <path>\buck2\examples\hello_world\prelude\toolchains\msvc\vswhere.py
def get_ucrt_dir():
    registry = winreg.ConnectRegistry(None, winreg.HKEY_LOCAL_MACHINE)
    key_name = "SOFTWARE\\Microsoft\\Windows Kits\\Installed Roots"
    registry_key = winreg.OpenKey(registry, key_name)
    kits_root = Path(winreg.QueryValueEx(registry_key, "KitsRoot10")[0])

    available_versions = [
        entry.name
        for entry in kits_root.joinpath("lib").iterdir()
        if entry.name.startswith("10.") and entry.joinpath("ucrt").is_dir()
    ]

    max_version = max(available_versions) if available_versions else None
    return kits_root, max_version
KapJI commented 1 year ago

Did you install toolchain with Visual Studio installer? We expect it to add these registry keys.

miknai commented 1 year ago

@KapJI Yes, the toolchain was installed via VS installer before I got the error.

alexlian commented 1 year ago

Expected file path from get_ucrt_dir: C:\Program Files\Windows Kits\10 The actual file path for the Windows Kits: C:\Program Files (x86)\Windows Kits\10

Wondering if it's the 64 bit vs 32 bit registry? Is it different under the WOW6432Node?