Skip to content

WindowsSdk: Fix finding the _Instances directory when it's not in the default location #19926

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 12, 2024

Conversation

squeek502
Copy link
Collaborator

@squeek502 squeek502 commented May 10, 2024

Information about installed MSVC instances are stored in state.json files within a Packages/_Instances directory. The default location for this is %PROGRAMDATA%\Microsoft\VisualStudio\Packages\_Instances. However, it is possible for the Packages directory to be put somewhere else. In that case, the registry value HKLM\SOFTWARE\Microsoft\VisualStudio\Setup\CachePath is set and contains the path to the Packages directory.

Previously, WindowsSdk did not check that registry value. After this commit, the registry value HKLM\SOFTWARE\Microsoft\VisualStudio\Setup\CachePath is checked first, which matches what ISetupEnumInstances does (according to a Procmon log).

Some more context: https://ziggit.dev/t/how-to-correctly-compile-static-libraries-on-windows/4232/23


Also fixes KEY_WOW64_32KEY being set whenever opening a registry key. This was causing HKLM\SOFTWARE\WOW6432Node\Microsoft\VisualStudio\Setup to be attempted to be opened instead of HKLM\SOFTWARE\Microsoft\VisualStudio\Setup


Confirmed to fix the motivating use case: https://ziggit.dev/t/how-to-correctly-compile-static-libraries-on-windows/4232/34

squeek502 added 2 commits May 9, 2024 22:22
… default location

Information about installed MSVC instances are stored in `state.json` files within a `Packages/_Instances` directory. The default location for this is `%PROGRAMDATA%\Microsoft\VisualStudio\Packages\_Instances`. However, it is possible for the Packages directory to be put somewhere else. In that case, the registry value `HKLM\SOFTWARE\Microsoft\VisualStudio\Setup\CachePath` is set and contains the path to the Packages directory.

Previously, WindowsSdk did not check that registry value. After this commit, the registry value `HKLM\SOFTWARE\Microsoft\VisualStudio\Setup\CachePath` is checked first, which matches what ISetupEnumInstances does (according to a Procmon log).
Now, an options struct is used to determine whether or not KEY_WOW64_32KEY should be set when opening a registry key.
@andrewrk andrewrk merged commit e2ec54b into ziglang:master May 12, 2024
10 checks passed
@perillo
Copy link
Contributor

perillo commented May 14, 2024

@squeek502

Is the use of break :method<n> in the findInstancesDir function really necessary?
I think that a simple use of scoping should be enough.

Original

method1: {
    return findInstancesDirViaSetup(allocator) catch |err| switch (err) {
        error.OutOfMemory => |e| return e,
        error.PathNotFound => break :method1,
    };
}

Alternate (not tested)

{
    return findInstancesDirViaSetup(allocator) catch |err| switch (err) {
        error.OutOfMemory => |e| return e,
        error.PathNotFound => {},
    };
}

@squeek502
Copy link
Collaborator Author

The labeled blocks aren't necessary, but I thought they made things a bit more clear.

andrewrk added a commit that referenced this pull request May 22, 2024
WindowsSdk: Fix finding the _Instances directory when it's not in the default location
squeek502 added a commit to squeek502/resinator that referenced this pull request May 31, 2024
…non-standard location

Same changes as ziglang/zig#19926, but for standalone resinator's auto_includes implementation
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants