This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author stapelberg
Recipients stapelberg
Date 2018-09-27.16:58:23
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1538067503.8.0.545547206417.issue34823@psf.upfronthosting.co.za>
In-reply-to
Content
(Tested with Python 3.7, but AFAICT, the situation hasn’t changed in Python 3.8.)

Python’s configure tries to fill the LIBFFI_INCLUDEDIR system variable with the value of -I as returned by pkg-config libffi --cflags-only-I.

Python’s setup.py tries to determine whether libffi is present by searching a couple of well-known library directories.

Both of these checks fail in my environment (think Linux From Scratch). I’m setting the following environment variables:

CPATH=/home/michael/libffi-3.2.1/include
LIBRARY_PATH=/home/michael/libffi-3.2.1/lib64

gcc can build against libffi just fine:

% echo echo '#include <ffi.h>                  
> int main() {}' > foo.c
% gcc -o foo foo.c -lffi
% ldd foo
	linux-vdso.so.1 (0x00007ffe4450a000)
	libffi.so.6 => /home/michael/libffi-3.2.1/lib64/libffi.so.6 (0x00007f3935aba000)
	libc.so.6 => /home/michael/glibc-2.27/lib/libc.so.6 (0x00007f3935902000)
	/lib64/ld-linux-x86-64.so.2 => /home/michael/glibc-2.27/lib/ld-linux-x86-64.so.2 (0x00007f3935aca000)

However, when compiling Python, I’m getting the following error message, resulting in the _ctypes module not being built:

INFO: Could not locate ffi libs and/or headers

Now, one issue is that pkg-config understands CPATH, so calling pkg-config --cflags-only-I is not sufficient to obtain the include directory, one also needs to clear CPATH:

% pkg-config libffi --cflags-only-I      

% CPATH= pkg-config libffi --cflags-only-I
-I/home/michael/libffi-3.2.1/include

After patching this in configure, LIBFFI_INCLUDEDIR is set correctly, but the build still fails, as the libffi shared object is located in my non-standard path, which setup.py doesn’t check.

Without knowing much about the Python internals, it seems to me that both of these issues would be fixed if Python stopped trying to find the libffi include/lib locations and just used pkg-config to detect the required CFLAGS and LDFLAGS, just like Python currently does with openssl.

Is there any reason we can’t use pkg-config for libffi like that?

Thanks!
History
Date User Action Args
2018-09-27 16:58:23stapelbergsetrecipients: + stapelberg
2018-09-27 16:58:23stapelbergsetmessageid: <1538067503.8.0.545547206417.issue34823@psf.upfronthosting.co.za>
2018-09-27 16:58:23stapelberglinkissue34823 messages
2018-09-27 16:58:23stapelbergcreate