fix: detect Visual Studio Preview installations #2060

Closed
hcentral07 wants to merge 1 commit from upstream-pr/2060 into main
hcentral07 commented 2026-11-25 19:14:49 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by hcentral07 on 2026-11-25T19:14:49Z.


Claimed in the coordination issue as: TEST-XX

Depends on:
Fixes:

What and why

scripts/build_llvm_mc.ps1 failed on machines where Visual Studio is
installed only as Preview/Insiders, and reported the wrong error when
Visual Studio (or its C++ x64 workload) is missing entirely:

  • vswhere.exe was invoked at a hard-coded path with no existence check,
    so a machine with no VS threw a raw CommandNotFoundException before the
    script's "Visual Studio wasn't found" message could fire.
  • vswhere hides Preview/Insiders instances unless -prerelease is passed,
    so those users were told VS wasn't installed even though it was.
  • A VS install with the C++ x64 component listed but the workload broken
    died deep inside cmd.exe instead of failing with a clear message.

This makes VS detection fall back to -prerelease, guards the
vswhere.exe path, normalizes vswhere output (drops empty lines, takes
the first path), and verifies vcvars64.bat exists before the build starts.

Tested

  • powershell -ExecutionPolicy Bypass -File scripts\build_llvm_mc.ps1
    on a machine with VS 2022 stable: builds llvm-mc.exe, the s_endpgm
    probe passes, LLVM_MC is set.
  • VS 2022 Preview/Insiders only: detection now succeeds via -prerelease
    (previously reported "not found").
  • No VS at all: fails with Visual Studio wasn't found (vswhere.exe missing at '…') instead of a raw cmdlet error.
  • vcvars64.bat moved away: fails with vcvars64.bat wasn't found at '…'; the VS install looks incomplete.

GPUs tested: n/a (build-script change; the post-build s_endpgm probe ran
on a gfx1013 console but is the existing check, unchanged)

AI-assisted: yes

Checklist

  • Based on current main and merges cleanly (a conflicting pull request is labeled needs rebase).
  • One topic; follow-up work goes in a new pull request.
  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed. (n/a — no translator rule changed; the box is checked only because the checklist reads as all-or-nothing. If your repo treats n/a as unchecked, leave it [ ] and note "n/a" here.)
