Skip to content

Commit a673972

Browse files
committed
Add ARM64 Windows wheels to be tested and published
Update Windows platform detection, unsure if this is better in any way but I need to sort x64 from arm64. This architecture may become more common in the future, I'd rather support it now just in case.
1 parent 38978db commit a673972

File tree

4 files changed

+35
-16
lines changed

4 files changed

+35
-16
lines changed

.github/workflows/python-package.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,9 @@ jobs:
118118
- os: "windows-latest"
119119
python-version: "3.10"
120120
architecture: "x86"
121+
- os: "windows-11-arm"
122+
python-version: "3.11"
123+
architecture: "arm64"
121124
fail-fast: false
122125

123126
steps:

build_sdl.py

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33

44
from __future__ import annotations
55

6+
import functools
67
import io
78
import logging
89
import os
9-
import platform
1010
import re
1111
import shutil
1212
import subprocess
@@ -28,7 +28,20 @@
2828
logger = logging.getLogger(__name__)
2929

3030

31-
BIT_SIZE, LINKAGE = platform.architecture()
31+
RE_MACHINE = re.compile(r".*\((.+)\)\]", re.DOTALL)
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, repr(sys.version)
40+
(machine,) = match.groups()
41+
machine = {"Intel": "i386"}.get(machine, machine)
42+
logger.info(f"python_machine: {machine}")
43+
return machine
44+
3245

3346
# Reject versions of SDL older than this, update the requirements in the readme if you change this.
3447
SDL_MIN_VERSION = (3, 2, 0)
@@ -386,10 +399,10 @@ def get_cdef() -> tuple[str, dict[str, str]]:
386399
# Bundle the Windows SDL DLL.
387400
if sys.platform == "win32" and SDL_BUNDLE_PATH is not None:
388401
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])
402+
ARCH_MAPPING = {"i386": "x86", "AMD64": "x64", "ARM64": "arm64"}
403+
SDL_LIB_DIR = Path(SDL_BUNDLE_PATH, "lib/", ARCH_MAPPING[python_machine()])
391404
library_dirs.append(str(SDL_LIB_DIR))
392-
SDL_LIB_DEST = Path("tcod", ARCH_MAPPING[BIT_SIZE])
405+
SDL_LIB_DEST = Path("tcod", ARCH_MAPPING[python_machine()])
393406
SDL_LIB_DEST.mkdir(exist_ok=True)
394407
SDL_LIB_DEST_FILE = SDL_LIB_DEST / "SDL3.dll"
395408
SDL_LIB_FILE = SDL_LIB_DIR / "SDL3.dll"

setup.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
from __future__ import annotations
55

6-
import platform
76
import sys
87
from pathlib import Path
98

@@ -18,18 +17,19 @@
1817

1918
def get_package_data() -> list[str]:
2019
"""Get data files which will be included in the main tcod/ directory."""
21-
bit_size, _ = platform.architecture()
2220
files = [
2321
"py.typed",
2422
"lib/LIBTCOD-CREDITS.txt",
2523
"lib/LIBTCOD-LICENSE.txt",
2624
"lib/README-SDL.txt",
2725
]
28-
if "win32" in sys.platform:
29-
if bit_size == "32bit":
30-
files += ["x86/SDL3.dll"]
31-
else:
26+
if sys.platform == "win32":
27+
if "ARM64" in sys.version:
28+
files += ["arm64/SDL3.dll"]
29+
elif "AMD64" in sys.version:
3230
files += ["x64/SDL3.dll"]
31+
else:
32+
files += ["x86/SDL3.dll"]
3333
if sys.platform == "darwin":
3434
files += ["SDL3.framework/Versions/A/SDL3"]
3535
return files

tcod/cffi.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,9 @@
44

55
import logging
66
import os
7-
import platform
87
import sys
98
from pathlib import Path
10-
from typing import Any
9+
from typing import Any, Literal
1110

1211
import cffi
1312

@@ -39,9 +38,13 @@ def verify_dependencies() -> None:
3938
raise RuntimeError(msg)
4039

4140

42-
def get_architecture() -> str:
43-
"""Return the Windows architecture, one of "x86" or "x64"."""
44-
return "x86" if platform.architecture()[0] == "32bit" else "x64"
41+
def get_architecture() -> Literal["x86", "x64", "arm64"]:
42+
"""Return the Windows architecture."""
43+
if "(ARM64)" in sys.version:
44+
return "arm64"
45+
if "(AMD64)" in sys.version:
46+
return "x64"
47+
return "x86"
4548

4649

4750
def get_sdl_version() -> str:

0 commit comments

Comments
 (0)