3737# The SDL version to include in binary distributions.
3838SDL_BUNDLE_VERSION = os .environ .get ("SDL_VERSION" , "3.2.16" )
3939
40-
4140# Used to remove excessive newlines in debug outputs.
4241RE_NEWLINES = re .compile (r"\n\n+" )
4342# Functions using va_list need to be culled.
124123 )
125124)
126125
126+ CMAKE_CMD = ("emcmake" , "cmake" ) if "PYODIDE" in os .environ else ("cmake" ,)
127+ CMAKE_FIND_SDL_CMD = (* CMAKE_CMD , "--find-package" , "-D" , "NAME=SDL3" , "-D" , "COMPILER_ID=GNU" , "-D" , "LANGUAGE=C" )
128+
127129
128130def check_sdl_version () -> None :
129131 """Check the local SDL3 version on Linux distributions."""
@@ -271,7 +273,13 @@ def get_emscripten_include_dir() -> Path:
271273 raise AssertionError (os .environ ["PATH" ])
272274
273275
274- check_sdl_version ()
276+ if "PYODIDE" in os .environ :
277+ with TemporaryDirectory () as tmp_dir :
278+ blank_source = Path (tmp_dir , "blank.c" )
279+ blank_source .write_text ("" )
280+ subprocess .run (["emcc" , "--use-port=sdl3" , blank_source ], check = True )
281+
282+ # check_sdl_version()
275283
276284SDL_PARSE_PATH : Path | None = None
277285SDL_BUNDLE_PATH : Path | None = None
@@ -285,10 +293,11 @@ def get_emscripten_include_dir() -> Path:
285293elif sys .platform == "darwin" and SDL_PARSE_PATH is not None :
286294 SDL_INCLUDE = SDL_PARSE_PATH / "Versions/A/Headers"
287295else : # Unix
288- matches = re .findall (
289- r"-I(\S+)" ,
290- subprocess .check_output (["pkg-config" , "sdl3" , "--cflags" ], universal_newlines = True ),
291- )
296+ try :
297+ out = subprocess .check_output (["pkg-config" , "sdl3" , "--cflags" ], universal_newlines = True )
298+ except Exception :
299+ out = subprocess .check_output ((* CMAKE_FIND_SDL_CMD , "-D" , "MODE=COMPILE" ), text = True )
300+ matches = re .findall (r"-I(\S+)" , out )
292301 if not matches :
293302 matches = ["/usr/include" ]
294303
@@ -406,6 +415,13 @@ def get_cdef() -> tuple[str, dict[str, str]]:
406415
407416if "PYODIDE" in os .environ :
408417 extra_compile_args += ["--use-port=sdl3" ]
418+ extra_link_args += ["--use-port=sdl3" ]
419+ extra_compile_args += (
420+ subprocess .check_output ((* CMAKE_FIND_SDL_CMD , "-D" , "MODE=COMPILE" ), text = True ).strip ().split ()
421+ )
422+ extra_link_args += subprocess .check_output ((* CMAKE_FIND_SDL_CMD , "-D" , "MODE=LINK" ), text = True ).strip ().split ()
423+ print (f"{ extra_compile_args = } " )
424+ print (f"{ extra_link_args = } " )
409425elif sys .platform not in ["win32" , "darwin" ]:
410426 # Use sdl-config to link to SDL on Linux.
411427 extra_compile_args += (
0 commit comments