Skip to content

BLD: Add support for building iOS wheels #28759

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 15 commits into
base: main
Choose a base branch
from

Conversation

freakboy3742
Copy link
Contributor

@freakboy3742 freakboy3742 commented Apr 18, 2025

Adds iOS as a test and release target for NumPy.

UPDATE: 30 July 2025 This PR is almost ready for review. PR body reflects current status.

In an environment where:

  • Xcode and the iOS SDK is installed, with all licences accepted.
  • cibuildwheel 3.1.2 is installed
  • ninja is available on the path

This branch will build and test accelerated iOS device and simulator wheels:

CIBW_PLATFORM=ios CIBW_ENVIRONMENT="INSTALL_OPENBLAS=false RUNNER_OS=iOS IPHONEOS_DEPLOYMENT_TARGET=17.0" cibuildwheel 

The build will also work without the IPHONEOS_DEPLOYMENT_TARGET definition, but with an unaccelerated version of blas (this is the analog of the MACOSX_DEPLOYMENT_TARGET=14.0 configuration, except that there isn't a pre-compiled openBLAS for iOS to fall back on).

Other notable details of this PR:

  • The pytest version used for testing has been bumped to 8.4.1, to avoid an issue with getuser() support on 3.13 that impacts iOS
  • CI workflows have been added to build and test iOS. The workflow is modelled off the Emscripten workflow, and includes triggers for manual dispatch, and publication of nightly wheels to the Scientific Python Nightly package index.
  • iOS CI workflows build x86_64 iOS simulator wheels - but they aren't tested. Unfortunately, GitHub is deprecating the macos-13 runner starting September 1, and the macos-13 runner is the last x86_64 runner available on GitHub Actions.

FWIW, macos-13 runner issue will also impact the workflows producing x86_64 macOS wheels. I don't know what (if any) decisions have been made about NumPy's support for macOS on x86_64, but adding new iOS workflows using macOS-13 a month or two before the runner is deprecated seemed ill-advised.

@rgommers
Copy link
Member

Thanks @freakboy3742. This looks pretty clean. The vendored-meson changes are integrated in the main branch of this repo now that gh-28860 is merged. I'd be fine with merging the npy_cblas.h and numpy/meson.build changes in this PR separate if that helps you, those changes look good to go.

@freakboy3742
Copy link
Contributor Author

And update; after discussions on the mesonbuild/meson-python#731, some additional changes to meson (mesonbuild/meson#14541) and CPython (python/cpython#133184) were identified. I'm working on getting those changes upstreamed.

@henryiii
Copy link
Contributor

cibuildwheel 3.0 out. :)

@freakboy3742
Copy link
Contributor Author

cibuildwheel 3.0 out. :)

Awesome! A new meson-python release is only remaining blocker.

@freakboy3742
Copy link
Contributor Author

freakboy3742 commented Jul 29, 2025

Status update: With the current main branch of meson-python, numpy/meson#22 applied to the meson-python branch, and the current main branch of cibuildwheel, this passes the full test suite on iOS under both Python 3.13 and 3.14.

The changes to the test suite changes involve:

  1. making test skips that were WASM-specific into a more generic test skip when subprocess isn't available, or
  2. making known macOS-specific test skips generic to all Apple platforms.

On top of those changes, there's one specific change to ctypes handling to account for the odd way that iOS handles dynamic loading, and one workaround for a pytest issue (related to getuser() and the creation of temporary files).

# getuser() tries to use `pwd`, which doesn't exist on iOS. Fake a
# username that will take priority.
if IS_IOS:
os.environ["USER"] = "iOSUser"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This workaround isn't required if you use pytest 8.1.0 or higher, as the underlying problem was fixed by pytest-dev/pytest#11875

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've removed this workaround by bumping pytest to 8.4.1.

@rgommers
Copy link
Member

The test changes seem fine to me.

@freakboy3742
Copy link
Contributor Author

I've added CI workflows, and updated cibuildwheel and vendored-meson versions; the meson-python release is the only outstanding TODO.

I've updated the description of the PR to reflect current status, and a couple of notable design decisions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
36 - Build Build related PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants