Skip to content

Commit c3c318c

Browse files
committed
Parse SDL headers directly from Emscripten
Simpler and easier than including the SDL headers externally
1 parent 626ed2c commit c3c318c

3 files changed

Lines changed: 15 additions & 17 deletions

File tree

‎.github/workflows/python-package.yml‎

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -350,25 +350,14 @@ jobs:
350350
strategy:
351351
fail-fast: false
352352
matrix:
353-
include: # https://pyodide.org/en/stable/development/abi.html
354-
- python: "cp313"
355-
sdl-version: "3.2.4" # For Emscripten 4.0.9
356-
- python: "cp314"
357-
sdl-version: "3.2.30" # For Emscripten 5.0.3
358-
- python: "cp315"
359-
sdl-version: "3.4.2" # For Emscripten 6.0.5
353+
python: ["cp313", "cp314", "cp315"] # https://pyodide.org/en/stable/development/abi.html
360354
steps:
361355
- uses: actions/checkout@v7
362356
with:
363357
persist-credentials: false
364358
fetch-depth: ${{ env.git-depth }}
365359
- name: Checkout submodules
366360
run: git submodule update --init --recursive --depth 1
367-
- uses: libsdl-org/setup-sdl@v1.0.1
368-
with:
369-
install-linux-dependencies: true
370-
build-type: "Debug"
371-
version: ${{ matrix.sdl-version }} # Should be equal or less than the version used by Emscripten
372361
- uses: pypa/cibuildwheel@v4.3.3
373362
env:
374363
CIBW_BUILD: ${{ matrix.python }}-pyodide_wasm32

‎.vscode/settings.json‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@
149149
"dunder",
150150
"DVLINE",
151151
"elif",
152+
"embuilder",
152153
"Emscripten",
153154
"EMSDK",
154155
"ENDCALL",

‎build_sdl.py‎

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,8 @@ def check_sdl_version() -> None:
147147
"""Check the local SDL3 version on Linux distributions."""
148148
if not sys.platform.startswith("linux"):
149149
return
150+
if "PYODIDE" in os.environ:
151+
return
150152
needed_version = f"{SDL_MIN_VERSION[0]}.{SDL_MIN_VERSION[1]}.{SDL_MIN_VERSION[2]}"
151153
try:
152154
sdl_version_str = subprocess.check_output(
@@ -280,12 +282,14 @@ def on_directive_handle(
280282
return super().on_directive_handle(directive, tokens, if_passthru, preceding_tokens)
281283

282284

283-
def get_emscripten_include_dir() -> Path:
284-
"""Find and return the Emscripten include dir."""
285+
def get_emscripten_dir() -> Path:
286+
"""Find and return the Emscripten root directory."""
287+
if "EMSDK" in os.environ:
288+
return Path(os.environ["EMSDK"])
285289
# None of the EMSDK environment variables exist! Search PATH for Emscripten as a workaround
286290
for path in os.environ["PATH"].split(os.pathsep)[::-1]:
287-
if Path(path).match("upstream/emscripten"):
288-
return Path(path, "system/include").resolve(strict=True)
291+
if Path(path).match("upstream/emscripten/embuilder"):
292+
return Path(path).resolve(strict=True)
289293
raise AssertionError(os.environ["PATH"])
290294

291295

@@ -298,7 +302,11 @@ def get_emscripten_include_dir() -> Path:
298302
SDL_BUNDLE_PATH = unpack_sdl(SDL_BUNDLE_VERSION)
299303

300304
SDL_INCLUDE: Path
301-
if sys.platform == "win32" and SDL_PARSE_PATH is not None:
305+
if "PYODIDE" in os.environ:
306+
embuilder = Path(get_emscripten_dir(), "upstream/emscripten/embuilder")
307+
subprocess.run([embuilder, "build", "sdl3"], check=True)
308+
SDL_INCLUDE = Path(get_emscripten_dir(), "upstream/emscripten/cache/sysroot/include/SDL3")
309+
elif sys.platform == "win32" and SDL_PARSE_PATH is not None:
302310
SDL_INCLUDE = SDL_PARSE_PATH / "include"
303311
elif sys.platform == "darwin" and SDL_PARSE_PATH is not None:
304312
SDL_INCLUDE = SDL_PARSE_PATH / "Versions/A/Headers"

0 commit comments

Comments
 (0)