d3d12: build-nvidia.ps1 builds the msvc target when Rust's host is not MSVC (BUILD-NVIDIA-MSVC-TARGET) #3426

Merged
leonida/mandy
OreoFR merged 4 commits from underlight3d/mandy:build-msvc-target into main 2026-12-04 06:55:29 +00:00

Pull request successfully merged and closed

Collaborator

Claimed in the coordination issue as: BUILD-NVIDIA-MSVC-TARGET (https://git.leonida.now/leonida/mandy/issues/3312#issuecomment-25051). Related: #3238 (exports from a gnullvm build, a different route).

What and why

d3d12/scripts/build-nvidia.ps1 ran cargo build without --target, and d3d12/rust-toolchain.toml installs the msvc target without selecting it. With rustup's default host x86_64-pc-windows-gnu, leonida.exe came out a GNU build: about 128 MB (122 MiB), mostly DWARF debug info, against about 22 MB. It has no export table and loads d3d12.dll at start instead of delay-loading it (build.rs gives /EXPORT and /DELAYLOAD to the msvc linker only), so the Agility SDK cannot be picked up. Mandy Setup installs rustup for the msvc host, so this mainly helps people who set up Rust themselves.

The script now asks rustc -vV in d3d12. If the host is not *-pc-windows-msvc (GNU, gnullvm, i686…):

  • It checks that the sysroot has the msvc target's libcore. If not, it stops with rustup target add x86_64-pc-windows-msvc, to run in d3d12 (so it lands on the pinned toolchain). If rustc gives no sysroot, or one that does not exist (for example a user folder with non-ASCII characters, read in the console code page), cargo is left to report.
  • It builds with --target x86_64-pc-windows-msvc.
  • It copies leonida.exe to target\diag, where the launcher and the play scripts already look. It first checks the msvc exe exists (otherwise the old files are kept and it exits 1), then removes cargo's hard-linked file before copying (so the GNU build's file in deps is not overwritten through the link), and dates the copy at copy time so play-nvidia.ps1 refreshes leonida_sm.exe. The pdb follows; if it cannot be replaced, that is only a warning.
  • The rustc calls are made safe under an inherited $ErrorActionPreference = "Stop" (as play-d3d12.ps1 sets before calling this script).

With an msvc host, or when rustc cannot say, cargo gets the same arguments as before. Launcher files are untouched; @OreoFR agreed, and the missing-target message is his request.

Tested

  • tests/test_build_nvidia_msvc_target.py (new; stand-in cargo and rustc that record their arguments and working folder): 14 tests. On main's script 12 fail for the reason they state; 14 pass here. Each of 14 deliberate breaks of the new script is caught by a test.
  • tests/test_build_nvidia_exit.py gets a failing rustc stand-in, so the PC's own Rust does not decide its result.
  • End to end on Windows 11 Pro (build 26300), rustup default host x86_64-pc-windows-gnu, Rust 1.98.1, the script run with no arguments as the launcher runs it: exit 0, "Built:" printed, a 21,789,696-byte msvc leonida.exe in target\diag exporting D3D12SDKVersion, one link, dated at copy time, built-with.txt written, and cargo's hard-linked file in deps left with its own contents.
  • Not run: the tests under pwsh on Linux (the paths are built with [IO.Path]::Combine).

GPUs tested: n/a (build script; the exe was not started in the game).

AI-assisted: yes (Claude Code, Claude Opus 5.5 for the code and tests; two independent read-only reviewer agents, Claude Opus 5.5, one on the code and one on the evidence and mutations; the code reviewer re-reviewed the fixes and found them ready).

Checklist

  • Based on current main and merges cleanly.
  • One topic.
  • No game data, keys or decryption.
  • No launcher file changed.

🤖 Generated with Claude Code

https://claude.ai/code/session_01WtKdZ5UBfzFHFUgnKaKoSc

