Skip to content

Set CMAKE_OSX_ARCHITECTURES for macOS builds#2835

Closed
Herrtian wants to merge 2 commits into
pypa:mainfrom
Herrtian:docs-macos-arch-overrides
Closed

Set CMAKE_OSX_ARCHITECTURES for macOS builds#2835
Herrtian wants to merge 2 commits into
pypa:mainfrom
Herrtian:docs-macos-arch-overrides

Conversation

@Herrtian

@Herrtian Herrtian commented May 2, 2026

Copy link
Copy Markdown
Contributor

Refs #1190.

This sets CMAKE_OSX_ARCHITECTURES in the macOS build environment for x86_64, arm64, and universal2 builds, alongside the existing ARCHFLAGS setup. It uses setdefault, so projects that already set CMAKE_OSX_ARCHITECTURES keep their explicit value.

Checked with:

  • .\.venv\Scripts\python.exe -m pytest unit_test\macos_environment_test.py -q
  • uv run --with ruff ruff check cibuildwheel\platforms\macos.py unit_test\macos_environment_test.py
  • git diff --check

@agriyakhetarpal agriyakhetarpal left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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! :)

@Herrtian Herrtian changed the title Document macOS arch-specific build env Set CMAKE_OSX_ARCHITECTURES for macOS builds May 3, 2026
@Herrtian

Herrtian commented May 3, 2026

Copy link
Copy Markdown
Contributor Author

Thanks, that makes sense. I switched this from the docs-only example to the code path in dd342b1.

It now sets CMAKE_OSX_ARCHITECTURES next to the existing macOS ARCHFLAGS defaults for x86_64, arm64, and universal2, while still preserving any value the project already set explicitly. I also dropped the CMake-specific docs example so the PR is focused on the environment setup instead.

I added a small unit test for the arch mapping and for keeping existing values.

@mayeut

mayeut commented May 4, 2026

Copy link
Copy Markdown
Member

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.
See also #1190 (comment)

@henryiii

henryiii commented May 4, 2026

Copy link
Copy Markdown
Contributor

scikit-build-core should read the Python-specific values and convert them for you. Is it not working?

@Herrtian

Herrtian commented May 4, 2026

Copy link
Copy Markdown
Contributor Author

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.

@Herrtian Herrtian closed this May 4, 2026
@agriyakhetarpal

Copy link
Copy Markdown
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants