Build: set up the MSVC linker and SDK libraries from Git Bash #943

Open
HailLucifer666 wants to merge 2 commits from upstream-pr/944 into main
HailLucifer666 commented 2026-11-25 13:24:55 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by HailLucifer666 on 2026-11-25T13:24:55Z.


Problem

Git Bash ships /usr/bin/link.exe — GNU coreutils' link, the syscall wrapper — which comes first on PATH and shadows the MSVC linker of the same name. rustc then reports:

error: linking with `link.exe` failed
        ensure the "C++ build tools" workload is selected

which blames the workload even when the workload is installed and only LIB is unset. That message sent this session hunting for a missing Visual Studio component that was never missing; the real cause was a wrong PATH and an empty LIB.

Fix

scripts/msvc-env.sh, sourced (. scripts/msvc-env.sh):

  1. Finds the toolchain through vswhere, falling back to any layout under a drive root, then converts the Windows-form path vswhere answers with into POSIX form — a PATH entry in F:\VS C++ form does not resolve from Git Bash, which is how GNU link kept winning even after PATH was "fixed".
  2. Finds the newest Windows SDK and exports LIB as the semicolon-separated Windows paths the linker wants (the toolchain's own lib/x64, then the SDK's um/x64 and ucrt/x64).
  3. Honours VICTORY_MSVC and VICTORY_WINDOWS_KITS.

Nothing is hardcoded to one machine. With no usable toolchain it says why and changes nothing, so sourcing it is always safe.

Verified here

rustc hello.rs links and the binary runs; which link.exe resolves to the MSVC one; with VICTORY_MSVC=/nope it prints the reason and leaves LIB unset.

