Set CMAKE_OSX_ARCHITECTURES for macOS builds#2835
Conversation
agriyakhetarpal
left a comment
There was a problem hiding this comment.
Thanks for making a start on this, @Herrtian! This looks fine to me in principle, but I'm still unsure because #1190 (comment) seemed to suggest we should add CMAKE_OSX_ARCHITECTURES to the macOS platform code itself for projects to use, rather than in the docs. We should do it unless the project already explicitly sets this environment variable, since we don't want to change how the build takes place.
This example is also CMake-specific, but we also support other build backends, one being meson-python, and that uses cross files to determine whether cross-compilation should take place. So the docs should probably be build-backend-agnostic.
I think @henryiii would have more coherent thoughts than I do! :)
|
Thanks, that makes sense. I switched this from the docs-only example to the code path in dd342b1. It now sets I added a small unit test for the arch mapping and for keeping existing values. |
|
IMHO, this is a build backend/custom CMake implementation issue and cibuildwheel should not be working around those. The workaround in cibuildwheel will mask issues building from an SDist or building the project directly without the project knowing they have an issue with their build backend/custom CMake implementation on macOS. |
|
scikit-build-core should read the Python-specific values and convert them for you. Is it not working? |
|
Thanks, that feedback makes sense. I agree this should not live in cibuildwheel if the build backend or project should derive the CMake architecture from the Python/macOS platform values itself. I'm closing this rather than keep pushing a workaround in the wrong layer. |
|
Sorry for directing you the wrong way @Herrtian! I think I'll probably close the linked issue as resolved for now, and we can revisit it if someone has any trouble cross-compiling on macOS later. |
Refs #1190.
This sets
CMAKE_OSX_ARCHITECTURESin the macOS build environment forx86_64,arm64, anduniversal2builds, alongside the existingARCHFLAGSsetup. It usessetdefault, so projects that already setCMAKE_OSX_ARCHITECTURESkeep their explicit value.Checked with:
.\.venv\Scripts\python.exe -m pytest unit_test\macos_environment_test.py -quv run --with ruff ruff check cibuildwheel\platforms\macos.py unit_test\macos_environment_test.pygit diff --check