bpo-14527: fix (some) _ctypes liffi build problems #20451
Conversation
Hello, and thanks for your contribution! I'm a bot set up to make sure that the project can legally accept this contribution by verifying everyone involved has signed the PSF contributor agreement (CLA). CLA MissingOur records indicate the following people have not signed the CLA: For legal reasons we need all the people listed to sign the CLA before we can look at your contribution. Please follow the steps outlined in the CPython devguide to rectify this issue. If you have recently signed the CLA, please wait at least one business day You can check yourself to see if the CLA has been received. Thanks again for the contribution, we look forward to reviewing it! |
Worked for my setup. Before following this commit, I had set PKG_CONFIG_PATH, LD_LIBRARY_PATH, LD_RUN_PATH and LIBRARY_PATH point towards the appropriate locations. ./configure did set correctly LIBFFI_INCLUDEDIR using pkgconfig Still couldn't build module _ctypes This commit solved my issue. |
This patch seems correct to me. |
if ffi_inc is not None: | ||
for lib_name in ('ffi', 'ffi_pic'): | ||
if (self.compiler.find_library_file(self.lib_dirs, lib_name)): | ||
fullpath = self.compiler.find_library_file(self.lib_dirs + ffi_libdir, lib_name) |
pmp-p
Nov 22, 2020
Contributor
Why use setup.py heuristics to find libname when you could just let pkgconfig gives the right hint for compilation host/target with pkg-config libffi --libs-only-l
like you did with LIBFFI_LIBDIR and LIBFFI_INCLUDEDIR ?
rupertnash
Dec 2, 2020
Author
That is a reasonable question.
The true answer is that while making my changes I tried to keep them as small as practical.
However when I came here to respond, I notice that this library search checks for libffi and libffi_pic, whether or not pkg-config is available on the compilation host.
If we simply create a new configure variable with say:
LIBFFI_LIBNAME="`"$PKG_CONFIG" libffi --libs-only-l 2> /dev/null | sed -e 's/^-l//;s/ *$//'`"
then we will lose the ability to find libffi_pic.{so,a}
if there's no pkg-config.
We could set a default like LIBFFI_LIBNAME="ffi ffi_pic"
and then have setup.py split it's value on space before looping much as now...
My feeling is to stick as we are, but happy to defer to core team
pmp-p
Dec 5, 2020
•
Contributor
whether or not pkg-config is available on the compilation host.
maybe if pkg-config is here then use it fully else use old way ( and good luck for cross compilation setup.py will pick anything in /usr instead of sysroot in most cases ).
my 3.9.1 android/wasm (with HAVE_FFI_PREP_CLOSURE_LOC and ffi git on wasm ) CI is quite happy with that patch, it looks like a good step forward into cross-compilation to me |
Dear devs - I had forgotten about this PR until I had to rebuild python yesterday on a machine with libffi in a non-standard location. Due to some major changes in setup.py around libffi, I've basically had to re-implement my patch. I've done this and force-pushed this branch. (Old commits https://github.com/rupertnash/cpython/tree/fix-ffi-build-old) I would appreciate your comments again and I will have a bit of time in the next week or two to actually get this merged |
Fundamentally, the problem appears to be that configure uses pkgconfig to find the libffi include directory, while setup.py's detect_ctypes only uses the global list of library directories.
I have made an attempt at fixing this by having configure produce the directory containing libffi (
LIBFFI_LIBDIR
) and setup.py use this. However I've hardly any experience with autotools, so I would be very happy to be corrected if this is no use at all.https://bugs.python.org/issue14527