build: isolate the SDL3 entry point implementation

SDL_main.h is a single-header implementation in SDL3. Include it only from the translation unit that owns main so MinGW emits one WinMain instead of one per SDL-using source.
This commit is contained in:
Matthew Stanley
2026-08-01 10:43:59 -07:00
parent c264a704ec
commit 5176e40037
7 changed files with 59 additions and 6 deletions
+1 -1
View File
@@ -139,7 +139,7 @@ cmake --build recompiler/build
cd recompiler/build && ctest --output-on-failure
```
37 tests, under five seconds, no BIOS dump or disc image required. See
38 tests, under five seconds, no BIOS dump or disc image required. See
[`docs/TESTING.md`](docs/TESTING.md) for running individual tests, what the
suite covers, and the three known-failing tests that are deliberately not
registered.
+1 -1
View File
@@ -135,7 +135,7 @@ After step 1 above — no BIOS or disc needed — verify the tree is sane:
cd recompiler/build && ctest --output-on-failure
```
37 tests, under five seconds. See [`TESTING.md`](TESTING.md).
38 tests, under five seconds. See [`TESTING.md`](TESTING.md).
On Windows with MSVC or plain MinGW makefiles, swap `-G Ninja` for your generator
(e.g. `-G "Unix Makefiles"`); everything else is identical.
+1 -1
View File
@@ -8,7 +8,7 @@ cmake --build recompiler/build
cd recompiler/build && ctest --output-on-failure
```
That is the whole thing. 37 tests, under 5 seconds, and it needs **no BIOS dump,
That is the whole thing. 38 tests, under 5 seconds, and it needs **no BIOS dump,
no disc image, and no generated code** — a plain recompiler build is enough. This
is the check to run before opening a PR.
+3 -2
View File
@@ -409,8 +409,9 @@ if(BUILD_TESTING)
mod_controller_override
overlay_candidate_capacity
overlay_decodable_fallback
overlay_init_guard
vk_build_default
overlay_init_guard
sdl3_main_single_include
vk_build_default
vk_color_self_barrier
vk_command_buffer_batching
vk_draw_area_batch_boundary
-1
View File
@@ -11,7 +11,6 @@
#define SDL_ENABLE_OLD_NAMES
#define SDL_FUNCTION_POINTER_IS_VOID_POINTER
#include <SDL3/SDL.h>
#include <SDL3/SDL_main.h>
#ifndef SDL_WINDOW_SHOWN
#define SDL_WINDOW_SHOWN 0
+8
View File
@@ -72,6 +72,14 @@ extern "C" void psx_event_step_conservative_env_init(void);
#include "launcher_profile.h" /* per-system variant profile (theme/caps bundle) */
#endif
#include "psx_sdl.h"
#if defined(PSX_SDL3)
/*
* SDL_main.h is a single-header implementation in SDL3. Keep it in the one
* translation unit that defines main(); including it through psx_sdl.h makes
* every SDL-using source emit WinMain under MinGW.
*/
#include <SDL3/SDL_main.h>
#endif
#include "psx_sdl_audio.h"
#if defined(PSX_WEB)
#include <emscripten/emscripten.h>
@@ -0,0 +1,45 @@
#!/usr/bin/env python3
"""Keep SDL3's single-header entry-point implementation in main.cpp only."""
from pathlib import Path
import sys
ROOT = Path(__file__).resolve().parents[2]
SDL_MAIN_HEADER = "<SDL3/SDL_main.h>"
def main() -> int:
runtime = ROOT / "runtime"
owners = []
for pattern in ("*.c", "*.cpp", "*.h"):
for path in runtime.rglob(pattern):
source = path.read_text(encoding="utf-8")
if SDL_MAIN_HEADER in source:
owners.append(path.relative_to(ROOT).as_posix())
if owners != ["runtime/src/main.cpp"]:
raise AssertionError(
"SDL_main.h must be included exactly once by runtime/src/main.cpp; "
f"found {owners}"
)
main_cpp = (runtime / "src/main.cpp").read_text(encoding="utf-8")
guard = (
"#if defined(PSX_SDL3)\n"
"/*\n"
" * SDL_main.h is a single-header implementation"
)
if guard not in main_cpp:
raise AssertionError("SDL_main.h include is no longer guarded by PSX_SDL3")
print("PASS: SDL3 entry-point implementation has one owner")
return 0
if __name__ == "__main__":
try:
sys.exit(main())
except AssertionError as exc:
print(f"FAIL: {exc}")
sys.exit(1)