Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,18 @@ def build_extension(self, ext):
'-DBUILD_TOOLS=OFF',
]

if sys.platform == 'darwin':
# Handle macOS architecture flags set by cibuildwheel (e.g. ARCHFLAGS="-arch x86_64")
archflags = os.environ.get("ARCHFLAGS", "")
if archflags:
archs = []
if "arm64" in archflags:
archs.append("arm64")
if "x86_64" in archflags:
archs.append("x86_64")
Comment on lines +39 to +42
Copy link

Copilot AI Dec 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The substring matching approach for parsing ARCHFLAGS is fragile and could lead to false positives. For example, if ARCHFLAGS contains a path or comment with "arm64" or "x86_64", it would incorrectly match. The standard format for ARCHFLAGS is space-separated tokens like "-arch arm64 -arch x86_64", so the code should properly parse this format by splitting on whitespace and looking for values that follow the "-arch" flag. This ensures only actual architecture specifications are captured.

Suggested change
if "arm64" in archflags:
archs.append("arm64")
if "x86_64" in archflags:
archs.append("x86_64")
tokens = archflags.split()
for i, token in enumerate(tokens):
if token == "-arch" and i + 1 < len(tokens):
arch = tokens[i + 1]
if arch not in archs:
archs.append(arch)

Copilot uses AI. Check for mistakes.
if archs:
cmake_args.append(f'-DCMAKE_OSX_ARCHITECTURES={";".join(archs)}')

# Limit parallel jobs to avoid OOM on Docker with limited memory
# Default to 4 or CPU count, whichever is smaller, to be safe
import multiprocessing
Expand Down