@@ -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+
252261check_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
258269SDL_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"
263274else : # 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
279291EXTRA_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+ )
0 commit comments