build: select a VS instance with the x64 C++ toolset among all installs #485

Manually merged
github merged 1 commit from gh-pr/485/head into gh-pr/485/base 2026-11-26 21:55:39 +00:00
Owner

@⁠FZNull on GitHub · 2026-11-22 06:47 UTC · original
FZNull:build/dev-ps1-vswhere-all-instances → main · +17 −1 · 1 files · 1 commits · merged 2026-11-22 07:10 UTC

Change

tools/dev.ps1 picks a Visual Studio installation with vswhere -latest -requires for both the x64 C++ toolset and the CMake component. A machine that installs CMake and Ninja from a package manager but has no VS CMake component fails that query even though a usable toolset instance exists, and the script throws the install error.

This change adds a fallback for that case: when no instance satisfies the combined requirement, query again for the x64 C++ toolset alone and pick the newest instance that actually ships Common7\Tools\Launch-VsDevShell.ps1. The primary query keeps -latest -products '*' -requires unchanged.

Reproduction

Environment: Visual Studio Community 2026 (18.9, no C++ workload) and Visual Studio Build Tools 2026 (18.4, MSVC 14.50.35717, no CMake component), CMake 4.5.1 and Ninja 1.13.2 from scoop, Windows SDK 10.0.26100.0, DXC 1.9.2609.5, Python 3.13.12, Windows 11 build 26300.9974.

On this two-install setup:

Query Result
-latest -products '*' -requires Microsoft.VisualStudio.Component.VC.Tools.x86.x64 Microsoft.VisualStudio.Component.VC.CMake.Project nothing
-latest -products '*' -requires Microsoft.VisualStudio.Component.VC.Tools.x86.x64 nothing — the Build Tools instance is incomplete to vswhere, so it is excluded without -all
-all -sort -products '*' -requires Microsoft.VisualStudio.Component.VC.Tools.x86.x64 C:\Program Files (x86)\Microsoft Visual Studio\18\BuildTools

Because the toolset-only -latest query returns nothing here, the fallback lists incomplete instances with -all -sort and then verifies that Common7\Tools\Launch-VsDevShell.ps1 exists, so an incomplete installation without a usable environment is never handed to the caller.

Before the change, .\tools\dev.ps1 threw the install error above even though the toolchain was present.

With the change, .\tools\dev.ps1 opens the Build Tools developer shell and configure, build and test succeed:

.\tools\dev.ps1
cmake --preset dev -DDXC_EXECUTABLE=C:/path/to/dxc/bin/x64/dxc.exe
cmake --build --preset dev
ctest --preset dev --no-tests=error
100% tests passed out of 198
The following tests did not run:
	 53 - bvh_wave64_hardware (Skipped)
	 77 - bvh_wave64_warp (Skipped)
	 83 - wave_shuffle_warp (Skipped)

Notes

  • Backward compatible: when an installation satisfies the combined requirement, the primary -latest query selects it exactly as before and the fallback never runs.
  • The fallback only changes machines where the old script refused to run at all.

AI-assisted.

**@⁠FZNull** on GitHub · 2026-11-22 06:47 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/485) `FZNull:build/dev-ps1-vswhere-all-instances` → `main` · +17 −1 · 1 files · 1 commits · merged 2026-11-22 07:10 UTC ## Change `tools/dev.ps1` picks a Visual Studio installation with `vswhere -latest -requires` for both the x64 C++ toolset and the CMake component. A machine that installs CMake and Ninja from a package manager but has no VS CMake component fails that query even though a usable toolset instance exists, and the script throws the install error. This change adds a fallback for that case: when no instance satisfies the combined requirement, query again for the x64 C++ toolset alone and pick the newest instance that actually ships `Common7\Tools\Launch-VsDevShell.ps1`. The primary query keeps `-latest -products '*' -requires` unchanged. ## Reproduction Environment: Visual Studio Community 2026 (18.9, no C++ workload) and Visual Studio Build Tools 2026 (18.4, MSVC 14.50.35717, no CMake component), CMake 4.5.1 and Ninja 1.13.2 from scoop, Windows SDK 10.0.26100.0, DXC 1.9.2609.5, Python 3.13.12, Windows 11 build 26300.9974. On this two-install setup: | Query | Result | |---|---| | `-latest -products '*' -requires Microsoft.VisualStudio.Component.VC.Tools.x86.x64 Microsoft.VisualStudio.Component.VC.CMake.Project` | nothing | | `-latest -products '*' -requires Microsoft.VisualStudio.Component.VC.Tools.x86.x64` | nothing — the Build Tools instance is incomplete to vswhere, so it is excluded without `-all` | | `-all -sort -products '*' -requires Microsoft.VisualStudio.Component.VC.Tools.x86.x64` | `C:\Program Files (x86)\Microsoft Visual Studio\18\BuildTools` | Because the toolset-only `-latest` query returns nothing here, the fallback lists incomplete instances with `-all -sort` and then verifies that `Common7\Tools\Launch-VsDevShell.ps1` exists, so an incomplete installation without a usable environment is never handed to the caller. Before the change, `.\tools\dev.ps1` threw the install error above even though the toolchain was present. With the change, `.\tools\dev.ps1` opens the Build Tools developer shell and configure, build and test succeed: ```powershell .\tools\dev.ps1 cmake --preset dev -DDXC_EXECUTABLE=C:/path/to/dxc/bin/x64/dxc.exe cmake --build --preset dev ctest --preset dev --no-tests=error ``` ```text 100% tests passed out of 198 The following tests did not run: 53 - bvh_wave64_hardware (Skipped) 77 - bvh_wave64_warp (Skipped) 83 - wave_shuffle_warp (Skipped) ``` ## Notes - Backward compatible: when an installation satisfies the combined requirement, the primary `-latest` query selects it exactly as before and the fallback never runs. - The fallback only changes machines where the old script refused to run at all. AI-assisted.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 21:55:38 +00:00
github manually merged commit dc406e45c7 into gh-pr/485/base 2026-11-26 21:55:39 +00:00
Author
Owner

