Skip to content

Commit 7d12117

Browse files
committed
Test Pyodide builds
Simple import test
1 parent 33a24b6 commit 7d12117

File tree

3 files changed

+34
-18
lines changed

3 files changed

+34
-18
lines changed

.github/workflows/python-package.yml

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -330,15 +330,16 @@ jobs:
330330
fetch-depth: ${{ env.git-depth }}
331331
- name: Checkout submodules
332332
run: git submodule update --init --recursive --depth 1
333-
- uses: HexDecimal/my-setup-sdl-action@v1.0.0
334-
with:
335-
install-linux-dependencies: true
336-
build-type: "Debug"
337-
version: "3.2.4" # Should be equal or less than the version used by Emscripten
333+
#- uses: HexDecimal/my-setup-sdl-action@v1.0.0
334+
# with:
335+
# install-linux-dependencies: true
336+
# build-type: "Debug"
337+
# version: "3.2.4" # Should be equal or less than the version used by Emscripten
338338
- uses: pypa/cibuildwheel@v3.1.3
339339
env:
340340
CIBW_BUILD: cp313-pyodide_wasm32
341341
CIBW_PLATFORM: pyodide
342+
CIBW_TEST_COMMAND: python -c "import tcod.context"
342343
- name: Archive wheel
343344
uses: actions/upload-artifact@v4
344345
with:

build_sdl.py

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@
3737
# The SDL version to include in binary distributions.
3838
SDL_BUNDLE_VERSION = os.environ.get("SDL_VERSION", "3.2.16")
3939

40-
4140
# Used to remove excessive newlines in debug outputs.
4241
RE_NEWLINES = re.compile(r"\n\n+")
4342
# Functions using va_list need to be culled.
@@ -124,6 +123,9 @@
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

128130
def 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

276284
SDL_PARSE_PATH: Path | None = None
277285
SDL_BUNDLE_PATH: Path | None = None
@@ -285,10 +293,11 @@ def get_emscripten_include_dir() -> Path:
285293
elif sys.platform == "darwin" and SDL_PARSE_PATH is not None:
286294
SDL_INCLUDE = SDL_PARSE_PATH / "Versions/A/Headers"
287295
else: # 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

407416
if "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=}")
409425
elif sys.platform not in ["win32", "darwin"]:
410426
# Use sdl-config to link to SDL on Linux.
411427
extra_compile_args += (

tcod/cffi.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,15 @@
1717

1818
REQUIRED_SDL_VERSION = (3, 2, 0)
1919

20-
ffi_check = cffi.FFI()
21-
ffi_check.cdef(
22-
"""
23-
int SDL_GetVersion(void);
24-
"""
25-
)
26-
2720

2821
def verify_dependencies() -> None:
2922
"""Try to make sure dependencies exist on this system."""
23+
ffi_check = cffi.FFI()
24+
ffi_check.cdef(
25+
"""
26+
int SDL_GetVersion(void);
27+
"""
28+
)
3029
if sys.platform == "win32":
3130
lib_test: Any = ffi_check.dlopen("SDL3.dll") # Make sure SDL3.dll is here.
3231
int_version = lib_test.SDL_GetVersion() # Need to check this version.

0 commit comments

Comments
 (0)