Add support for iOS cross-platform virtual environments#2828
Add support for iOS cross-platform virtual environments#2828
Conversation
|
Thanks for the PR, having to use cibuildwheel or xbuild to compile iOS wheel is probably fine, but I just want to ask if it's possible to do it without them by only using |
Yes, a build is possible without using cibuildwheel or xbuild; however, you also need to:
The benefit of the cross environment approach is that both these details are managed for you. (FYI - I've made one additional change from the original PR, so the the cross-platform target discovery is also performed when an interpreter is explicitly provided; |
I don't see this as an issue, we always pass it in github actions (maturin-action) when cross-compiling
|
That's the problem though - it's not something Xcode knows about. You need to know the location where the iOS version of Python is installed, which is specific to a given user's install, and the version that they have installed. |
At present, when targeting an `abi3` build, Maturin will use a dummy interpreter to provide build configuration details, unless the user specifies an interpreter with `--interpreter`, or the target is cross-compiling, or Windows is being targeted. The use of a dummy interpreter when a real interpreter is available can lead to the interpreter details that are available and defined in `sysconfigdata` not being used as part of the build process. This was discovered in the process of working on iOS support (see #2827 and #2828); although the iOS build environment *does* provide build configuration details, those details were not being passed down to the PyO3 build configuration. With those two patches (and some patches to PyO3 - see PyO3/pyo3#5605 and PyO3/pyo3#5606), it was possible to build a non-abi3 wheel; but this patch was needed to build an abi3 wheel.
Tools such as
cibuildwheelandxbuildmanage building wheels for iOS by using a cross-platform virtual environment - a valid virtual environment for the build platform that can "pretend" to be the target/host platform when asked for sysconfigdata. This is done by monkeypatching key values in the sys, sysconfig, platform and os module when the interpreter starts. Many of these environments also setsys.cross_compiling = Trueas an indicator that they aren't "real" environments.Maturin's concept of "cross-compiling", however, has more to do with whether the interpreter that is running the Maturin build can be used to interrogate details about the Python install for the purpose of configuring a build. To that end, somewhat counterintuitively, a cross-platform venv isn't "cross platform" from the perspective of Maturin.
This PR makes 3 changes:
--target, or--interpreter, the build interpreter will be interrogated to see if it is a cross-compilation environment - and if it is, the target implied by the platform is used for the build.--interpreterhas been provided, the target will be modified if the environment is a cross-platform environment.When combined with #2827, this means it is possible to create an iOS wheel with no more than
maturin build, provided you're in an iOS cross-platform venv (such as those created bycibuildwheelandxbuild).