Fix cross-compiling by searching the right lib and include directories - #9977
Closed
radarhere wants to merge 1 commit into
Closed
Fix cross-compiling by searching the right lib and include directories#9977radarhere wants to merge 1 commit into
radarhere wants to merge 1 commit into
Conversation
We were previously searching the `{sys.prefix}/lib` and
`{sys.prefix}/include` directories unconditionally. This is problematic
when cross-compiling, as it does not take account of any sysroot where
alternative libraries and headers are located. Adding `-I/usr/include`
causes the build to explode, at least when cross-compiling from 64-bit
to 32-bit.
Python does not officially support cross-compiling, but Gentoo achieves
this by modifying the sysconfig variables like `LIBDIR` and `INCLUDEDIR`
with great results.
Assuming "lib" is bad. 64-bit Linux systems often use lib64, putting
32-bit libraries under lib. You cannot assume that either though, as
pure 64-bit Linux systems may just use lib instead. Things get even
stranger on RISC-V.
The value of `sys.prefix` changes when using a virtualenv. Dependencies
may be installed here, so it does make sense to continue supporting this
case, even if it is incompatible with cross-compiling. Unlike regular
environments, "lib" is generally used for libraries, although a lib64
symlink may also be present.
akx
reviewed
Sep 9, 2026
Comment on lines
+577
to
+578
| (sys.prefix == sys.base_prefix and sysconfig.get_config_var("LIBDIR")) | ||
| or os.path.join(sys.prefix, "lib"), |
Contributor
There was a problem hiding this comment.
At first read, this reads like the pre-Python-2.5 pattern of COND and T or F for T if COND else F, but not quite:
There's a subtle difference here since sysconfig.get_config_var() can return None, so then we fall back to the default. 👍
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Rebase of #7634
It looks like we don't have permissions to update that PR, and it is failing to build the docs because it is out of date.