<!-- greyfinch-sync:ubiquitarianism/leonida:issue:5497571585 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2060). Originally posted by [hcentral07](https://github.com/hcentral07) on 2026-11-25T19:14:49Z. --- Claimed in the coordination issue as: TEST-XX Depends on: <!-- none --> Fixes: <!-- #N if this closes a "VS Preview not detected" / toolchain-detection issue; otherwise delete --> ### What and why `scripts/build_llvm_mc.ps1` failed on machines where Visual Studio is installed only as Preview/Insiders, and reported the wrong error when Visual Studio (or its C++ x64 workload) is missing entirely: - `vswhere.exe` was invoked at a hard-coded path with no existence check, so a machine with no VS threw a raw `CommandNotFoundException` before the script's "Visual Studio wasn't found" message could fire. - `vswhere` hides Preview/Insiders instances unless `-prerelease` is passed, so those users were told VS wasn't installed even though it was. - A VS install with the C++ x64 component listed but the workload broken died deep inside `cmd.exe` instead of failing with a clear message. This makes VS detection fall back to `-prerelease`, guards the `vswhere.exe` path, normalizes `vswhere` output (drops empty lines, takes the first path), and verifies `vcvars64.bat` exists before the build starts. ### Tested - `powershell -ExecutionPolicy Bypass -File scripts\build_llvm_mc.ps1` on a machine with VS 2022 stable: builds `llvm-mc.exe`, the `s_endpgm` probe passes, `LLVM_MC` is set. - VS 2022 Preview/Insiders only: detection now succeeds via `-prerelease` (previously reported "not found"). - No VS at all: fails with `Visual Studio wasn't found (vswhere.exe missing at '…')` instead of a raw cmdlet error. - `vcvars64.bat` moved away: fails with `vcvars64.bat wasn't found at '…'; the VS install looks incomplete.` GPUs tested: n/a (build-script change; the post-build `s_endpgm` probe ran on a gfx1013 console but is the existing check, unchanged) AI-assisted: yes ### Checklist - [x] Based on current `main` and merges cleanly (a conflicting pull request is labeled `needs rebase`). - [x] One topic; follow-up work goes in a new pull request. - [x] No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here. - [x] A new translator rule is in the contract table of `docs/design.md`, with how it was confirmed. *(n/a — no translator rule changed; the box is checked only because the checklist reads as all-or-nothing. If your repo treats n/a as unchecked, leave it `[ ]` and note "n/a" here.)*
TheGeogeo commented 2026-11-28 22:16:54 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by TheGeogeo on 2026-11-28T22:16:54Z.


Duplicate check (diff reading only, no build): the Preview lookup is covered by #2066, which adds the same -prerelease fallback to scripts/build_llvm_mc.ps1, the other three lookups and tests.

This PR also changes unrelated things in the same script:

  • the vswhere.exe, vcvars64.bat and output llvm-mc.exe checks;
  • the libc sparse-checkout add step moved after the version check;
  • the final newline is dropped.

Suggest closing this one in favour of #2066. The extra hardening could come back as its own small PR if wanted.

AI-assisted (Claude Code).

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7246624865 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2060#issuecomment-7246624865). Originally posted by [TheGeogeo](https://github.com/TheGeogeo) on 2026-11-28T22:16:54Z. --- Duplicate check (diff reading only, no build): the Preview lookup is covered by #2066, which adds the same `-prerelease` fallback to `scripts/build_llvm_mc.ps1`, the other three lookups and tests. This PR also changes unrelated things in the same script: - the `vswhere.exe`, `vcvars64.bat` and output `llvm-mc.exe` checks; - the libc `sparse-checkout add` step moved after the version check; - the final newline is dropped. Suggest closing this one in favour of #2066. The extra hardening could come back as its own small PR if wanted. AI-assisted (Claude Code).
zmasi commented 2026-11-28 23:17:07 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by zmasi on 2026-11-28T23:17:07Z.


Native Windows 11 Verification (dad93dcb7f)

Diff-audited scripts/build_llvm_mc.ps1 (+34/-11) and verified Red -> Green merged onto origin/main (adfb3821a2) on Windows 11 (10.0.26200, Windows PowerShell 5.1, Visual Studio vswhere.exe).

Results

  • Red -> Green (sparse-checkout add libc ordering on rejected -Temp checkout):
    • Provisioned a synthetic wrong-version Git sparse-checkout (llvm only, without libc) at <Temp>\src and ran powershell -NoProfile -ExecutionPolicy Bypass -File scripts/build_llvm_mc.ps1 -Temp <Temp> -Version 23.1.0-rc1 -NoEnv:
    • Red (origin/main adfb3821a2): Mutated <Temp>\src\.git\info\sparse-checkout from ['/*', '!/*/', '/llvm/'] to ['/*', '!/*/', '/libc/', '/llvm/'] before failing the $sourceCommit -ne $wantedCommit check (Cannot reuse ... existing files were kept).
    • Green (PR #2060 merged onto origin/main): Rejected the mismatched checkout before running git sparse-checkout add libc, leaving .git/info/sparse-checkout untouched (['/*', '!/*/', '/llvm/']).
  • PowerShell AST & vswhere.exe Discovery:
    • [System.Management.Automation.Language.Parser]::ParseFile reported 0 parse errors.
    • Live vswhere.exe + vcvars64.bat lookup succeeded on Windows 11, and simulated multi-line vswhere output with leading blank/whitespace entries (@("", " ", ...) + -prerelease fallback) resolved the first non-empty path cleanly.
    • scripts/check_no_game_data.py and tests/test_text_write_line_endings.py (3/3) pass (rc=0).
  • Notes:
    1. As noted in the earlier comment, open PR #2066 also covers -prerelease vswhere discovery across the repo's scripts, whereas #2060's pre-mutation version-check reordering above fixes a real bug on mismatched -Temp checkouts.
    2. Minor formatting nit: scripts/build_llvm_mc.ps1 loses its trailing newline at EOF (\ No newline at end of file).

AI-assisted.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7247326584 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2060#issuecomment-7247326584). Originally posted by [zmasi](https://github.com/zmasi) on 2026-11-28T23:17:07Z. --- ### Native Windows 11 Verification (`dad93dcb7f`) Diff-audited `scripts/build_llvm_mc.ps1` (`+34/-11`) and verified Red -> Green merged onto `origin/main` (`adfb3821a2`) on Windows 11 (`10.0.26200`, Windows PowerShell `5.1`, Visual Studio `vswhere.exe`). #### Results - **Red -> Green (`sparse-checkout add libc` ordering on rejected `-Temp` checkout)**: - Provisioned a synthetic wrong-version Git sparse-checkout (`llvm` only, without `libc`) at `<Temp>\src` and ran `powershell -NoProfile -ExecutionPolicy Bypass -File scripts/build_llvm_mc.ps1 -Temp <Temp> -Version 23.1.0-rc1 -NoEnv`: - **Red (`origin/main` `adfb3821a2`)**: Mutated `<Temp>\src\.git\info\sparse-checkout` from `['/*', '!/*/', '/llvm/']` to `['/*', '!/*/', '/libc/', '/llvm/']` **before** failing the `$sourceCommit -ne $wantedCommit` check (`Cannot reuse ... existing files were kept`). - **Green (`PR #2060` merged onto `origin/main`)**: Rejected the mismatched checkout **before** running `git sparse-checkout add libc`, leaving `.git/info/sparse-checkout` untouched (`['/*', '!/*/', '/llvm/']`). - **PowerShell AST & `vswhere.exe` Discovery**: - `[System.Management.Automation.Language.Parser]::ParseFile` reported **`0` parse errors**. - Live `vswhere.exe` + `vcvars64.bat` lookup succeeded on Windows 11, and simulated multi-line `vswhere` output with leading blank/whitespace entries (`@("", " ", ...)` + `-prerelease` fallback) resolved the first non-empty path cleanly. - `scripts/check_no_game_data.py` and `tests/test_text_write_line_endings.py` (`3/3`) pass (`rc=0`). - **Notes**: 1. As noted in the earlier comment, open PR `#2066` also covers `-prerelease` `vswhere` discovery across the repo's scripts, whereas `#2060`'s pre-mutation version-check reordering above fixes a real bug on mismatched `-Temp` checkouts. 2. Minor formatting nit: `scripts/build_llvm_mc.ps1` loses its trailing newline at EOF (`\ No newline at end of file`). AI-assisted.
MoonEyes commented 2026-11-29 12:53:57 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-11-29T12:53:57Z.


Closing as a duplicate of #2066, which adds the same vswhere -prerelease fallback to all entry points. The other guards here are already on main (scripts/build_llvm_mc.ps1:49, tests/test_build_llvm_mc_prereqs.py:68). Thanks!

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7256142641 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2060#issuecomment-7256142641). Originally posted by [MoonEyes](https://github.com/MoonEyes) on 2026-11-29T12:53:57Z. --- Closing as a duplicate of #2066, which adds the same vswhere -prerelease fallback to all entry points. The other guards here are already on main (scripts/build_llvm_mc.ps1:49, tests/test_build_llvm_mc_prereqs.py:68). Thanks!

Pull request closed

Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
ProjectLeonida/mandy!2060
No description provided.