|
14 | 14 |
|
15 | 15 | import os |
16 | 16 | import pathlib |
17 | | -from sysconfig import get_platform |
| 17 | +import platform |
| 18 | +import sys |
18 | 19 | from typing import Any, Dict |
19 | 20 |
|
20 | 21 | import setuptools # type: ignore |
21 | | -import setuptools.command.build_py # type: ignore |
22 | 22 | from wheel.bdist_wheel import bdist_wheel as _bdist_wheel # type: ignore |
23 | 23 |
|
24 | 24 | here = pathlib.Path(__file__).parent.resolve() |
|
27 | 27 | exec(f.read(), about) |
28 | 28 |
|
29 | 29 |
|
| 30 | +def get_platform_tag(): |
| 31 | + """Get the wheel platform tag for the current/target platform. |
| 32 | +
|
| 33 | + On macOS, we must respect MACOSX_DEPLOYMENT_TARGET and ARCHFLAGS environment |
| 34 | + variables that cibuildwheel sets, rather than using sysconfig.get_platform() |
| 35 | + which returns Python's compile-time values. |
| 36 | + """ |
| 37 | + if sys.platform == "darwin": |
| 38 | + # Get deployment target from environment (set by cibuildwheel) or fall back |
| 39 | + target = os.environ.get("MACOSX_DEPLOYMENT_TARGET") |
| 40 | + if not target: |
| 41 | + target = platform.mac_ver()[0] |
| 42 | + parts = target.split(".") |
| 43 | + target = f"{parts[0]}.{parts[1] if len(parts) > 1 else '0'}" |
| 44 | + |
| 45 | + version_tag = target.replace(".", "_") |
| 46 | + |
| 47 | + # Check ARCHFLAGS for cross-compilation (cibuildwheel sets this) |
| 48 | + archflags = os.environ.get("ARCHFLAGS", "") |
| 49 | + if "-arch arm64" in archflags: |
| 50 | + arch = "arm64" |
| 51 | + elif "-arch x86_64" in archflags: |
| 52 | + arch = "x86_64" |
| 53 | + else: |
| 54 | + arch = platform.machine() |
| 55 | + |
| 56 | + return f"macosx_{version_tag}_{arch}" |
| 57 | + elif sys.platform == "linux": |
| 58 | + return f"linux_{platform.machine()}" |
| 59 | + elif sys.platform == "win32": |
| 60 | + arch = platform.machine() |
| 61 | + if arch == "AMD64": |
| 62 | + arch = "amd64" |
| 63 | + return f"win_{arch}" |
| 64 | + else: |
| 65 | + return f"{platform.system().lower()}_{platform.machine()}" |
| 66 | + |
| 67 | + |
30 | 68 | class bdist_wheel(_bdist_wheel): |
31 | 69 | def finalize_options(self): |
32 | | - self.plat_name = get_platform() # force a platform tag |
| 70 | + self.plat_name = get_platform_tag() |
33 | 71 | _bdist_wheel.finalize_options(self) |
34 | 72 |
|
35 | 73 |
|
|
0 commit comments