<!-- greyfinch-sync:fxceless/victory-fork:issue:6605508382 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/944). Originally posted by [HailLucifer666](https://github.com/HailLucifer666) on 2026-11-25T13:24:55Z. --- ### Problem Git Bash ships `/usr/bin/link.exe` — GNU coreutils' `link`, the syscall wrapper — which comes first on `PATH` and shadows the MSVC linker of the same name. `rustc` then reports: ``` error: linking with `link.exe` failed ensure the "C++ build tools" workload is selected ``` which blames the workload even when the workload is installed and only `LIB` is unset. That message sent this session hunting for a missing Visual Studio component that was never missing; the real cause was a wrong `PATH` and an empty `LIB`. ### Fix `scripts/msvc-env.sh`, sourced (`. scripts/msvc-env.sh`): 1. Finds the toolchain through `vswhere`, falling back to any layout under a drive root, then converts the Windows-form path `vswhere` answers with into POSIX form — a `PATH` entry in `F:\VS C++` form does not resolve from Git Bash, which is how GNU `link` kept winning even after `PATH` was "fixed". 2. Finds the newest Windows SDK and exports `LIB` as the semicolon-separated Windows paths the linker wants (the toolchain's own `lib/x64`, then the SDK's `um/x64` and `ucrt/x64`). 3. Honours `VICTORY_MSVC` and `VICTORY_WINDOWS_KITS`. Nothing is hardcoded to one machine. With no usable toolchain it says why and changes nothing, so sourcing it is always safe. ### Verified here `rustc hello.rs` links and the binary runs; `which link.exe` resolves to the MSVC one; with `VICTORY_MSVC=/nope` it prints the reason and leaves `LIB` unset.
avt0m4t48 commented 2026-11-25 16:12:55 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by avt0m4t48 on 2026-11-25T16:09:48Z.


I checked the helper at 6aa4add3 with synthetic toolchain and SDK directories in Bash and dash on Linux, using a test double for cygpath. The helper file is identical in GitHub’s test merge and when applied to main at 39731795. The complete SDK, Windows-form MSVC path with spaces, and missing-linker controls passed in both shells.

I reproduced two SDK selection cases with a valid linker override:

  • With both Lib/10.0.10.0/{um,ucrt}/x64 and only Lib/10.0.11.0/um/x64, the helper chooses 10.0.11.0 and sets LIB to include its missing ucrt/x64. The older complete version is available.
  • With VICTORY_WINDOWS_KITS set to a nonexistent root or a root with an empty Lib, the helper prints SDK libraries: with an empty value and overwrites an existing LIB. In this case _ver is empty, so the SDK arguments passed to cygpath -w are /um/x64 and /ucrt/x64.

Could the helper pick the newest version containing both x64 directories and warn while preserving LIB if none can be used? These checks exercised shell selection and environment output. Native Git Bash and MSVC linking remain unverified in this run.

<!-- greyfinch-sync:fxceless/victory-fork:comment:7167648285 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/944#issuecomment-7167648285). Originally posted by [avt0m4t48](https://github.com/avt0m4t48) on 2026-11-25T16:09:48Z. --- I checked the helper at `6aa4add3` with synthetic toolchain and SDK directories in Bash and dash on Linux, using a test double for `cygpath`. The helper file is identical in GitHub’s test merge and when applied to main at `39731795`. The complete SDK, Windows-form MSVC path with spaces, and missing-linker controls passed in both shells. I reproduced two SDK selection cases with a valid linker override: - With both `Lib/10.0.10.0/{um,ucrt}/x64` and only `Lib/10.0.11.0/um/x64`, the helper chooses `10.0.11.0` and sets `LIB` to include its missing `ucrt/x64`. The older complete version is available. - With `VICTORY_WINDOWS_KITS` set to a nonexistent root or a root with an empty `Lib`, the helper prints `SDK libraries:` with an empty value and overwrites an existing `LIB`. In this case `_ver` is empty, so the SDK arguments passed to `cygpath -w` are `/um/x64` and `/ucrt/x64`. Could the helper pick the newest version containing both x64 directories and warn while preserving `LIB` if none can be used? These checks exercised shell selection and environment output. Native Git Bash and MSVC linking remain unverified in this run.
HailLucifer666 commented 2026-11-25 21:05:53 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by HailLucifer666 on 2026-11-25T20:20:19Z.


Fixed both SDK-selection edge cases in 3aca156f (thanks @avt0m4t48):

  1. _ver now selects the newest Lib/10.* directory that contains both um/x64 and ucrt/x64, skipping incomplete SDKs.
  2. When no complete SDK is found (e.g. nonexistent or empty VICTORY_WINDOWS_KITS), scripts/msvc-env.sh warns and preserves the existing LIB instead of overwriting it.

Verified in Git Bash (sh) against synthetic fixtures for both cases plus the local MSVC + Windows 10.0.26100.0 SDK toolchain.

<!-- greyfinch-sync:fxceless/victory-fork:comment:7173520712 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/944#issuecomment-7173520712). Originally posted by [HailLucifer666](https://github.com/HailLucifer666) on 2026-11-25T20:20:19Z. --- Fixed both SDK-selection edge cases in `3aca156f` (thanks `@avt0m4t48`): 1. `_ver` now selects the newest `Lib/10.*` directory that contains **both** `um/x64` and `ucrt/x64`, skipping incomplete SDKs. 2. When no complete SDK is found (e.g. nonexistent or empty `VICTORY_WINDOWS_KITS`), `scripts/msvc-env.sh` warns and preserves the existing `LIB` instead of overwriting it. Verified in Git Bash (`sh`) against synthetic fixtures for both cases plus the local MSVC + Windows 10.0.26100.0 SDK toolchain.
HailLucifer666 commented 2026-11-26 15:04:07 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by HailLucifer666 on 2026-11-26T14:11:20Z.


The two SDK-selection cases from your review are addressed at head 3aca156f: _ver now requires both um/x64 and ucrt/x64 before choosing a version, and an unusable VICTORY_WINDOWS_KITS keeps the existing LIB and warns instead of replacing it. Could you retest those two scenarios against this head when you have a moment? The helper itself is unchanged since your run; only the selection logic moved.

<!-- greyfinch-sync:fxceless/victory-fork:comment:7194400964 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/944#issuecomment-7194400964). Originally posted by [HailLucifer666](https://github.com/HailLucifer666) on 2026-11-26T14:11:20Z. --- The two SDK-selection cases from your review are addressed at head `3aca156f`: `_ver` now requires both `um/x64` and `ucrt/x64` before choosing a version, and an unusable `VICTORY_WINDOWS_KITS` keeps the existing `LIB` and warns instead of replacing it. Could you retest those two scenarios against this head when you have a moment? The helper itself is unchanged since your run; only the selection logic moved.
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/944:upstream-pr/944'
git switch 'upstream-pr/944'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/944'
git switch 'upstream-pr/944'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/944'
git switch 'upstream-pr/944'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/944'
git switch 'main'
git merge --squash 'upstream-pr/944'
git switch 'main'
git merge --ff-only 'upstream-pr/944'
git switch 'main'
git merge 'upstream-pr/944'
git push origin 'main'
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
fxceless/victory-fork!943
No description provided.