I am the maintainer of crossenv, a tool that creates a special virtual environment such that once set up,
pip wheel numpy will cross-compile a wheel for a different architecture. While this is definitely a niche tool, it works well enough that it has started to see some interest in various other projects. (The one in particular that made me write this is Cross compiling aarch64 wheel · Issue #598 · pypa/cibuildwheel · GitHub)
I would like a way to maintain crossenv in a less hacky way, especially as other people start to rely on it. Currently to make it work, I patch a handful of standard library modules and a few third party modules. It’s the third party modules that give me more trouble; they move much faster. It’s also the third party modules that require the most workarounds, and the most likely to just not work. For example, manylinux support is disabled by default because the detection algorithms break when
crossenv is active.
I don’t know that a cross-compiling environment, as I have done it, is the only or best way of cross-compiling Python extension modules, but I’ve found it very helpful dealing with the wealth of
setup.py's already out there. It would be very useful to have an accepted way of communicating to other tools that they are cross-compiling. It would make it easier to submit patches to other projects to improve cross-compiling support. It would make it easier to for other projects to mock cross compiling for testing. It would make it easier for new language support (think
setuptools-rust) to have cross-compiling support from the start. It might play nicely with PEP 517, too.
I would like to hear what the community at large thinks of this. If there is interest in this, I would be happy to try and put together a PEP. I am not proposing that cross-compiling become officially supported.
Some initial thoughts: Right now, you can detect cross-compiling on *nix by checking if
sysconfig.get_config_var('HOST_GNU_TYPE') != sysconfig.get_config_var('BUILD_GNU_TYPE'). I also set an environment variable
PYTHON_CROSSENV=1 and add
sys.cross_compiling. Maybe adding a module, like the
_manylinux module technique in PEP 600 would be better?