-
Notifications
You must be signed in to change notification settings - Fork 73
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
Fix finding headers when cross compiling #145
Conversation
When cross-compiling third-party extensions, get_python_inc() may be called to return the path to Python's headers. However, it uses the sys.prefix or sys.exec_prefix of the build Python, which returns paths pointing to build system headers when instead we really want the host system headers. To fix this, we use the INCLUDEPY and CONFINCLUDEPY conf variables, which can be configured to point at host Python by setting _PYTHON_SYSCONFIGDATA_NAME. The existing behavior is maintained on non-POSIX platforms or if a prefix is manually specified.
I note that |
… treatment diverges even more.
…Use value algebra to simplify the logic.
Thanks! |
I can't believe this is broken again: the fix didn't even live up to the next release. 😞 |
I can fix it with this change
Cross and non-cross compilation work, but I don't know if this has unintended consequences. |
This is a resubmission of #35, rebased and reworked a bit. I've included the same notes I posted in #35 describing the use case this patch enables:
We use the following techniques to make cross-compilation work:
_sysconfigdata
module for the host platform Python installation toPYTHONPATH
, so that it can be imported from build platform Python._PYTHON_HOST_PLATFORM
to the correct value for the host platform (e.g.linux-armv7l
)_PYTHON_SYSCONFIGDATA_NAME
to the appropriate value for the host platform (e.g._sysconfigdata__linux_arm-linux-gnueabihf
).setup.py
is executed using build platform Python (by necessity, since the build machine can't normally run host platform binaries), but thesysconfig
module returns data from the host platform Python installation, due to_PYTHON_SYSCONFIGDATA_NAME
.If the package contains extension modules, eventually
distutils.sysconfig.get_python_inc()
will be called to get the location of the Python headers. Without this patch, the build platform headers will be returned, sinceget_python_inc()
returns paths relative tosys.base_prefix
orsys.base_exec_prefix
. This causes problems when the build platform word length doesn't match the host platform, resulting in errors like the following:This patch avoids this problem by relying on sysconfig to provide the include paths. With
_PYTHON_SYSCONFIGDATA_NAME
set appropriately, the include directories will be returned from host platform Python.The latest version of the patch will always use sysconfig on posix if the relevant config variables are defined, otherwise it will fall back to the current behavior.
I have been having trouble coming up with an effective and simple automated test due to the amount of infrastructure required. I think you would need multiple Python installations in order to demonstrate how
_PYTHON_SYSCONFIGDATA_NAME
can affect the return value ofget_python_inc()
. IMO, the most important thing is ensuring that existing (non-cross) use cases are not affected by this change.