Skip to content

Commit a55b375

Browse files
mrecachinasCopilot
andcommitted
Fix setup.py cross-compilation flags for cibuildwheel
- macOS: detect x86_64 cross-compile via CIBW_ARCHS_MACOS, use -msse4.2 -mpopcnt instead of -mcpu=apple-m1 for x86_64 targets - Linux x86_64: use -msse4.2 -mpopcnt instead of -march=native for manylinux portability - Linux aarch64: use -march=armv8-a+simd Previously, machine() returned 'arm64' on M1 runners even when building x86_64 wheels, causing -mcpu=apple-m1 to be passed incorrectly. And -march=native in manylinux containers didn't include popcnt, breaking _mm_popcnt_u64 compilation. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent e9903c8 commit a55b375

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

setup.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,22 @@
1010
from os import environ
1111

1212
extra_compile_args = []
13-
if system().lower() == "darwin" and (
14-
machine().lower() == "arm64" or environ.get("CIBW_ARCHS_MACOS", "") == "arm64"
15-
):
16-
extra_compile_args.append("-mcpu=apple-m1")
13+
cibw_arch = environ.get("CIBW_ARCHS_MACOS", "")
14+
cibw_linux_arch = environ.get("CIBW_ARCHS_LINUX", "")
15+
host_machine = machine().lower()
16+
17+
if system().lower() == "darwin":
18+
if cibw_arch == "x86_64" or (cibw_arch == "" and host_machine != "arm64"):
19+
extra_compile_args.extend(["-msse4.2", "-mpopcnt"])
20+
else:
21+
extra_compile_args.append("-mcpu=apple-m1")
1722
elif uname().system == "Windows":
1823
extra_compile_args.append("-O2")
1924
extra_compile_args.append("/d2FH4-")
25+
elif cibw_linux_arch == "aarch64" or host_machine == "aarch64":
26+
extra_compile_args.append("-march=armv8-a+simd")
2027
else:
21-
extra_compile_args.append("-march=native")
28+
extra_compile_args.extend(["-msse4.2", "-mpopcnt"])
2229

2330
setup(
2431
ext_modules=[

0 commit comments

Comments
 (0)