-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
windows_sdk.zig: Reinstate COM ISetupEnumInstances logic #16594
Conversation
IIUC, seems like this is the best approach to detect? I'll test it tomorrow in the morning too. Thank you so much! |
84f1222
to
f0b26c4
Compare
The C++ version of this code used this logic, and it turns out it is able to find some setups that the current registry/Vs7 methods cannot. For example, if only the "Build Tools for Visual Studio" are installed but not Visual Studio itself, then only the ISetupEnumInstances method seems to find it. Follow up to ziglang#15657, fixes a regression caused by moving from the C++ version to the Zig version
f0b26c4
to
8579f72
Compare
This patch does fix for 1 of my win11 pc which only have VS2019 build tool install. For my other window 11 pc with both VS2019 build tools and VS2022 community, it detects the VS2019 build tools with this fix(the zig master detected the VS2022). Zig previously with cpp code is also detect the VS2019 build tools which seems fine for me. For windows 11 pc with only VS2022 community, it does able to detect the lib (same output for both zig master & the libc_only) zig master 0.11.0-dev.4296+7e25fb4a4 PC with VS2019 build tools and VS2022
libc_only PC with VS2019 build tools and VS2022
zig master & libc_only PC with VS2022 community only
|
@sgwong, thanks for testing. Right now this (and the old C++ version) only checks the first installation path returned from Will update |
Before, iteration would stop whenever an installation with vcruntime.lib was found, but that may not be the most recent installed version. Instead, we now iterate all installed instances and choose the one with the newest version.
@sgwong here's an updated Let me know what your results are with that. |
This is the latest output on pc with multiple build tools and VS installation. It does find the latest VS2022 now.
|
There might be another way to detect this without using COM API.local function get_latest_vs_install_path()
local instances_dir = "C:\\ProgramData\\Microsoft\\VisualStudio\\Packages\\_Instances\\"
local instance_ids = {}
for instance in io.popen('dir "' .. instances_dir .. '" /b /ad'):lines() do
table.insert(instance_ids, instance)
end
local newest_version = "0.0.0"
local newest_path = nil
for _, instance_id in ipairs(instance_ids) do
local state_path = instances_dir .. instance_id .. "\\state.json"
local file = io.open(state_path, "r")
if file then
local content = file:read("*all")
file:close()
local version = content:match('"buildVersion"%s-:%s-"(.-)%+')
local path = content:match('"installationPath"%s-:%s-"(.-)"')
if version and path and version > newest_version then
newest_version = version
newest_path = path
end
end
end |
Visual Studio Community 2022 with MSVC 143 (C++ build tools, C++ libraries and Visual C++ stuff), MSBuild support for Clang/LLVM, UCRT package, MSVC 140 (build tools only), two windows 10 sdks: # The directory that contains `stdlib.h`.
# On POSIX-like systems, include directories be found with: `cc -E -Wp,-v -xc /dev/null`
include_dir=C:\Program Files (x86)\Windows Kits\10\Include\10.0.20348.0\ucrt
# The system-specific include directory. May be the same as `include_dir`.
# On Windows it's the directory that includes `vcruntime.h`.
# On POSIX it's the directory that includes `sys/errno.h`.
sys_include_dir=C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.35.32215\include
# The directory that contains `crt1.o` or `crt2.o`.
# On POSIX, can be found with `cc -print-file-name=crt1.o`.
# Not needed when targeting MacOS.
crt_dir=C:\Program Files (x86)\Windows Kits\10\Lib\10.0.20348.0\ucrt\x64
# The directory that contains `vcruntime.lib`.
# Only needed when targeting MSVC on Windows.
msvc_lib_dir=C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.35.32215\Lib\x64
# The directory that contains `kernel32.lib`.
# Only needed when targeting MSVC on Windows.
kernel32_lib_dir=C:\Program Files (x86)\Windows Kits\10\Lib\10.0.20348.0\um\x64
# The directory that contains `crtbeginS.o` and `crtendS.o`
# Only needed when targeting Haiku.
gcc_dir= This branch: [debug] Found version: 17.5.33627.172 (4785098282696876L)
# The directory that contains `stdlib.h`.
# On POSIX-like systems, include directories be found with: `cc -E -Wp,-v -xc /dev/null`
include_dir=C:\Program Files (x86)\Windows Kits\10\Include\10.0.20348.0\ucrt
# The system-specific include directory. May be the same as `include_dir`.
# On Windows it's the directory that includes `vcruntime.h`.
# On POSIX it's the directory that includes `sys/errno.h`.
sys_include_dir=C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.35.32215\include
# The directory that contains `crt1.o` or `crt2.o`.
# On POSIX, can be found with `cc -print-file-name=crt1.o`.
# Not needed when targeting MacOS.
crt_dir=C:\Program Files (x86)\Windows Kits\10\Lib\10.0.20348.0\ucrt\x64
# The directory that contains `vcruntime.lib`.
# Only needed when targeting MSVC on Windows.
msvc_lib_dir=C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.35.32215\Lib\x64
# The directory that contains `kernel32.lib`.
# Only needed when targeting MSVC on Windows.
kernel32_lib_dir=C:\Program Files (x86)\Windows Kits\10\Lib\10.0.20348.0\um\x64
# The directory that contains `crtbeginS.o` and `crtendS.o`
# Only needed when targeting Haiku.
gcc_dir= (same result) Everything as in above, but without IDE: This branch: (regression fixed!) |
IDK what happened, but after rebooting [debug] Found version: 17.6.33829.357 (4785102590902629L)
error: unable to detect native libc: LibCStdLibHeaderNotFound Previously, it printed like on master with IDE. Maybe after rebooting IDE finished uninstalling or smth similar, IDK. |
After another rebooting, it suddenly started to work again (but with slightly different path for MSVC): [debug] Found version: 17.5.33627.172 (4785098282696876L)
# The directory that contains `stdlib.h`.
# On POSIX-like systems, include directories be found with: `cc -E -Wp,-v -xc /dev/null`
include_dir=C:\Program Files (x86)\Windows Kits\10\Include\10.0.20348.0\ucrt
# The system-specific include directory. May be the same as `include_dir`.
# On Windows it's the directory that includes `vcruntime.h`.
# On POSIX it's the directory that includes `sys/errno.h`.
sys_include_dir=C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Tools\MSVC\14.35.32215\include
# The directory that contains `crt1.o` or `crt2.o`.
# On POSIX, can be found with `cc -print-file-name=crt1.o`.
# Not needed when targeting MacOS.
crt_dir=C:\Program Files (x86)\Windows Kits\10\Lib\10.0.20348.0\ucrt\x64
# The directory that contains `vcruntime.lib`.
# Only needed when targeting MSVC on Windows.
msvc_lib_dir=C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Tools\MSVC\14.35.32215\Lib\x64
# The directory that contains `kernel32.lib`.
# Only needed when targeting MSVC on Windows.
kernel32_lib_dir=C:\Program Files (x86)\Windows Kits\10\Lib\10.0.20348.0\um\x64
# The directory that contains `crtbeginS.o` and `crtendS.o`
# Only needed when targeting Haiku.
gcc_dir= |
@yuyoyuppe using ProcessMonitor, it looks like that's what the COM stuff is doing internally: Good to know, but might as well use the COM stuff since the code is already written now and is the recommended-by-Microsoft way of doing it. |
The C++ version of this code used this logic, and it turns out it is able to find some setups that the current registry/Vs7 methods cannot.
For example, if only the "Build Tools for Visual Studio" are installed but not Visual Studio itself, then only the ISetupEnumInstances method seems to find it.
Follow up to #15657, fixes a regression caused by moving from the C++ version to the Zig version
Needs some testing for sure. I've only tested it on one setup with only the build tools installed so far.
Here's a build of
libc_only.exe
(detailed here: #15657 (comment)) if anyone wants to test their setup:libc_only-20230728.zip
Otherwise, to test this, build this branch and run
zig libc
Before, with only the build tools installed:
After:
cc @BratishkaErik