@⁠R0Y00 on GitHub · 2026-11-22 06:57 UTC · original

The fallback for an external CMake/Ninja installation addresses the reported setup. The local vswhere -? confirms -all also includes incomplete installations, so selecting the first result can hand Launch-VsDevShell.ps1 an unusable instance. Please keep -latest -products '*' -requires on both queries, and change only the required components in the fallback. On your two-install setup, please confirm the combined query returns nothing and the VC-only query returns the Build Tools path. That isolates the fix and preserves the original launchable-instance filter.

**@⁠R0Y00** on GitHub · 2026-11-22 06:57 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/485#issuecomment-7075626846) The fallback for an external CMake/Ninja installation addresses the reported setup. The local `vswhere -?` confirms `-all` also includes incomplete installations, so selecting the first result can hand `Launch-VsDevShell.ps1` an unusable instance. Please keep `-latest -products '*' -requires` on both queries, and change only the required components in the fallback. On your two-install setup, please confirm the combined query returns nothing and the VC-only query returns the Build Tools path. That isolates the fix and preserves the original launchable-instance filter.
Author
Owner

@⁠FZNull on GitHub · 2026-11-22 07:06 UTC · original

Thanks — here are the exact results on the two-install setup (Visual Studio Community 2026 18.9 without the C++ workload, and Visual Studio Build Tools 2026 18.4 with MSVC 14.50.35717 but no CMake component):

$vswhere = "${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\vswhere.exe"
& $vswhere -latest -products '*' -requires Microsoft.VisualStudio.Component.VC.Tools.x86.x64 Microsoft.VisualStudio.Component.VC.CMake.Project -property installationPath
# -> nothing (confirmed)

& $vswhere -latest -products '*' -requires Microsoft.VisualStudio.Component.VC.Tools.x86.x64 -property installationPath
# -> nothing as well. The Build Tools instance reports isComplete=False, so vswhere
#    excludes it from queries without -all.

& $vswhere -all -sort -products '*' -requires Microsoft.VisualStudio.Component.VC.Tools.x86.x64 -property installationPath
# -> C:\Program Files (x86)\Microsoft Visual Studio\18\BuildTools

So on this setup a -latest toolset-only query cannot return the Build Tools path. The branch therefore keeps the primary query exactly as before (-latest -products '*' -requires with both components) and changes the fallback to a toolset-only -all -sort query, followed by a check that Common7\Tools\Launch-VsDevShell.ps1 exists before the instance is selected. That keeps the fallback from handing an unusable incomplete installation to the launcher while still finding the usable one here.

With the pushed commit dc406e4, .\tools\dev.ps1 opens the Build Tools developer shell (VSINSTALLDIR points at the Build Tools instance, cl/cmake/ninja resolve) and the configure/build/test results in the PR body are unchanged. The PR description now records the query table above.

If you would rather the fallback stay -latest only, I can keep it and instead skip the fallback on this setup — but then the script still refuses a machine with a working toolset, which is what this PR set out to fix. Happy to adjust either way.

**@⁠FZNull** on GitHub · 2026-11-22 07:06 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/485#issuecomment-7075717125) Thanks — here are the exact results on the two-install setup (Visual Studio Community 2026 18.9 without the C++ workload, and Visual Studio Build Tools 2026 18.4 with MSVC 14.50.35717 but no CMake component): ```powershell $vswhere = "${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\vswhere.exe" & $vswhere -latest -products '*' -requires Microsoft.VisualStudio.Component.VC.Tools.x86.x64 Microsoft.VisualStudio.Component.VC.CMake.Project -property installationPath # -> nothing (confirmed) & $vswhere -latest -products '*' -requires Microsoft.VisualStudio.Component.VC.Tools.x86.x64 -property installationPath # -> nothing as well. The Build Tools instance reports isComplete=False, so vswhere # excludes it from queries without -all. & $vswhere -all -sort -products '*' -requires Microsoft.VisualStudio.Component.VC.Tools.x86.x64 -property installationPath # -> C:\Program Files (x86)\Microsoft Visual Studio\18\BuildTools ``` So on this setup a `-latest` toolset-only query cannot return the Build Tools path. The branch therefore keeps the primary query exactly as before (`-latest -products '*' -requires` with both components) and changes the fallback to a toolset-only `-all -sort` query, followed by a check that `Common7\Tools\Launch-VsDevShell.ps1` exists before the instance is selected. That keeps the fallback from handing an unusable incomplete installation to the launcher while still finding the usable one here. With the pushed commit `dc406e4`, `.\tools\dev.ps1` opens the Build Tools developer shell (VSINSTALLDIR points at the Build Tools instance, `cl`/`cmake`/`ninja` resolve) and the configure/build/test results in the PR body are unchanged. The PR description now records the query table above. If you would rather the fallback stay `-latest` only, I can keep it and instead skip the fallback on this setup — but then the script still refuses a machine with a working toolset, which is what this PR set out to fix. Happy to adjust either way.
This discussion has been locked. Commenting is limited to contributors.
No description provided.