Add macOS architecture flags support for cibuildwheel#15
Conversation
…wheel compatibility
There was a problem hiding this comment.
Pull request overview
This PR enhances the CMake-based Python extension build system to support macOS architecture flags set by cibuildwheel. It adds logic to parse the ARCHFLAGS environment variable and translate it into the appropriate CMAKE_OSX_ARCHITECTURES CMake configuration, enabling proper multi-architecture builds (x86_64 and arm64) on macOS.
Key changes:
- Added platform-specific handling for macOS in the build extension method
- Introduced ARCHFLAGS parsing to extract architecture specifications
- Configured CMAKE_OSX_ARCHITECTURES based on detected architectures
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| if "arm64" in archflags: | ||
| archs.append("arm64") | ||
| if "x86_64" in archflags: | ||
| archs.append("x86_64") |
There was a problem hiding this comment.
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.
| 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) |
Introduce support for macOS architecture flags in the CMake build process to enhance compatibility with cibuildwheel. This change allows the build system to recognize and utilize architecture flags set in the environment.