diff --git a/runtime/CMakeLists.txt b/runtime/CMakeLists.txt index 7e7acf88..345850af 100644 --- a/runtime/CMakeLists.txt +++ b/runtime/CMakeLists.txt @@ -537,6 +537,9 @@ if(BUILD_TESTING) add_test(NAME cdrom_lid_integration_test COMMAND ${Python3_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/tests/test_cdrom_lid_integration.py) + add_test(NAME bios_registry_zero_entry_guard_test + COMMAND ${Python3_EXECUTABLE} + ${CMAKE_CURRENT_SOURCE_DIR}/tests/test_bios_registry_zero_entry.py) endif() # Full card protocol regression: read, write, address echo, per-slot state, diff --git a/runtime/runtime.cmake b/runtime/runtime.cmake index e9b9aa7c..65ac20e8 100644 --- a/runtime/runtime.cmake +++ b/runtime/runtime.cmake @@ -667,6 +667,15 @@ else() list(LENGTH _psxrt_bios_linked _psxrt_bios_count) endif() +# ISO C requires at least one initializer. A setup host can intentionally have +# zero linked BIOS backends, so give the generated array one unused null entry +# while keeping its public count at zero. MSVC 19.44 otherwise crashes with +# C1001 in CloseTypeServerPDB when it compiles an empty initializer list. +if(NOT _psxrt_registry_entries) + set(_psxrt_registry_entries " 0, /* unused: registry count is zero */ +") +endif() + # Registry of the compiled-in backends, in preference order. Generated so the # stem list stays the single source of truth. set(_psxrt_registry_c "${CMAKE_BINARY_DIR}/psx_bios_registry.c") diff --git a/runtime/tests/test_bios_registry_zero_entry.py b/runtime/tests/test_bios_registry_zero_entry.py new file mode 100644 index 00000000..331b5c09 --- /dev/null +++ b/runtime/tests/test_bios_registry_zero_entry.py @@ -0,0 +1,18 @@ +#!/usr/bin/env python3 +"""Keep setup-host BIOS registry generation valid ISO C.""" + +from pathlib import Path + + +ROOT = Path(__file__).resolve().parents[2] +RUNTIME_CMAKE = (ROOT / "runtime" / "runtime.cmake").read_text(encoding="utf-8") + +guard = "if(NOT _psxrt_registry_entries)" +sentinel = 'set(_psxrt_registry_entries " 0, /* unused: registry count is zero */' +writer = 'set(_psxrt_registry_c "${CMAKE_BINARY_DIR}/psx_bios_registry.c")' + +assert guard in RUNTIME_CMAKE +assert sentinel in RUNTIME_CMAKE +assert RUNTIME_CMAKE.index(guard) < RUNTIME_CMAKE.index(writer) + +print("zero-entry BIOS registry guard passed")