Skip to content

Fix cross-compiling by searching the right lib and include directories - #9977

Closed
radarhere wants to merge 1 commit into
python-pillow:mainfrom
radarhere:cross-prefix
Closed

Fix cross-compiling by searching the right lib and include directories#9977
radarhere wants to merge 1 commit into
python-pillow:mainfrom
radarhere:cross-prefix

Conversation

@radarhere

Copy link
Copy Markdown
Member

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.

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.
Comment thread setup.py
Comment on lines +577 to +578
(sys.prefix == sys.base_prefix and sysconfig.get_config_var("LIBDIR"))
or os.path.join(sys.prefix, "lib"),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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. 👍

@radarhere radarhere closed this Sep 9, 2026
@radarhere
radarhere deleted the cross-prefix branch September 9, 2026 23:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants