|
3 | 3 |
|
4 | 4 | from __future__ import annotations |
5 | 5 |
|
| 6 | +import functools |
6 | 7 | import io |
7 | 8 | import logging |
8 | 9 | import os |
9 | | -import platform |
10 | 10 | import re |
11 | 11 | import shutil |
12 | 12 | import subprocess |
|
28 | 28 | logger = logging.getLogger(__name__) |
29 | 29 |
|
30 | 30 |
|
31 | | -BIT_SIZE, LINKAGE = platform.architecture() |
| 31 | +RE_MACHINE = re.compile(r".*\((.+)\)\]") |
| 32 | + |
| 33 | + |
| 34 | +@functools.cache |
| 35 | +def python_machine() -> str: |
| 36 | + """Return the Python machine architecture (e.g. 'i386', 'AMD64', 'ARM64').""" |
| 37 | + # Only needs to function correctly for Windows platforms. |
| 38 | + match = RE_MACHINE.match(sys.version) |
| 39 | + assert match, sys.version |
| 40 | + (machine,) = match.groups() |
| 41 | + return {"Intel": "i386"}.get(machine, machine) |
| 42 | + |
32 | 43 |
|
33 | 44 | # Reject versions of SDL older than this, update the requirements in the readme if you change this. |
34 | 45 | SDL_MIN_VERSION = (3, 2, 0) |
@@ -386,10 +397,10 @@ def get_cdef() -> tuple[str, dict[str, str]]: |
386 | 397 | # Bundle the Windows SDL DLL. |
387 | 398 | if sys.platform == "win32" and SDL_BUNDLE_PATH is not None: |
388 | 399 | include_dirs.append(str(SDL_INCLUDE)) |
389 | | - ARCH_MAPPING = {"32bit": "x86", "64bit": "x64"} |
390 | | - SDL_LIB_DIR = Path(SDL_BUNDLE_PATH, "lib/", ARCH_MAPPING[BIT_SIZE]) |
| 400 | + ARCH_MAPPING = {"i386": "x86", "AMD64": "x64", "ARM64": "arm64"} |
| 401 | + SDL_LIB_DIR = Path(SDL_BUNDLE_PATH, "lib/", ARCH_MAPPING[python_machine()]) |
391 | 402 | library_dirs.append(str(SDL_LIB_DIR)) |
392 | | - SDL_LIB_DEST = Path("tcod", ARCH_MAPPING[BIT_SIZE]) |
| 403 | + SDL_LIB_DEST = Path("tcod", ARCH_MAPPING[python_machine()]) |
393 | 404 | SDL_LIB_DEST.mkdir(exist_ok=True) |
394 | 405 | SDL_LIB_DEST_FILE = SDL_LIB_DEST / "SDL3.dll" |
395 | 406 | SDL_LIB_FILE = SDL_LIB_DIR / "SDL3.dll" |
|
0 commit comments