Skip to content

Commit 291522d

Browse files
committed
Use alpha builds of Pyodide supporting SDL3.
Stable version is too old and only supports SDL2. Try not to bundle win/mac binaries during Pyodide build
1 parent fc0f5b3 commit 291522d

File tree

4 files changed

+32
-13
lines changed

4 files changed

+32
-13
lines changed

.github/workflows/python-package.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -334,9 +334,10 @@ jobs:
334334
with:
335335
install-linux-dependencies: true
336336
build-type: "Debug"
337-
version: ${{ env.sdl-version }}
337+
version: "3.2.4" # Should be equal or less than the version used by Emscripten
338338
- uses: pypa/[email protected]
339339
env:
340+
CIBW_BUILD: cp313-pyodide_wasm32
340341
CIBW_PLATFORM: pyodide
341342
- name: Archive wheel
342343
uses: actions/upload-artifact@v4

.vscode/settings.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@
141141
"dunder",
142142
"DVLINE",
143143
"elif",
144+
"Emscripten",
144145
"ENDCALL",
145146
"endianness",
146147
"epel",

build_sdl.py

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -249,16 +249,27 @@ def on_directive_handle(
249249
return super().on_directive_handle(directive, tokens, if_passthru, preceding_tokens)
250250

251251

252+
def get_emscripten_include_dir() -> Path:
253+
"""Find and return the Emscripten include dir."""
254+
# None of the EMSDK environment variables exist! Search PATH for Emscripten as a workaround
255+
for path in os.environ["PATH"].split(os.pathsep)[::-1]:
256+
if Path(path).match("upstream/emscripten"):
257+
return Path(path, "system/include").resolve(strict=True)
258+
raise AssertionError(os.environ["PATH"])
259+
260+
252261
check_sdl_version()
253262

254-
if sys.platform == "win32" or sys.platform == "darwin":
263+
SDL_PARSE_PATH: Path | None = None
264+
SDL_BUNDLE_PATH: Path | None = None
265+
if (sys.platform == "win32" or sys.platform == "darwin") and "PYODIDE" not in os.environ:
255266
SDL_PARSE_PATH = unpack_sdl(SDL_PARSE_VERSION)
256267
SDL_BUNDLE_PATH = unpack_sdl(SDL_BUNDLE_VERSION)
257268

258269
SDL_INCLUDE: Path
259-
if sys.platform == "win32":
270+
if sys.platform == "win32" and SDL_PARSE_PATH is not None:
260271
SDL_INCLUDE = SDL_PARSE_PATH / "include"
261-
elif sys.platform == "darwin":
272+
elif sys.platform == "darwin" and SDL_PARSE_PATH is not None:
262273
SDL_INCLUDE = SDL_PARSE_PATH / "Versions/A/Headers"
263274
else: # Unix
264275
matches = re.findall(
@@ -275,6 +286,7 @@ def on_directive_handle(
275286
raise AssertionError(matches)
276287
assert SDL_INCLUDE
277288

289+
logger.info(f"{SDL_INCLUDE=}")
278290

279291
EXTRA_CDEF = """
280292
#define SDLK_SCANCODE_MASK ...
@@ -358,7 +370,7 @@ def get_cdef() -> tuple[str, dict[str, str]]:
358370
libraries += ["SDL3"]
359371

360372
# Bundle the Windows SDL DLL.
361-
if sys.platform == "win32":
373+
if sys.platform == "win32" and SDL_BUNDLE_PATH is not None:
362374
include_dirs.append(str(SDL_INCLUDE))
363375
ARCH_MAPPING = {"32bit": "x86", "64bit": "x64"}
364376
SDL_LIB_DIR = Path(SDL_BUNDLE_PATH, "lib/", ARCH_MAPPING[BIT_SIZE])
@@ -372,18 +384,19 @@ def get_cdef() -> tuple[str, dict[str, str]]:
372384

373385
# Link to the SDL framework on MacOS.
374386
# Delocate will bundle the binaries in a later step.
375-
if sys.platform == "darwin":
387+
if sys.platform == "darwin" and SDL_BUNDLE_PATH is not None:
376388
include_dirs.append(SDL_INCLUDE)
377389
extra_link_args += [f"-F{SDL_BUNDLE_PATH}/.."]
378390
extra_link_args += ["-rpath", f"{SDL_BUNDLE_PATH}/.."]
379391
extra_link_args += ["-rpath", "/usr/local/opt/llvm/lib/"]
380392

381-
# Use sdl-config to link to SDL on Linux.
382-
if sys.platform not in ["win32", "darwin"]:
393+
if "PYODIDE" in os.environ:
394+
extra_compile_args += ["--use-port=sdl3"]
395+
elif sys.platform not in ["win32", "darwin"]:
396+
# Use sdl-config to link to SDL on Linux.
383397
extra_compile_args += (
384398
subprocess.check_output(["pkg-config", "sdl3", "--cflags"], universal_newlines=True).strip().split()
385399
)
386-
if "PYODIDE" not in os.environ:
387-
extra_link_args += (
388-
subprocess.check_output(["pkg-config", "sdl3", "--libs"], universal_newlines=True).strip().split()
389-
)
400+
extra_link_args += (
401+
subprocess.check_output(["pkg-config", "sdl3", "--libs"], universal_newlines=True).strip().split()
402+
)

pyproject.toml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,11 @@ filterwarnings = [
100100
]
101101

102102
[tool.cibuildwheel] # https://cibuildwheel.pypa.io/en/stable/options/
103-
enable = ["pypy"]
103+
enable = ["pypy", "pyodide-prerelease"]
104+
105+
[tool.cibuildwheel.pyodide]
106+
dependency-versions = "latest" # Until pyodide-version is stable on cibuildwheel
107+
pyodide-version = "0.28.0a3"
104108

105109
[tool.mypy]
106110
files = ["."]

0 commit comments

Comments
 (0)