Skip to content
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

bpo-14527: fix (some) _ctypes liffi build problems #20451

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

@rupertnash
Copy link

@rupertnash rupertnash commented May 27, 2020

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

@the-knights-who-say-ni
Copy link

@the-knights-who-say-ni the-knights-who-say-ni commented May 27, 2020

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 Missing

Our records indicate the following people have not signed the CLA:

@rupertnash

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
before our records are updated.

You can check yourself to see if the CLA has been received.

Thanks again for the contribution, we look forward to reviewing it!

Copy link

@lapsintra lapsintra left a comment

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.

@FFY00
FFY00 approved these changes Nov 6, 2020
Copy link
Member

@FFY00 FFY00 left a comment

This patch seems correct to me.

setup.py Outdated
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)

This comment has been minimized.

@pmp-p

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 ?

This comment has been minimized.

@rupertnash

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

This comment has been minimized.

@pmp-p

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

ref: https://bugs.python.org/issue31710

@pmp-p
pmp-p approved these changes Dec 9, 2020
Copy link
Contributor

@pmp-p pmp-p left a comment

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

Shillaker added a commit to faasm/cpython that referenced this pull request Dec 16, 2020
@rupertnash rupertnash force-pushed the rupertnash:fix-ffi-build branch from 76c8001 to 8fe5428 Mar 23, 2021
@rupertnash
Copy link
Author

@rupertnash rupertnash commented Mar 23, 2021

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
6 participants