From e33181bc6273abdcc4ec67cb6161401823f49b57 Mon Sep 17 00:00:00 2001 From: Max Wipfli Date: Thu, 7 Aug 2025 10:11:58 +0200 Subject: [PATCH] pypy{27,310,311}: make CFFI builds find libsqlite3 --- .../interpreters/python/pypy/default.nix | 16 ++++++++- .../python/pypy/sqlite_paths.patch | 36 ++++++++++++++++--- .../python/pypy/sqlite_paths_2_7.patch | 22 ++++++++++++ 3 files changed, 69 insertions(+), 5 deletions(-) create mode 100644 pkgs/development/interpreters/python/pypy/sqlite_paths_2_7.patch diff --git a/pkgs/development/interpreters/python/pypy/default.nix b/pkgs/development/interpreters/python/pypy/default.nix index 93dadcfce437..7779b3fbba8f 100644 --- a/pkgs/development/interpreters/python/pypy/default.nix +++ b/pkgs/development/interpreters/python/pypy/default.nix @@ -140,8 +140,22 @@ stdenv.mkDerivation rec { tcl_libprefix = tcl.libPrefix; }) - (replaceVars ./sqlite_paths.patch { + # Python ctypes.util uses three different strategies to find a library (on Linux): + # 1. /sbin/ldconfig + # 2. cc -Wl,-t -l"$libname"; objdump -p + # 3. ld -t (where it attaches the values in $LD_LIBRARY_PATH as -L arguments) + # The first is disabled in Nix (and wouldn't work in the build sandbox or on NixOS anyway), and + # the third was only introduced in Python 3.6 (see bugs.python.org/issue9998), so is not + # available when buliding PyPy (which is built using Python/PyPy 2.7). + # The second requires SONAME to be set for the dynamic library for the second part not to fail. + # As libsqlite3 stopped shipping with SONAME after the switch to autosetup (>= 3.50 in Nixpkgs; + # see https://www.sqlite.org/src/forumpost/5a3b44f510df8ded). This makes the Python CFFI module + # unable to find the SQLite library. + # To circumvent these issues, we hardcode the path during build. + # For more information, see https://github.com/NixOS/nixpkgs/issues/419942. + (replaceVars (if isPy3k then ./sqlite_paths.patch else ./sqlite_paths_2_7.patch) { inherit (sqlite) out dev; + libsqlite = "${sqlite.out}/lib/libsqlite3${stdenv.hostPlatform.extensions.sharedLibrary}"; }) ]; diff --git a/pkgs/development/interpreters/python/pypy/sqlite_paths.patch b/pkgs/development/interpreters/python/pypy/sqlite_paths.patch index 42de7efb3ea3..73af8942acf2 100644 --- a/pkgs/development/interpreters/python/pypy/sqlite_paths.patch +++ b/pkgs/development/interpreters/python/pypy/sqlite_paths.patch @@ -1,7 +1,35 @@ -diff -ur a/lib_pypy/_sqlite3_build.py b/lib_pypy/_sqlite3_build.py ---- a/lib_pypy/_sqlite3_build.py 2021-04-12 01:11:48.000000000 -0400 -+++ b/lib_pypy/_sqlite3_build.py 2021-07-14 18:08:33.000000000 -0400 -@@ -301,6 +301,8 @@ +diff --git a/lib_pypy/_sqlite3_build.py b/lib_pypy/_sqlite3_build.py +index 2a4e573..92ab786 100644 +--- a/lib_pypy/_sqlite3_build.py ++++ b/lib_pypy/_sqlite3_build.py +@@ -352,7 +352,7 @@ def _has_load_extension(): + typedef ... sqlite3; + int sqlite3_enable_load_extension(sqlite3 *db, int onoff); + """) +- libname = 'sqlite3' ++ libname = '@libsqlite@' + if sys.platform == 'win32': + import os + _libname = os.path.join(os.path.dirname(sys.executable), libname) +@@ -369,7 +369,7 @@ def _has_backup(): + typedef ... sqlite3_backup; + sqlite3_backup* sqlite3_backup_init(sqlite3 *, const char* , sqlite3 *, const char*); + """) +- libname = 'sqlite3' ++ libname = '@libsqlite@' + if sys.platform == 'win32': + import os + _libname = os.path.join(os.path.dirname(sys.executable), libname) +@@ -383,7 +383,7 @@ def _get_version(): + unverified_ffi.cdef(""" + int sqlite3_libversion_number(void); + """) +- libname = 'sqlite3' ++ libname = '@libsqlite@' + if sys.platform == 'win32': + import os + _libname = os.path.join(os.path.dirname(sys.executable), libname) +@@ -554,6 +554,8 @@ if sys.platform.startswith('freebsd'): else: extra_args = dict( libraries=libraries, diff --git a/pkgs/development/interpreters/python/pypy/sqlite_paths_2_7.patch b/pkgs/development/interpreters/python/pypy/sqlite_paths_2_7.patch new file mode 100644 index 000000000000..2226bac5e3d8 --- /dev/null +++ b/pkgs/development/interpreters/python/pypy/sqlite_paths_2_7.patch @@ -0,0 +1,22 @@ +diff --git a/lib_pypy/_sqlite3_build.py b/lib_pypy/_sqlite3_build.py +index fb03aee..b3b5f39 100644 +--- a/lib_pypy/_sqlite3_build.py ++++ b/lib_pypy/_sqlite3_build.py +@@ -234,7 +234,7 @@ def _has_load_extension(): + typedef ... sqlite3; + int sqlite3_enable_load_extension(sqlite3 *db, int onoff); + """) +- libname = 'sqlite3' ++ libname = '@libsqlite@' + if sys.platform == 'win32': + import os + _libname = os.path.join(os.path.dirname(sys.executable), libname) +@@ -257,6 +257,8 @@ if sys.platform.startswith('freebsd'): + else: + extra_args = dict( + libraries=libraries, ++ include_dirs=['@dev@/include'], ++ library_dirs=['@out@/lib'] + ) + + _ffi.set_source("_sqlite3_cffi", "#include ", **extra_args)