Skip to content

Commit 110f3a2

Browse files
committed
fixup! fixup! fixup! Parse SDL headers from EMSDK during Pyodide builds
1 parent a4681b3 commit 110f3a2

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

setup.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33

44
from __future__ import annotations
55

6+
import os
67
import platform
8+
import subprocess
79
import sys
810
from pathlib import Path
911

@@ -35,11 +37,45 @@ def get_package_data() -> list[str]:
3537
return files
3638

3739

40+
def check_sdl_version() -> None:
41+
"""Check the local SDL version on Linux distributions."""
42+
if not sys.platform.startswith("linux"):
43+
return
44+
if "PYODIDE" in os.environ:
45+
return
46+
needed_version = "{}.{}.{}".format(*SDL_VERSION_NEEDED)
47+
try:
48+
sdl_version_str = subprocess.check_output(
49+
["pkg-config", "sdl3", "--modversion"], # noqa: S607
50+
universal_newlines=True,
51+
).strip()
52+
except FileNotFoundError:
53+
try:
54+
sdl_version_str = subprocess.check_output(["sdl3-config", "--version"], universal_newlines=True).strip() # noqa: S607
55+
except FileNotFoundError as exc:
56+
msg = (
57+
f"libsdl3-dev or equivalent must be installed on your system and must be at least version {needed_version}."
58+
"\nsdl3-config must be on PATH."
59+
)
60+
raise RuntimeError(msg) from exc
61+
except subprocess.CalledProcessError as exc:
62+
if sys.version_info >= (3, 11):
63+
exc.add_note(f"Note: {os.environ.get('PKG_CONFIG_PATH')=}")
64+
raise
65+
print(f"Found SDL {sdl_version_str}.")
66+
sdl_version = tuple(int(s) for s in sdl_version_str.split("."))
67+
if sdl_version < SDL_VERSION_NEEDED:
68+
msg = f"SDL version must be at least {needed_version}, (found {sdl_version_str})"
69+
raise RuntimeError(msg)
70+
71+
3872
if not (SETUP_DIR / "libtcod/src").exists():
3973
print("Libtcod submodule is uninitialized.")
4074
print("Did you forget to run 'git submodule update --init'?")
4175
sys.exit(1)
4276

77+
check_sdl_version()
78+
4379
setup(
4480
py_modules=["libtcodpy"],
4581
packages=["tcod", "tcod.sdl", "tcod.__pyinstaller"],

0 commit comments

Comments
 (0)