fix(build): link the MSVC runtime statically #72

Manually merged
github merged 1 commit from gh-pr/72/head into gh-pr/72/base 2026-11-26 19:17:37 +00:00
Owner

@⁠Dark3581 on GitHub · 2026-11-23 05:21 UTC · original
Dark3581:fix/msvc-static-runtime → main · +2 −1 · 2 files · 1 commits · merged 2026-11-23 05:23 UTC

What

MSVC builds linked AnyBox's libraries against the dynamic C and C++ runtime (MSVCP140.dll, VCRUNTIME140.dll and the api-ms-win-crt-* sets). anybox_static_runtime only made MinGW static. A relinked title's folder holds the title's own console builds of msvcp140.dll and vcruntime140.dll, so MSVC-built AnyBox libraries loaded those and could crash in them.

Found while testing #71: with the MSVC-built libraries, a bundled GDK module's HCInitialize died with an access violation reading address 0 at msvcp140.dll+0x12f70, in the package's own msvcp140.dll. The MinGW-built libraries never touch it.

set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>") in the root CMakeLists.txt selects the static runtime for every target. It has to be global so the static libraries linked into the DLLs use the same runtime. MinGW builds are unchanged. ARCHITECTURE now says both toolchains link the runtime statically, and why it matters for titles.

Tested

Windows 10, MSVC 2022 (fresh build tree) and MinGW (GCC).

  • MSVC: ab_runtime.dll now imports only KERNEL32.dll, and ab_xgameruntime.dll and ab_d3d12_x.dll import only ab_runtime.dll and KERNEL32.dll. Before, they imported MSVCP140, VCRUNTIME140, VCRUNTIME140_1 and nine api-ms-win-crt-* sets.
  • MSVC ctest: 77 of 77, the full suite.
  • The bundled module's HCInitialize (the #71 harness) now returns S_OK with the MSVC-built libraries too, instead of crashing.
  • Every target builds except ab_gameinput, which needs gameinput.lib, which this machine doesn't have. MinGW ctest: 77 of 77. python tools/check_conventions.py: ok.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • python tools/check_conventions.py passes (no comments in code, one declaration per export, Conventional Commit subjects)
  • Unimplemented paths stop (AbxNotImplemented / AbxUnsupported); silent stubs are listed under Silent stubs through a debt fragment
  • Known gaps added, changed or removed through docs/dev/debt/changes/<branch>.md
  • Generic behaviour, not specific to one title
  • No game files, keys, notes or logs added to the repository
  • Depends on: none
  • Fixes: none
  • Unblocks: none
  • Source of behaviour: CMake documentation (CMAKE_MSVC_RUNTIME_LIBRARY)
  • AI-assisted: yes
**@⁠Dark3581** on GitHub · 2026-11-23 05:21 UTC · [original](https://github.com/Dark3581/AnyBox/pull/72) `Dark3581:fix/msvc-static-runtime` → `main` · +2 −1 · 2 files · 1 commits · merged 2026-11-23 05:23 UTC ### What MSVC builds linked AnyBox's libraries against the dynamic C and C++ runtime (`MSVCP140.dll`, `VCRUNTIME140.dll` and the `api-ms-win-crt-*` sets). `anybox_static_runtime` only made MinGW static. A relinked title's folder holds the title's own console builds of `msvcp140.dll` and `vcruntime140.dll`, so MSVC-built AnyBox libraries loaded those and could crash in them. Found while testing #71: with the MSVC-built libraries, a bundled GDK module's `HCInitialize` died with an access violation reading address 0 at `msvcp140.dll+0x12f70`, in the package's own `msvcp140.dll`. The MinGW-built libraries never touch it. `set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")` in the root `CMakeLists.txt` selects the static runtime for every target. It has to be global so the static libraries linked into the DLLs use the same runtime. MinGW builds are unchanged. ARCHITECTURE now says both toolchains link the runtime statically, and why it matters for titles. ### Tested Windows 10, MSVC 2022 (fresh build tree) and MinGW (GCC). - MSVC: `ab_runtime.dll` now imports only `KERNEL32.dll`, and `ab_xgameruntime.dll` and `ab_d3d12_x.dll` import only `ab_runtime.dll` and `KERNEL32.dll`. Before, they imported `MSVCP140`, `VCRUNTIME140`, `VCRUNTIME140_1` and nine `api-ms-win-crt-*` sets. - MSVC `ctest`: 77 of 77, the full suite. - The bundled module's `HCInitialize` (the #71 harness) now returns `S_OK` with the MSVC-built libraries too, instead of crashing. - Every target builds except `ab_gameinput`, which needs `gameinput.lib`, which this machine doesn't have. MinGW `ctest`: 77 of 77. `python tools/check_conventions.py`: ok. ### Checklist - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] `python tools/check_conventions.py` passes (no comments in code, one declaration per export, Conventional Commit subjects) - [x] Unimplemented paths stop (`AbxNotImplemented` / `AbxUnsupported`); silent stubs are listed under Silent stubs through a debt fragment - [x] Known gaps added, changed or removed through `docs/dev/debt/changes/<branch>.md` - [x] Generic behaviour, not specific to one title - [x] No game files, keys, notes or logs added to the repository - [x] Depends on: none - [x] Fixes: none - [x] Unblocks: none - [x] Source of behaviour: CMake documentation (`CMAKE_MSVC_RUNTIME_LIBRARY`) - [x] AI-assisted: yes
MSVC builds linked AnyBox's libraries against the dynamic C++ runtime, so in a title's folder they loaded the console msvcp140.dll the title ships and crashed in it. CMAKE_MSVC_RUNTIME_LIBRARY now selects the static runtime, as MinGW builds already do.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 19:17:35 +00:00
github manually merged commit 0a04d9eb41 into gh-pr/72/base 2026-11-26 19:17:37 +00:00
This discussion has been locked. Commenting is limited to contributors.
No description provided.