Skip to content

Add iOS builds #281

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Add iOS builds #281

wants to merge 2 commits into from

Conversation

marcpabst
Copy link

Experimental builds for iOS using main branch of cibuildwheel. Tested using Beeware Python 3.13 on a real iOS device. Addresses #276.

@viblo
Copy link
Owner

viblo commented Apr 20, 2025

Looks like its build fine here on GH 👍
Is it possible to run the tests in the pipeline?

@marcpabst
Copy link
Author

marcpabst commented Apr 20, 2025

The problem with iOS is that you can't just run a Python interpreter, so you always need to create an app that bundles the Python interpreter with your Python library.

It should be possible through either BeeWare (the maintainer is awesome and has done a lot of the work making iOS builds possible at all) or Kivy (no idea about them, never used it) to automatically create an app, launch Xcode, and run tests on the iOS simulator. I thought it might be complicated, but the BeeWare docs say:

The run command can also be used to execute your app’s test suite, in the packaged environment (e.g., on the iOS simulator, or from within a Linux Flatpak). When running in test mode (using the --test option), a different entry point will be used for the app: if your app is contained in a Python module named myapp, test mode will attempt to launch tests.myapp. Your app is responsible for providing the logic to discover and start the test suite.

So that might be worth exploring!

@viblo
Copy link
Owner

viblo commented Apr 20, 2025

Found this discussion on cibuildwheel pypa/cibuildwheel#2363 that make it sound like something is possible.

curl https://files.pythonhosted.org/packages/8b/f1/672d303ddf17c24fc83afd712316fda78dc6fce1cd53011b839483e1ecc8/cffi-1.17.1-cp313-cp313-macosx_11_0_arm64.whl -L -o cffi-1.17.1-py3-none-any.whl && \
pip install cffi-1.17.1-py3-none-any.whl && \
# install the rest of the dependencies
python -m pip install setuptools wheel
Copy link
Owner

Choose a reason for hiding this comment

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

Seems like these are also in CIBW_BEFORE_BUILD just below?

Copy link
Author

Choose a reason for hiding this comment

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

yes, true! It was part of a matrix before, but I've moved it to an iOS only job so we really need CIBW_BEFORE_BUILD or CIBW_BEFORE_BUILD_IOS.


- name: Build wheels
run: python -m cibuildwheel
env:
Copy link
Owner

Choose a reason for hiding this comment

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

I think you can set PYMUNK_BUILD_SLIM: 1 here, just like done on wasm/Pypodide. It will exclude the examples from the wheel which if I understand it correctly are not useful anyway, or are they?

Copy link
Author

Choose a reason for hiding this comment

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

no, you're right!

CIBW_BUILD_VERBOSITY: 1
CIBW_BEFORE_BUILD_IOS: |
# download wheel and pretend that it's compatible with the current platform settings
curl https://files.pythonhosted.org/packages/8b/f1/672d303ddf17c24fc83afd712316fda78dc6fce1cd53011b839483e1ecc8/cffi-1.17.1-cp313-cp313-macosx_11_0_arm64.whl -L -o cffi-1.17.1-py3-none-any.whl && \
Copy link
Owner

Choose a reason for hiding this comment

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

So if cffi also build a ios wheel, then this hack would not be needed, right?

Copy link
Author

@marcpabst marcpabst Apr 28, 2025

Choose a reason for hiding this comment

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

Not quite - BeeWare actually already provides iOS wheels (which are necessary to run Pymunk because there is also a runtime dependency), but this is just for building the wheel. Here, cibuildwheel actually tries to install the iOS wheel, but we want the macOS wheel. The proper solution is for cibuildwheel to install host platform wheels for the build step instead of target platform wheel.

- name: Build wheels
run: python -m cibuildwheel
env:
IPHONEOS_DEPLOYMENT_TARGET: "23.0"
Copy link
Owner

Choose a reason for hiding this comment

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

What is this one for, and why 23.0?

Copy link
Author

Choose a reason for hiding this comment

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

Good point. My other project depend on newer iOS SDK versions but I guess pymunk can down much lower than that. I think the minimum supported version in PEP730 is 12.0.

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.

2 participants