From ef2c6368876722cfcd5f090e57fbf5f5fa104a78 Mon Sep 17 00:00:00 2001 From: Rupert Nash Date: Mon, 22 Mar 2021 16:18:59 +0000 Subject: [PATCH 1/2] fix for _ctypes liffi build problems bpo-14527 --- Makefile.pre.in | 1 + configure | 4 ++++ configure.ac | 3 +++ setup.py | 25 ++++++++++++++++++++----- 4 files changed, 28 insertions(+), 5 deletions(-) diff --git a/Makefile.pre.in b/Makefile.pre.in index 6655edafeb1ecf..8c044e031c0d7c 100644 --- a/Makefile.pre.in +++ b/Makefile.pre.in @@ -305,6 +305,7 @@ IO_OBJS= \ ########################################################################## LIBFFI_INCLUDEDIR= @LIBFFI_INCLUDEDIR@ +LIBFFI_LIBDIR= @LIBFFI_LIBDIR@ ########################################################################## # Parser diff --git a/configure b/configure index 2ddca079860625..8f0dd3688e1dcd 100755 --- a/configure +++ b/configure @@ -660,6 +660,7 @@ DFLAGS DTRACE TCLTK_LIBS TCLTK_INCLUDES +LIBFFI_LIBDIR LIBFFI_INCLUDEDIR PKG_CONFIG_LIBDIR PKG_CONFIG_PATH @@ -10632,11 +10633,14 @@ fi if test "$with_system_ffi" = "yes" && test -n "$PKG_CONFIG"; then LIBFFI_INCLUDEDIR="`"$PKG_CONFIG" libffi --cflags-only-I 2>/dev/null | sed -e 's/^-I//;s/ *$//'`" + LIBFFI_LIBDIR="`"$PKG_CONFIG" libffi --libs-only-L 2>/dev/null | sed -e 's/^-L//;s/ *$//'`" else LIBFFI_INCLUDEDIR="" + LIBFFI_LIBDIR="" fi + # Check for use of the system libmpdec library { $as_echo "$as_me:${as_lineno-$LINENO}: checking for --with-system-libmpdec" >&5 $as_echo_n "checking for --with-system-libmpdec... " >&6; } diff --git a/configure.ac b/configure.ac index 4c3c80f74d215b..f7adeb016ee098 100644 --- a/configure.ac +++ b/configure.ac @@ -3097,10 +3097,13 @@ fi if test "$with_system_ffi" = "yes" && test -n "$PKG_CONFIG"; then LIBFFI_INCLUDEDIR="`"$PKG_CONFIG" libffi --cflags-only-I 2>/dev/null | sed -e 's/^-I//;s/ *$//'`" + LIBFFI_LIBDIR="`"$PKG_CONFIG" libffi --libs-only-L 2>/dev/null | sed -e 's/^-L//;s/ *$//'`" else LIBFFI_INCLUDEDIR="" + LIBFFI_LIBDIR="" fi AC_SUBST(LIBFFI_INCLUDEDIR) +AC_SUBST(LIBFFI_LIBDIR) # Check for use of the system libmpdec library AC_MSG_CHECKING(for --with-system-libmpdec) diff --git a/setup.py b/setup.py index 80deacce8de48c..a05e3d8f10a83e 100644 --- a/setup.py +++ b/setup.py @@ -2236,7 +2236,9 @@ def detect_ctypes(self): libraries=['m'])) ffi_inc = sysconfig.get_config_var("LIBFFI_INCLUDEDIR") - ffi_lib = None + + # Potential names of the library (e.g. libNAME.{so,dylib}) + ffi_libname_candidates = ('ffi', 'ffi_pic') ffi_inc_dirs = self.inc_dirs.copy() if MACOS: @@ -2246,7 +2248,7 @@ def detect_ctypes(self): if os.path.exists(ffi_in_sdk): ext.extra_compile_args.append("-DUSING_APPLE_OS_LIBFFI=1") ffi_inc = ffi_in_sdk - ffi_lib = 'ffi' + ffi_libname_candidates = ('ffi',) else: # OS X 10.5 comes with libffi.dylib; the include files are # in /usr/include/ffi @@ -2261,10 +2263,21 @@ def detect_ctypes(self): if not os.path.exists(ffi_h): ffi_inc = None print('Header file {} does not exist'.format(ffi_h)) - if ffi_lib is None and ffi_inc: - for lib_name in ('ffi', 'ffi_pic'): - if (self.compiler.find_library_file(self.lib_dirs, lib_name)): + + ffi_lib = None + # Then we probably also need to figure out the path to the + # library too. + if ffi_inc: + # A list containing nothing or the directory from the + # configure script. + maybe_ffi_libdir = [d for d in [sysconfig.get_config_var("LIBFFI_LIBDIR")] + if os.path.isdir(d)] + + for lib_name in ffi_libname_candidates: + fullpath = self.compiler.find_library_file(self.lib_dirs + maybe_ffi_libdir, lib_name) + if fullpath: ffi_lib = lib_name + ffi_libdir = os.path.normpath(os.path.dirname(fullpath)) break if ffi_inc and ffi_lib: @@ -2278,6 +2291,8 @@ def detect_ctypes(self): ext.include_dirs.append(ffi_inc) ext.libraries.append(ffi_lib) + if ffi_libdir not in self.lib_dirs: + ext.library_dirs.append(ffi_libdir) self.use_system_libffi = True if sysconfig.get_config_var('HAVE_LIBDL'): From 8fe5428e48519d5fc5daac0dc197786b366a34e3 Mon Sep 17 00:00:00 2001 From: Rupert Nash Date: Tue, 23 Mar 2021 15:02:07 +0000 Subject: [PATCH 2/2] add NEWS entry --- Misc/NEWS.d/next/Build/2020-05-28-10-39-11.bpo-14527.OavBJT.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 Misc/NEWS.d/next/Build/2020-05-28-10-39-11.bpo-14527.OavBJT.rst diff --git a/Misc/NEWS.d/next/Build/2020-05-28-10-39-11.bpo-14527.OavBJT.rst b/Misc/NEWS.d/next/Build/2020-05-28-10-39-11.bpo-14527.OavBJT.rst new file mode 100644 index 00000000000000..8f04902c7cb270 --- /dev/null +++ b/Misc/NEWS.d/next/Build/2020-05-28-10-39-11.bpo-14527.OavBJT.rst @@ -0,0 +1 @@ +Fix issues with building python with a non-system version of libffi.