-
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 #35
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 incorrect paths when cross-compiling (paths pointing to build 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.
Thanks for the contrib. I don't have a lot of experience with the sysconfig module. Right now, there's a lot of work going on right now to refactor sysconfig to enable better configurability by different platforms, so it's possible this change will conflict with some of those efforts. Is there a test that could be added to this PR that would help capture the missed expectation (and thus fail before and pass after the patch)? |
Would you be willing to take another look at this patch? I have rebased it and reworked it a bit (not visible unless the PR is reopened). I will also explain more thoroughly how we (nixpkgs) use this patch to enable cross-compilation of Python packages with extension modules, as well as the challenges involved in developing an automated test. We use the following techniques to make cross-compilation work:
If the package contains extension modules, eventually
This patch avoids this problem by relying on sysconfig to provide the include paths. With 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 |
I opened #145 |
Singular `license_file` is deprecated since wheel v0.32.0. Refs: * https://wheel.readthedocs.io/en/stable/news.html * https://wheel.readthedocs.io/en/stable/user_guide.html#including-license-files-in-the-generated-wheel-file
* Use `extend-ignore` in flake8 config This option allows to add extra ignored rules to the default list instead of replacing it. The default exclusions are: E121, E123, E126, E226, E24, E704, W503 and W504. Fixes #28. Refs: * https://github.com/pypa/setuptools/pull/2486/files#r541943356 * https://flake8.pycqa.org/en/latest/user/options.html#cmdoption-flake8-extend-ignore * https://flake8.pycqa.org/en/latest/user/options.html#cmdoption-flake8-ignore * Enable complexity limit. Fixes jaraco/skeleton#34. * Replace pep517.build with build (#37) * Replace pep517.build with build Resolves #30 * Prefer simple usage Co-authored-by: Jason R. Coombs <[email protected]> * Use license_files instead of license_file in meta (#35) Singular `license_file` is deprecated since wheel v0.32.0. Refs: * https://wheel.readthedocs.io/en/stable/news.html * https://wheel.readthedocs.io/en/stable/user_guide.html#including-license-files-in-the-generated-wheel-file Co-authored-by: Jason R. Coombs <[email protected]>
When cross-compiling extension modules using
build_ext
,get_python_inc()
may be called to return the path to Python's headers. However, it uses thesys.prefix
orsys.exec_prefix
of the build Python, which returns incorrect paths when cross-compiling (paths pointing to build system headers).To fix this, we use the
INCLUDEPY
andCONFINCLUDEPY
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.This was originally submitted to stdlib distutils as python/cpython#22440, but unfortunately they are no longer accepting patches to it even though setuptools still uses stdlib distutils by default.
I tested this with the netifaces package, which compiles an extension module and fails with the following error if it is cross-compiled from x86_64 to armv7l without this patch, due to the word size difference:
After applying this patch and setting
_PYTHON_SYSCONFIGDATA_NAME
andSETUPTOOLS_USE_DISTUTILS
appropriately, the build succeeds.The stdlib distutils version of this patch is currently applied in nixpkgs (NixOS/nixpkgs#98915) and we have not observed any breakage.