From 2ab19879b57adf5f5460f63dd1b7e29f3749b0b1 Mon Sep 17 00:00:00 2001 From: Alex Vanderveen Date: Sat, 8 Aug 2026 19:36:52 -0400 Subject: [PATCH 1/3] Update psxrecomp_cli.py --- psxrecomp_cli.py | 58 +++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 53 insertions(+), 5 deletions(-) diff --git a/psxrecomp_cli.py b/psxrecomp_cli.py index 04a4a6dc..2d7cd07f 100755 --- a/psxrecomp_cli.py +++ b/psxrecomp_cli.py @@ -766,6 +766,28 @@ def cmd_generate(args: argparse.Namespace, progress: ProgressReporter) -> int: return EXIT_OK +def _which_tool(name: str) -> Optional[Path]: + """Resolve *name* or *name*.exe from PATH (Windows PATHEXT-friendly).""" + for cand in (name, f"{name}.exe"): + found = shutil.which(cand) + if found: + return Path(found) + return None + + +def _read_cmake_cache_generator(cache_file: Path) -> str: + if not cache_file.is_file(): + return "" + try: + text = cache_file.read_text(encoding="utf-8", errors="replace") + except OSError: + return "" + for line in text.splitlines(): + if line.startswith("CMAKE_GENERATOR:INTERNAL="): + return line.split("=", 1)[1].strip() + return "" + + def _cmake_configure( project_root: Path, build_dir: Path, @@ -775,11 +797,34 @@ def _cmake_configure( progress: ProgressReporter, ) -> None: build_dir.mkdir(parents=True, exist_ok=True) - # Prefer Ninja when available; fall back so hosts without ninja still build. - if not (build_dir / "CMakeCache.txt").is_file() and shutil.which("ninja"): - gen = ["-G", "Ninja"] - else: - gen = [] + cache_file = build_dir / "CMakeCache.txt" + ninja = _which_tool("ninja") + clang_c = _which_tool("clang") + clang_cxx = _which_tool("clang++") + + # Prefer Ninja + pack clang when the portable toolchain is on PATH. + # On Windows, a prior failed configure often leaves CMakeCache stuck on + # "NMake Makefiles" with no compiler — wipe that and force Ninja. + gen: list[str] = [] + if ninja is not None: + cached_gen = _read_cmake_cache_generator(cache_file) + if cached_gen and cached_gen != "Ninja": + progress.log(f'Replacing cmake generator "{cached_gen}" with Ninja…') + shutil.rmtree(build_dir, ignore_errors=True) + build_dir.mkdir(parents=True, exist_ok=True) + gen = ["-G", "Ninja", f"-DCMAKE_MAKE_PROGRAM={ninja}"] + elif sys.platform == "win32": + progress.log( + "warning: ninja not on PATH — cmake may pick NMake Makefiles " + "(ensure cmake-clang-v1 bin is active)" + ) + + compiler_args: list[str] = [] + if clang_c is not None: + compiler_args.append(f"-DCMAKE_C_COMPILER={clang_c}") + if clang_cxx is not None: + compiler_args.append(f"-DCMAKE_CXX_COMPILER={clang_cxx}") + cmd = [ "cmake", "-S", @@ -789,6 +834,7 @@ def _cmake_configure( *gen, "-DCMAKE_BUILD_TYPE=Release", f"-DPSX_PGO={pgo}", + *compiler_args, *extra, ] progress.log(" ".join(cmd)) @@ -802,6 +848,8 @@ def _cmake_configure( raise RuntimeError(f"cmake configure failed (exit {proc.returncode})") + + def _cmake_build( build_dir: Path, target: str, From 6877d712257281b464f1b5777b6466068f6c91eb Mon Sep 17 00:00:00 2001 From: Alex Vanderveen Date: Sat, 8 Aug 2026 20:01:36 -0400 Subject: [PATCH 2/3] SDL3 toolchain patch --- runtime/runtime.cmake | 11 +++++++++++ tools/toolchain_pack.py | 7 ++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/runtime/runtime.cmake b/runtime/runtime.cmake index 2bf86e75..e70ee0ff 100644 --- a/runtime/runtime.cmake +++ b/runtime/runtime.cmake @@ -97,7 +97,18 @@ if(_psx_sdl_backend STREQUAL "SDL3") option(PSX_SDL3_FETCH "Fetch the pinned SDL3 release when no system SDL3 package is found" ON) + # cmake-clang-v1 1.0.7+ ships static SDL3 under the pack root. Prefer that + # over FetchContent (avoids hundreds of Windows try_compile probes). + foreach(_psx_tc_env IN ITEMS RETCOMM_TOOLCHAIN_DIR PSXRECOMP_TOOLCHAIN_DIR) + if(DEFINED ENV{${_psx_tc_env}} AND NOT "$ENV{${_psx_tc_env}}" STREQUAL "") + list(PREPEND CMAKE_PREFIX_PATH "$ENV{${_psx_tc_env}}") + endif() + endforeach() + list(REMOVE_DUPLICATES CMAKE_PREFIX_PATH) find_package(SDL3 3.4 CONFIG QUIET COMPONENTS SDL3) + if(TARGET SDL3::SDL3) + message(STATUS "psxrecomp: using prebuilt/system SDL3 (skip FetchContent)") + endif() if(NOT TARGET SDL3::SDL3 AND PSX_SDL3_FETCH) include(FetchContent) # The fetched dependency is private to this build, so link it directly diff --git a/tools/toolchain_pack.py b/tools/toolchain_pack.py index d2d6ad24..168c3e75 100644 --- a/tools/toolchain_pack.py +++ b/tools/toolchain_pack.py @@ -481,7 +481,7 @@ def activate_toolchain_bin(bin_dir: Path, log=None) -> None: # Idempotent session PATH: only prepend when missing. if str(bin_dir) not in parts and prefix not in parts: os.environ["PATH"] = prefix + (os.pathsep + cur if cur else "") - # Windows cmake-clang-v1 ships zlib under the pack root; help FindZLIB. + # Pack root hosts zlib (Windows) + static SDL3 (1.0.7+) for find_package. pack_s = str(pack_root) os.environ["ZLIB_ROOT"] = pack_s os.environ["RETCOMM_TOOLCHAIN_DIR"] = pack_s @@ -492,6 +492,11 @@ def activate_toolchain_bin(bin_dir: Path, log=None) -> None: os.environ["CMAKE_PREFIX_PATH"] = pack_s elif pack_s not in prev_prefix.split(os.pathsep): os.environ["CMAKE_PREFIX_PATH"] = pack_s + os.pathsep + prev_prefix + # Hint CONFIG packages when present (harmless if absent on older packs). + sdl3_config = pack_root / "lib" / "cmake" / "SDL3" / "SDL3Config.cmake" + sdl3_config_alt = pack_root / "lib" / "cmake" / "SDL3" / "SDL3-config.cmake" + if sdl3_config.is_file() or sdl3_config_alt.is_file(): + os.environ["SDL3_DIR"] = str(pack_root / "lib" / "cmake" / "SDL3") lib_dir = pack_root / "lib" if lib_dir.is_dir() and not sys_platform_is_windows(): lib_s = str(lib_dir) From e8f96d75b53f8c41ce4c7cfc6b7adf2614c74240 Mon Sep 17 00:00:00 2001 From: Alex Vanderveen Date: Sat, 8 Aug 2026 20:01:44 -0400 Subject: [PATCH 3/3] SDL3 toolchain patch --- runtime/runtime.cmake | 11 +++++++++++ tools/toolchain_pack.py | 7 ++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/runtime/runtime.cmake b/runtime/runtime.cmake index 2bf86e75..e70ee0ff 100644 --- a/runtime/runtime.cmake +++ b/runtime/runtime.cmake @@ -97,7 +97,18 @@ if(_psx_sdl_backend STREQUAL "SDL3") option(PSX_SDL3_FETCH "Fetch the pinned SDL3 release when no system SDL3 package is found" ON) + # cmake-clang-v1 1.0.7+ ships static SDL3 under the pack root. Prefer that + # over FetchContent (avoids hundreds of Windows try_compile probes). + foreach(_psx_tc_env IN ITEMS RETCOMM_TOOLCHAIN_DIR PSXRECOMP_TOOLCHAIN_DIR) + if(DEFINED ENV{${_psx_tc_env}} AND NOT "$ENV{${_psx_tc_env}}" STREQUAL "") + list(PREPEND CMAKE_PREFIX_PATH "$ENV{${_psx_tc_env}}") + endif() + endforeach() + list(REMOVE_DUPLICATES CMAKE_PREFIX_PATH) find_package(SDL3 3.4 CONFIG QUIET COMPONENTS SDL3) + if(TARGET SDL3::SDL3) + message(STATUS "psxrecomp: using prebuilt/system SDL3 (skip FetchContent)") + endif() if(NOT TARGET SDL3::SDL3 AND PSX_SDL3_FETCH) include(FetchContent) # The fetched dependency is private to this build, so link it directly diff --git a/tools/toolchain_pack.py b/tools/toolchain_pack.py index d2d6ad24..168c3e75 100644 --- a/tools/toolchain_pack.py +++ b/tools/toolchain_pack.py @@ -481,7 +481,7 @@ def activate_toolchain_bin(bin_dir: Path, log=None) -> None: # Idempotent session PATH: only prepend when missing. if str(bin_dir) not in parts and prefix not in parts: os.environ["PATH"] = prefix + (os.pathsep + cur if cur else "") - # Windows cmake-clang-v1 ships zlib under the pack root; help FindZLIB. + # Pack root hosts zlib (Windows) + static SDL3 (1.0.7+) for find_package. pack_s = str(pack_root) os.environ["ZLIB_ROOT"] = pack_s os.environ["RETCOMM_TOOLCHAIN_DIR"] = pack_s @@ -492,6 +492,11 @@ def activate_toolchain_bin(bin_dir: Path, log=None) -> None: os.environ["CMAKE_PREFIX_PATH"] = pack_s elif pack_s not in prev_prefix.split(os.pathsep): os.environ["CMAKE_PREFIX_PATH"] = pack_s + os.pathsep + prev_prefix + # Hint CONFIG packages when present (harmless if absent on older packs). + sdl3_config = pack_root / "lib" / "cmake" / "SDL3" / "SDL3Config.cmake" + sdl3_config_alt = pack_root / "lib" / "cmake" / "SDL3" / "SDL3-config.cmake" + if sdl3_config.is_file() or sdl3_config_alt.is_file(): + os.environ["SDL3_DIR"] = str(pack_root / "lib" / "cmake" / "SDL3") lib_dir = pack_root / "lib" if lib_dir.is_dir() and not sys_platform_is_windows(): lib_s = str(lib_dir)