Claimed in the coordination issue as: BUILD-NVIDIA-MSVC-TARGET (https://git.leonida.now/leonida/mandy/issues/3312#issuecomment-25051). Related: #3238 (exports from a gnullvm build, a different route). ### What and why `d3d12/scripts/build-nvidia.ps1` ran `cargo build` without `--target`, and `d3d12/rust-toolchain.toml` installs the msvc target without selecting it. With rustup's default host `x86_64-pc-windows-gnu`, `leonida.exe` came out a GNU build: about 128 MB (122 MiB), mostly DWARF debug info, against about 22 MB. It has no export table and loads `d3d12.dll` at start instead of delay-loading it (`build.rs` gives `/EXPORT` and `/DELAYLOAD` to the msvc linker only), so the Agility SDK cannot be picked up. Mandy Setup installs rustup for the msvc host, so this mainly helps people who set up Rust themselves. The script now asks `rustc -vV` in `d3d12`. If the host is not `*-pc-windows-msvc` (GNU, gnullvm, i686…): - It checks that the sysroot has the msvc target's `libcore`. If not, it stops with `rustup target add x86_64-pc-windows-msvc`, to run in `d3d12` (so it lands on the pinned toolchain). If rustc gives no sysroot, or one that does not exist (for example a user folder with non-ASCII characters, read in the console code page), cargo is left to report. - It builds with `--target x86_64-pc-windows-msvc`. - It copies `leonida.exe` to `target\diag`, where the launcher and the play scripts already look. It first checks the msvc exe exists (otherwise the old files are kept and it exits 1), then removes cargo's hard-linked file before copying (so the GNU build's file in `deps` is not overwritten through the link), and dates the copy at copy time so `play-nvidia.ps1` refreshes `leonida_sm.exe`. The pdb follows; if it cannot be replaced, that is only a warning. - The rustc calls are made safe under an inherited `$ErrorActionPreference = "Stop"` (as `play-d3d12.ps1` sets before calling this script). With an msvc host, or when rustc cannot say, cargo gets the same arguments as before. Launcher files are untouched; @OreoFR agreed, and the missing-target message is his request. ### Tested - `tests/test_build_nvidia_msvc_target.py` (new; stand-in `cargo` and `rustc` that record their arguments and working folder): 14 tests. On `main`'s script 12 fail for the reason they state; 14 pass here. Each of 14 deliberate breaks of the new script is caught by a test. - `tests/test_build_nvidia_exit.py` gets a failing `rustc` stand-in, so the PC's own Rust does not decide its result. - End to end on Windows 11 Pro (build 26300), rustup default host `x86_64-pc-windows-gnu`, Rust 1.98.1, the script run with no arguments as the launcher runs it: exit 0, "Built:" printed, a 21,789,696-byte msvc `leonida.exe` in `target\diag` exporting `D3D12SDKVersion`, one link, dated at copy time, `built-with.txt` written, and cargo's hard-linked file in `deps` left with its own contents. - Not run: the tests under pwsh on Linux (the paths are built with `[IO.Path]::Combine`). GPUs tested: n/a (build script; the exe was not started in the game). AI-assisted: yes (Claude Code, Claude Opus 5.5 for the code and tests; two independent read-only reviewer agents, Claude Opus 5.5, one on the code and one on the evidence and mutations; the code reviewer re-reviewed the fixes and found them ready). ### Checklist - [x] Based on current `main` and merges cleanly. - [x] One topic. - [x] No game data, keys or decryption. - [x] No launcher file changed. 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01WtKdZ5UBfzFHFUgnKaKoSc
cargo build ran without --target, and rust-toolchain.toml installs the msvc
target without selecting it, so with rustup's default host
x86_64-pc-windows-gnu leonida.exe came out a GNU build: about 122 MB against
21, without the D3D12SDKVersion and D3D12SDKPath exports (build.rs passes
them to the msvc linker only).

The script now asks rustc -vV in d3d12, where rust-toolchain.toml applies.
With a host that is not *-pc-windows-msvc it builds with
--target x86_64-pc-windows-msvc and copies leonida.exe (and leonida.pdb) to
target\diag, dated now, where play-nvidia.ps1, play-d3d12.ps1 and the
launcher take it. When the toolchain's sysroot lacks that target's libcore
it stops with the command that adds it (rustup target add
x86_64-pc-windows-msvc). With an msvc host, or when rustc cannot say, cargo
gets the same arguments as before.

tests/test_build_nvidia_msvc_target.py covers this with stand-in cargo and
rustc; tests/test_build_nvidia_exit.py gets a failing rustc stand-in so the
Rust of the PC running it does not decide its build.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WtKdZ5UBfzFHFUgnKaKoSc
- cargo's target\diag\leonida.exe (and .pdb) is a hard link to its file in
  deps: the old file is removed before the copy, so the msvc build is no
  longer written through the link into cargo's GNU file.
- A pdb that cannot be replaced is reported and the build stands (the exe
  is already the new one); it no longer fails the build with built-with.txt
  left stale.
- rustc runs in a function with its own $ErrorActionPreference 'Continue':
  under play-d3d12.ps1's 'Stop' with the output taken by 2>&1, a line
  rustup or rustc wrote to stderr ended the call and the build fell back
  to GNU without a word.
- A sysroot that is not there (rustc prints it in UTF-8, Windows
  PowerShell reads it in the console code page: an accented user folder)
  no longer counts as a missing target; cargo runs and reports.
- Paths built with [IO.Path]::Combine instead of backslash strings, for
  pwsh on Linux CI.
- The comment drops the frame time and gives the GNU exe as about 128 MB,
  mostly DWARF, against about 22, with no export table and d3d12.dll
  loaded at start, and says Mandy Setup installs rustup for the msvc host.

Tests: a cargo-style hard link in target\diag, a pdb in the way, cargo
failing with status 7 on the GNU path, a sysroot that is not there, the
Stop preference with rustc writing to stderr, and a gnullvm host; each
rustc call's folder is recorded on its own.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WtKdZ5UBfzFHFUgnKaKoSc
The old leonida.exe in target\diag was removed before the script checked
that the msvc build exists. When cargo wrote elsewhere (CARGO_TARGET_DIR)
the copy failed and target\diag was left with no exe. The msvc exe is now
looked for first; without it the old files stay and the script exits 1 as
before. test_gnu_host_fails_when_the_msvc_exe_is_not_there checks that the
old exe is kept.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WtKdZ5UBfzFHFUgnKaKoSc
OreoFR merged commit 662d061e16 into main 2026-12-04 06:55:29 +00:00
Member

Merged by OreoFR (agent) at MoonEyes' request, after his judge accepted it.

Local CI on head 621520c8e merged into main a700d029e: PASS. It found no Rust change and skipped the Rust step. The other checks passed:

  • merge clean;
  • no game data;
  • Python compiles;
  • make_game.py --help;
  • standard-library Python tests, 369 s.

enlighted then merged main into the branch, giving head 56930c702. Its tree is identical to the tree this CI tested: git merge-tree of 621520c8e with a700d029e gives df0529168. Merged as 662d061e1.

Next: MoonEyes rebases #3187 on this.

Merged by OreoFR (agent) at MoonEyes' request, after his judge accepted it. Local CI on head `621520c8e` merged into main `a700d029e`: PASS. It found no Rust change and skipped the Rust step. The other checks passed: - merge clean; - no game data; - Python compiles; - `make_game.py --help`; - standard-library Python tests, 369 s. enlighted then merged `main` into the branch, giving head `56930c702`. Its tree is identical to the tree this CI tested: `git merge-tree` of `621520c8e` with `a700d029e` gives `df0529168`. Merged as `662d061e1`. Next: MoonEyes rebases #3187 on this.
Sign in to join this conversation.
No description provided.