From f34b4820e1e2863194630c69f62110d8124c6141 Mon Sep 17 00:00:00 2001 From: "Erlend E. Aasland" Date: Tue, 9 Nov 2021 23:27:55 +0100 Subject: [PATCH 01/15] bpo-45774: Autoconfiscate SQLite detection --- configure | 127 +++++++++++++++++++++++++++++++++++++++++++++++++- configure.ac | 22 ++++++++- pyconfig.h.in | 6 +++ setup.py | 118 +++++++--------------------------------------- 4 files changed, 170 insertions(+), 103 deletions(-) diff --git a/configure b/configure index a1f5e53018b079..5fd596306e0489 100755 --- a/configure +++ b/configure @@ -10762,12 +10762,137 @@ fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $with_decimal_contextvar" >&5 $as_echo "$with_decimal_contextvar" >&6; } +for ac_header in sqlite3.h +do : + ac_fn_c_check_header_mongrel "$LINENO" "sqlite3.h" "ac_cv_header_sqlite3_h" "$ac_includes_default" +if test "x$ac_cv_header_sqlite3_h" = xyes; then : + cat >>confdefs.h <<_ACEOF +#define HAVE_SQLITE3_H 1 +_ACEOF + + save_LIBS=$LIBS + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for sqlite3_open_v2 in -lsqlite3" >&5 +$as_echo_n "checking for sqlite3_open_v2 in -lsqlite3... " >&6; } +if ${ac_cv_lib_sqlite3_sqlite3_open_v2+:} false; then : + $as_echo_n "(cached) " >&6 +else + ac_check_lib_save_LIBS=$LIBS +LIBS="-lsqlite3 $LIBS" +cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +/* Override any GCC internal prototype to avoid an error. + Use char because int might match the return type of a GCC + builtin and then its argument prototype would still apply. */ +#ifdef __cplusplus +extern "C" +#endif +char sqlite3_open_v2 (); +int +main () +{ +return sqlite3_open_v2 (); + ; + return 0; +} +_ACEOF +if ac_fn_c_try_link "$LINENO"; then : + ac_cv_lib_sqlite3_sqlite3_open_v2=yes +else + ac_cv_lib_sqlite3_sqlite3_open_v2=no +fi +rm -f core conftest.err conftest.$ac_objext \ + conftest$ac_exeext conftest.$ac_ext +LIBS=$ac_check_lib_save_LIBS +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_sqlite3_sqlite3_open_v2" >&5 +$as_echo "$ac_cv_lib_sqlite3_sqlite3_open_v2" >&6; } +if test "x$ac_cv_lib_sqlite3_sqlite3_open_v2" = xyes; then : + + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + + + #include + #if SQLITE_VERSION_NUMBER < 3007015 + # error "SQLite 3.7.15 or higher required" + #endif + +int +main () +{ + + ; + return 0; +} + +_ACEOF +if ac_fn_c_try_compile "$LINENO"; then : + +$as_echo "#define HAVE_LIBSQLITE3 1" >>confdefs.h + +fi +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext + +fi + + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for sqlite3_load_extension in -lsqlite3" >&5 +$as_echo_n "checking for sqlite3_load_extension in -lsqlite3... " >&6; } +if ${ac_cv_lib_sqlite3_sqlite3_load_extension+:} false; then : + $as_echo_n "(cached) " >&6 +else + ac_check_lib_save_LIBS=$LIBS +LIBS="-lsqlite3 $LIBS" +cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +/* Override any GCC internal prototype to avoid an error. + Use char because int might match the return type of a GCC + builtin and then its argument prototype would still apply. */ +#ifdef __cplusplus +extern "C" +#endif +char sqlite3_load_extension (); +int +main () +{ +return sqlite3_load_extension (); + ; + return 0; +} +_ACEOF +if ac_fn_c_try_link "$LINENO"; then : + ac_cv_lib_sqlite3_sqlite3_load_extension=yes +else + ac_cv_lib_sqlite3_sqlite3_load_extension=no +fi +rm -f core conftest.err conftest.$ac_objext \ + conftest$ac_exeext conftest.$ac_ext +LIBS=$ac_check_lib_save_LIBS +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_sqlite3_sqlite3_load_extension" >&5 +$as_echo "$ac_cv_lib_sqlite3_sqlite3_load_extension" >&6; } +if test "x$ac_cv_lib_sqlite3_sqlite3_load_extension" = xyes; then : + have_sqlite3_load_extension=yes +else + have_sqlite3_load_extension=no +fi + + LIBS=$save_LIBS + +fi + +done + + # Check for support for loadable sqlite extensions { $as_echo "$as_me:${as_lineno-$LINENO}: checking for --enable-loadable-sqlite-extensions" >&5 $as_echo_n "checking for --enable-loadable-sqlite-extensions... " >&6; } # Check whether --enable-loadable-sqlite-extensions was given. if test "${enable_loadable_sqlite_extensions+set}" = set; then : - enableval=$enable_loadable_sqlite_extensions; + enableval=$enable_loadable_sqlite_extensions; if test "x$have_sqlite3_load_extension" = xno; then : + as_fn_error $? "Your version of SQLite does not support loadable extensions" "$LINENO" 5 +fi else enable_loadable_sqlite_extensions=no fi diff --git a/configure.ac b/configure.ac index a7e5f2bd548b74..2496edff7456b9 100644 --- a/configure.ac +++ b/configure.ac @@ -3068,12 +3068,32 @@ fi AC_MSG_RESULT($with_decimal_contextvar) +dnl Check for SQLite library +AC_CHECK_HEADERS([sqlite3.h], [ + AS_VAR_COPY([save_LIBS], [LIBS]) + AC_CHECK_LIB([sqlite3], [sqlite3_open_v2], [ + AC_COMPILE_IFELSE([ + AC_LANG_PROGRAM([ + #include + #if SQLITE_VERSION_NUMBER < 3007015 + # error "SQLite 3.7.15 or higher required" + #endif + ], []) + ], [AC_DEFINE([HAVE_LIBSQLITE3], [1], [Define if SQLite > 3.7.15 is found])]) + ]) + AC_CHECK_LIB([sqlite3], [sqlite3_load_extension], + [have_sqlite3_load_extension=yes], + [have_sqlite3_load_extension=no]) + AS_VAR_COPY([LIBS], [save_LIBS]) +]) + # Check for support for loadable sqlite extensions AC_MSG_CHECKING(for --enable-loadable-sqlite-extensions) AC_ARG_ENABLE(loadable-sqlite-extensions, AS_HELP_STRING([--enable-loadable-sqlite-extensions], [support loadable extensions in _sqlite module, see Doc/library/sqlite3.rst (default is no)]), - [], + [AS_VAR_IF([have_sqlite3_load_extension], [no], + [AC_MSG_ERROR([Your version of SQLite does not support loadable extensions])])], [enable_loadable_sqlite_extensions=no]) AC_MSG_RESULT($enable_loadable_sqlite_extensions) diff --git a/pyconfig.h.in b/pyconfig.h.in index 2f71dd1758dcdc..cc3b91542bd834 100644 --- a/pyconfig.h.in +++ b/pyconfig.h.in @@ -610,6 +610,9 @@ /* Define to 1 if you have the `sendfile' library (-lsendfile). */ #undef HAVE_LIBSENDFILE +/* Define if SQLite > 3.7.15 is found */ +#undef HAVE_LIBSQLITE3 + /* Define to 1 if you have the header file. */ #undef HAVE_LIBUTIL_H @@ -1028,6 +1031,9 @@ /* Define to 1 if you have the `splice' function. */ #undef HAVE_SPLICE +/* Define to 1 if you have the header file. */ +#undef HAVE_SQLITE3_H + /* Define if your compiler provides ssize_t */ #undef HAVE_SSIZE_T diff --git a/setup.py b/setup.py index 7fe7d27b14ce08..7d3e2b054ff423 100644 --- a/setup.py +++ b/setup.py @@ -1506,108 +1506,24 @@ class db_found(Exception): pass self.missing.append('_gdbm') def detect_sqlite(self): - # The sqlite interface - sqlite_setup_debug = False # verbose debug prints from this script? - - # We hunt for #define SQLITE_VERSION "n.n.n" - sqlite_incdir = sqlite_libdir = None - sqlite_inc_paths = [ '/usr/include', - '/usr/include/sqlite', - '/usr/include/sqlite3', - '/usr/local/include', - '/usr/local/include/sqlite', - '/usr/local/include/sqlite3', - ] - if CROSS_COMPILING: - sqlite_inc_paths = [] - MIN_SQLITE_VERSION_NUMBER = (3, 7, 15) # Issue 40810 - MIN_SQLITE_VERSION = ".".join([str(x) - for x in MIN_SQLITE_VERSION_NUMBER]) - - # Scan the default include directories before the SQLite specific - # ones. This allows one to override the copy of sqlite on OSX, - # where /usr/include contains an old version of sqlite. - if MACOS: - sysroot = macosx_sdk_root() + have_sqlite3 = sysconfig.get_config_var("HAVE_LIBSQLITE3") + if not have_sqlite3: + self.missing.append("_sqlite3") + return - for d_ in self.inc_dirs + sqlite_inc_paths: - d = d_ - if MACOS and is_macosx_sdk_path(d): - d = os.path.join(sysroot, d[1:]) - - f = os.path.join(d, "sqlite3.h") - if os.path.exists(f): - if sqlite_setup_debug: print("sqlite: found %s"%f) - with open(f) as file: - incf = file.read() - m = re.search( - r'\s*.*#\s*.*define\s.*SQLITE_VERSION\W*"([\d\.]*)"', incf) - if m: - sqlite_version = m.group(1) - sqlite_version_tuple = tuple([int(x) - for x in sqlite_version.split(".")]) - if sqlite_version_tuple >= MIN_SQLITE_VERSION_NUMBER: - # we win! - if sqlite_setup_debug: - print("%s/sqlite3.h: version %s"%(d, sqlite_version)) - sqlite_incdir = d - break - else: - if sqlite_setup_debug: - print("%s: version %s is too old, need >= %s"%(d, - sqlite_version, MIN_SQLITE_VERSION)) - elif sqlite_setup_debug: - print("sqlite: %s had no SQLITE_VERSION"%(f,)) - - if sqlite_incdir: - sqlite_dirs_to_check = [ - os.path.join(sqlite_incdir, '..', 'lib64'), - os.path.join(sqlite_incdir, '..', 'lib'), - os.path.join(sqlite_incdir, '..', '..', 'lib64'), - os.path.join(sqlite_incdir, '..', '..', 'lib'), - ] - sqlite_libfile = self.compiler.find_library_file( - sqlite_dirs_to_check + self.lib_dirs, 'sqlite3') - if sqlite_libfile: - sqlite_libdir = [os.path.abspath(os.path.dirname(sqlite_libfile))] - - if sqlite_incdir and sqlite_libdir: - sqlite_srcs = [ - '_sqlite/connection.c', - '_sqlite/cursor.c', - '_sqlite/microprotocols.c', - '_sqlite/module.c', - '_sqlite/prepare_protocol.c', - '_sqlite/row.c', - '_sqlite/statement.c', - '_sqlite/util.c', ] - sqlite_defines = [] - - # Enable support for loadable extensions in the sqlite3 module - # if --enable-loadable-sqlite-extensions configure option is used. - if ( - MACOS and - sqlite_incdir == os.path.join(MACOS_SDK_ROOT, "usr/include") and - sysconfig.get_config_var("PY_SQLITE_ENABLE_LOAD_EXTENSION") - ): - raise DistutilsError("System version of SQLite does not support loadable extensions") - - include_dirs = ["Modules/_sqlite"] - # Only include the directory where sqlite was found if it does - # not already exist in set include directories, otherwise you - # can end up with a bad search path order. - if sqlite_incdir not in self.compiler.include_dirs: - include_dirs.append(sqlite_incdir) - # avoid a runtime library path for a system library dir - if sqlite_libdir and sqlite_libdir[0] in self.lib_dirs: - sqlite_libdir = None - self.add(Extension('_sqlite3', sqlite_srcs, - define_macros=sqlite_defines, - include_dirs=include_dirs, - library_dirs=sqlite_libdir, - libraries=["sqlite3",])) - else: - self.missing.append('_sqlite3') + sqlite_srcs = [ + "_sqlite/connection.c", + "_sqlite/cursor.c", + "_sqlite/microprotocols.c", + "_sqlite/module.c", + "_sqlite/prepare_protocol.c", + "_sqlite/row.c", + "_sqlite/statement.c", + "_sqlite/util.c", + ] + self.add(Extension("_sqlite3", sqlite_srcs, + include_dirs=["Modules/_sqlite"], + libraries=["sqlite3",])) def detect_platform_specific_exts(self): # Unix-only modules From 8d55894fd9dde75155558372f9c9a4e152222eb1 Mon Sep 17 00:00:00 2001 From: "Erlend E. Aasland" Date: Tue, 9 Nov 2021 23:30:17 +0100 Subject: [PATCH 02/15] Add NEWS --- Misc/NEWS.d/next/Build/2021-11-09-23-30-12.bpo-45774.Mwm3ZR.rst | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 Misc/NEWS.d/next/Build/2021-11-09-23-30-12.bpo-45774.Mwm3ZR.rst diff --git a/Misc/NEWS.d/next/Build/2021-11-09-23-30-12.bpo-45774.Mwm3ZR.rst b/Misc/NEWS.d/next/Build/2021-11-09-23-30-12.bpo-45774.Mwm3ZR.rst new file mode 100644 index 00000000000000..a2d943cd044e09 --- /dev/null +++ b/Misc/NEWS.d/next/Build/2021-11-09-23-30-12.bpo-45774.Mwm3ZR.rst @@ -0,0 +1,2 @@ +The build dependencies for :mod:`sqlite3` are now detected by ``configure``. +Patch by Erlend E. Aasland. From 9bc5d7b5353a753f5e6fd9fb125fb4b1b5b6cc6d Mon Sep 17 00:00:00 2001 From: "Erlend E. Aasland" Date: Tue, 9 Nov 2021 23:36:45 +0100 Subject: [PATCH 03/15] Don't pollute pyconfig.h with unneeded HAVE_SQLITE_H --- configure | 8 +------- configure.ac | 2 +- pyconfig.h.in | 3 --- 3 files changed, 2 insertions(+), 11 deletions(-) diff --git a/configure b/configure index 5fd596306e0489..3939c813d0e00f 100755 --- a/configure +++ b/configure @@ -10762,13 +10762,8 @@ fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $with_decimal_contextvar" >&5 $as_echo "$with_decimal_contextvar" >&6; } -for ac_header in sqlite3.h -do : - ac_fn_c_check_header_mongrel "$LINENO" "sqlite3.h" "ac_cv_header_sqlite3_h" "$ac_includes_default" +ac_fn_c_check_header_mongrel "$LINENO" "sqlite3.h" "ac_cv_header_sqlite3_h" "$ac_includes_default" if test "x$ac_cv_header_sqlite3_h" = xyes; then : - cat >>confdefs.h <<_ACEOF -#define HAVE_SQLITE3_H 1 -_ACEOF save_LIBS=$LIBS { $as_echo "$as_me:${as_lineno-$LINENO}: checking for sqlite3_open_v2 in -lsqlite3" >&5 @@ -10882,7 +10877,6 @@ fi fi -done # Check for support for loadable sqlite extensions diff --git a/configure.ac b/configure.ac index 2496edff7456b9..066aa51ac0a7c6 100644 --- a/configure.ac +++ b/configure.ac @@ -3069,7 +3069,7 @@ fi AC_MSG_RESULT($with_decimal_contextvar) dnl Check for SQLite library -AC_CHECK_HEADERS([sqlite3.h], [ +AC_CHECK_HEADER([sqlite3.h], [ AS_VAR_COPY([save_LIBS], [LIBS]) AC_CHECK_LIB([sqlite3], [sqlite3_open_v2], [ AC_COMPILE_IFELSE([ diff --git a/pyconfig.h.in b/pyconfig.h.in index cc3b91542bd834..50da29df8a23b9 100644 --- a/pyconfig.h.in +++ b/pyconfig.h.in @@ -1031,9 +1031,6 @@ /* Define to 1 if you have the `splice' function. */ #undef HAVE_SPLICE -/* Define to 1 if you have the header file. */ -#undef HAVE_SQLITE3_H - /* Define if your compiler provides ssize_t */ #undef HAVE_SSIZE_T From 1a33d5c192e71397883063ad02792fcac7718e11 Mon Sep 17 00:00:00 2001 From: "Erlend E. Aasland" Date: Wed, 10 Nov 2021 23:15:21 +0100 Subject: [PATCH 04/15] Prelim pkg-config support --- Makefile.pre.in | 9 +++++++++ Modules/Setup | 2 +- configure | 22 ++++++++++++++++++++-- configure.ac | 24 ++++++++++++++++++++---- setup.py | 21 +++++++++++++++++---- 5 files changed, 67 insertions(+), 11 deletions(-) diff --git a/Makefile.pre.in b/Makefile.pre.in index 1535cabdade9c2..c3f9db4fe7ebd8 100644 --- a/Makefile.pre.in +++ b/Makefile.pre.in @@ -564,6 +564,14 @@ LIBEXPAT_HEADERS= \ LIBEXPAT_A= Modules/expat/libexpat.a +# +# SQLite stuff +# + +# For setup.py +PY_SQLITE_CFLAGS=@PY_SQLITE_CFLAGS@ +PY_SQLITE_LDFLAGS=@PY_SQLITE_LDFLAGS@ + ######################################################################### # Rules @@ -2471,6 +2479,7 @@ MODULE__SHA512_DEPS=$(srcdir)/Modules/hashlib.h MODULE__SOCKET_DEPS=$(srcdir)/Modules/socketmodule.h MODULE__SSL_DEPS=$(srcdir)/Modules/_ssl.h $(srcdir)/Modules/_ssl/cert.c $(srcdir)/Modules/_ssl/debughelpers.c $(srcdir)/Modules/_ssl/misc.c $(srcdir)/Modules/_ssl_data.h $(srcdir)/Modules/_ssl_data_111.h $(srcdir)/Modules/_ssl_data_300.h $(srcdir)/Modules/socketmodule.h MODULE__TESTCAPI_DEPS=$(srcdir)/Modules/testcapi_long.h +MODULE__SQLITE3_DEPS=$(srcdir)/Modules/_sqlite/connection.h $(srcdir)/Modules/_sqlite/cursor.h $(srcdir)/Modules/_sqlite/microprotocols.h $(srcdir)/Modules/_sqlite/module.h $(srcdir)/Modules/_sqlite/prepare_protocol.h $(srcdir)/Modules/_sqlite/row.h $(srcdir)/Modules/_sqlite/util.h # IF YOU PUT ANYTHING HERE IT WILL GO AWAY # Local Variables: diff --git a/Modules/Setup b/Modules/Setup index 608866d9cedd53..0c036b43cd8fbc 100644 --- a/Modules/Setup +++ b/Modules/Setup @@ -218,7 +218,7 @@ time timemodule.c #_dbm _dbmmodule.c -lgdbm_compat -DUSE_GDBM_COMPAT #_gdbm _gdbmmodule.c -lgdbm #_lzma _lzmamodule.c -llzma -#_sqlite3 _sqlite/connection.c _sqlite/cursor.c _sqlite/microprotocols.c _sqlite/module.c _sqlite/prepare_protocol.c _sqlite/row.c _sqlite/statement.c _sqlite/util.c -lsqlite3 +#_sqlite3 _sqlite/connection.c _sqlite/cursor.c _sqlite/microprotocols.c _sqlite/module.c _sqlite/prepare_protocol.c _sqlite/row.c _sqlite/statement.c _sqlite/util.c $(PY_SQLITE_LDFLAGS) #_uuid _uuidmodule.c -luuid #zlib zlibmodule.c -lz diff --git a/configure b/configure index 48ec0140b2446d..ad715934093351 100755 --- a/configure +++ b/configure @@ -660,6 +660,8 @@ DFLAGS DTRACE TCLTK_LIBS TCLTK_INCLUDES +PY_SQLITE_LDFLAGS +PY_SQLITE_CFLAGS LIBMPDEC_INTERNAL LIBMPDEC_LDFLAGS LIBMPDEC_CFLAGS @@ -10921,10 +10923,21 @@ if test "$have_glibc_memmove_bug" = yes; then as_fn_append LIBMPDEC_CFLAGS " -U_FORTIFY_SOURCE" fi + + +if test ! -z "$PKG_CONFIG"; then + as_fn_append PY_SQLITE_CFLAGS "`"$PKG_CONFIG" sqlite3 --cflags-only-I 2>/dev/null`" + as_fn_append PY_SQLITE_LDFLAGS "`"$PKG_CONFIG" sqlite3 --libs-only-L 2>/dev/null`" +fi + +save_CFLAGS=$CFLAGS +save_LDFLAGS=$LDFLAGS +as_fn_append CFLAGS "$PY_SQLITE_CFLAGS" +as_fn_append LDFLAGS "$PY_SQLITE_LDFLAGS" + ac_fn_c_check_header_mongrel "$LINENO" "sqlite3.h" "ac_cv_header_sqlite3_h" "$ac_includes_default" if test "x$ac_cv_header_sqlite3_h" = xyes; then : - save_LIBS=$LIBS { $as_echo "$as_me:${as_lineno-$LINENO}: checking for sqlite3_open_v2 in -lsqlite3" >&5 $as_echo_n "checking for sqlite3_open_v2 in -lsqlite3... " >&6; } if ${ac_cv_lib_sqlite3_sqlite3_open_v2+:} false; then : @@ -10983,8 +10996,11 @@ main () _ACEOF if ac_fn_c_try_compile "$LINENO"; then : + $as_echo "#define HAVE_LIBSQLITE3 1" >>confdefs.h + as_fn_append PY_SQLITE_LDFLAGS " -lsqlite3" + fi rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext @@ -11032,12 +11048,14 @@ else have_sqlite3_load_extension=no fi - LIBS=$save_LIBS fi +CFLAGS=$save_CFLAGS +LDFLAGS=$save_LDFLAGS + # Check for support for loadable sqlite extensions { $as_echo "$as_me:${as_lineno-$LINENO}: checking for --enable-loadable-sqlite-extensions" >&5 $as_echo_n "checking for --enable-loadable-sqlite-extensions... " >&6; } diff --git a/configure.ac b/configure.ac index 80d093a768949a..84df5decfcbcef 100644 --- a/configure.ac +++ b/configure.ac @@ -3165,9 +3165,20 @@ if test "$have_glibc_memmove_bug" = yes; then AS_VAR_APPEND([LIBMPDEC_CFLAGS], [" -U_FORTIFY_SOURCE"]) fi -dnl Check for SQLite library +dnl Check for SQLite library. Use pkg-config if available. +AC_SUBST([PY_SQLITE_CFLAGS]) +AC_SUBST([PY_SQLITE_LDFLAGS]) +if test ! -z "$PKG_CONFIG"; then + AS_VAR_APPEND([PY_SQLITE_CFLAGS], ["`"$PKG_CONFIG" sqlite3 --cflags-only-I 2>/dev/null`"]) + AS_VAR_APPEND([PY_SQLITE_LDFLAGS], ["`"$PKG_CONFIG" sqlite3 --libs-only-L 2>/dev/null`"]) +fi + +AS_VAR_COPY([save_CFLAGS], [CFLAGS]) +AS_VAR_COPY([save_LDFLAGS], [LDFLAGS]) +AS_VAR_APPEND([CFLAGS], ["$PY_SQLITE_CFLAGS"]) +AS_VAR_APPEND([LDFLAGS], ["$PY_SQLITE_LDFLAGS"]) + AC_CHECK_HEADER([sqlite3.h], [ - AS_VAR_COPY([save_LIBS], [LIBS]) AC_CHECK_LIB([sqlite3], [sqlite3_open_v2], [ AC_COMPILE_IFELSE([ AC_LANG_PROGRAM([ @@ -3176,14 +3187,19 @@ AC_CHECK_HEADER([sqlite3.h], [ # error "SQLite 3.7.15 or higher required" #endif ], []) - ], [AC_DEFINE([HAVE_LIBSQLITE3], [1], [Define if SQLite > 3.7.15 is found])]) + ], [ + AC_DEFINE([HAVE_LIBSQLITE3], [1], [Define if SQLite > 3.7.15 is found]) + AS_VAR_APPEND([PY_SQLITE_LDFLAGS], [" -lsqlite3"]) + ]) ]) AC_CHECK_LIB([sqlite3], [sqlite3_load_extension], [have_sqlite3_load_extension=yes], [have_sqlite3_load_extension=no]) - AS_VAR_COPY([LIBS], [save_LIBS]) ]) +AS_VAR_COPY([CFLAGS], [save_CFLAGS]) +AS_VAR_COPY([LDFLAGS], [save_LDFLAGS]) + # Check for support for loadable sqlite extensions AC_MSG_CHECKING(for --enable-loadable-sqlite-extensions) AC_ARG_ENABLE(loadable-sqlite-extensions, diff --git a/setup.py b/setup.py index 3332ecb79ebd9d..2503423a51c1a2 100644 --- a/setup.py +++ b/setup.py @@ -1359,7 +1359,13 @@ def detect_sqlite(self): self.missing.append("_sqlite3") return - sqlite_srcs = [ + cflags = parse_cflags(sysconfig.get_config_var("PY_SQLITE_CFLAGS")) + include_dirs, define_macros, undef_macros, extra_compile_args = cflags + + ldflags = parse_ldflags(sysconfig.get_config_var("PY_SQLITE_LDFLAGS")) + library_dirs, libraries, extra_link_args = ldflags + + sources = [ "_sqlite/connection.c", "_sqlite/cursor.c", "_sqlite/microprotocols.c", @@ -1369,9 +1375,16 @@ def detect_sqlite(self): "_sqlite/statement.c", "_sqlite/util.c", ] - self.add(Extension("_sqlite3", sqlite_srcs, - include_dirs=["Modules/_sqlite"], - libraries=["sqlite3",])) + library_dirs.append("Modules/_sqlite") + self.add(Extension("_sqlite3", + include_dirs=include_dirs, + define_macros=define_macros, + undef_macros=undef_macros, + extra_compile_args=extra_compile_args, + library_dirs=library_dirs, + libraries=libraries, + extra_link_args=extra_link_args, + sources=sources)) def detect_platform_specific_exts(self): # Unix-only modules From e90164d33ac471e651492cb17a2dc85a474fefd0 Mon Sep 17 00:00:00 2001 From: "Erlend E. Aasland" Date: Wed, 17 Nov 2021 14:48:08 +0100 Subject: [PATCH 05/15] Address review --- Modules/Setup | 2 +- configure | 4 ++-- configure.ac | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Modules/Setup b/Modules/Setup index 0c036b43cd8fbc..68467ae5ef0313 100644 --- a/Modules/Setup +++ b/Modules/Setup @@ -218,7 +218,7 @@ time timemodule.c #_dbm _dbmmodule.c -lgdbm_compat -DUSE_GDBM_COMPAT #_gdbm _gdbmmodule.c -lgdbm #_lzma _lzmamodule.c -llzma -#_sqlite3 _sqlite/connection.c _sqlite/cursor.c _sqlite/microprotocols.c _sqlite/module.c _sqlite/prepare_protocol.c _sqlite/row.c _sqlite/statement.c _sqlite/util.c $(PY_SQLITE_LDFLAGS) +#_sqlite3 _sqlite/connection.c _sqlite/cursor.c _sqlite/microprotocols.c _sqlite/module.c _sqlite/prepare_protocol.c _sqlite/row.c _sqlite/statement.c _sqlite/util.c $(PY_SQLITE_CFLAGS) $(PY_SQLITE_LDFLAGS) #_uuid _uuidmodule.c -luuid #zlib zlibmodule.c -lz diff --git a/configure b/configure index ad715934093351..e85c3bb01f4036 100755 --- a/configure +++ b/configure @@ -10926,8 +10926,8 @@ fi if test ! -z "$PKG_CONFIG"; then - as_fn_append PY_SQLITE_CFLAGS "`"$PKG_CONFIG" sqlite3 --cflags-only-I 2>/dev/null`" - as_fn_append PY_SQLITE_LDFLAGS "`"$PKG_CONFIG" sqlite3 --libs-only-L 2>/dev/null`" + as_fn_append PY_SQLITE_CFLAGS "`"$PKG_CONFIG" sqlite3 --cflags 2>/dev/null`" + as_fn_append PY_SQLITE_LDFLAGS "`"$PKG_CONFIG" sqlite3 --libs 2>/dev/null`" fi save_CFLAGS=$CFLAGS diff --git a/configure.ac b/configure.ac index 84df5decfcbcef..638fc6b8f8802b 100644 --- a/configure.ac +++ b/configure.ac @@ -3169,8 +3169,8 @@ dnl Check for SQLite library. Use pkg-config if available. AC_SUBST([PY_SQLITE_CFLAGS]) AC_SUBST([PY_SQLITE_LDFLAGS]) if test ! -z "$PKG_CONFIG"; then - AS_VAR_APPEND([PY_SQLITE_CFLAGS], ["`"$PKG_CONFIG" sqlite3 --cflags-only-I 2>/dev/null`"]) - AS_VAR_APPEND([PY_SQLITE_LDFLAGS], ["`"$PKG_CONFIG" sqlite3 --libs-only-L 2>/dev/null`"]) + AS_VAR_APPEND([PY_SQLITE_CFLAGS], ["`"$PKG_CONFIG" sqlite3 --cflags 2>/dev/null`"]) + AS_VAR_APPEND([PY_SQLITE_LDFLAGS], ["`"$PKG_CONFIG" sqlite3 --libs 2>/dev/null`"]) fi AS_VAR_COPY([save_CFLAGS], [CFLAGS]) From 02ed8244d4541a52bbee545764f08bee8353cadb Mon Sep 17 00:00:00 2001 From: "Erlend E. Aasland" Date: Wed, 17 Nov 2021 15:43:44 +0100 Subject: [PATCH 06/15] Make sure we append with leading whitespace. Set -lsqlite3 if pkg-config not found. --- configure | 7 ++++--- configure.ac | 7 ++++--- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/configure b/configure index e85c3bb01f4036..515918ab66b0f6 100755 --- a/configure +++ b/configure @@ -10926,8 +10926,10 @@ fi if test ! -z "$PKG_CONFIG"; then - as_fn_append PY_SQLITE_CFLAGS "`"$PKG_CONFIG" sqlite3 --cflags 2>/dev/null`" - as_fn_append PY_SQLITE_LDFLAGS "`"$PKG_CONFIG" sqlite3 --libs 2>/dev/null`" + as_fn_append PY_SQLITE_CFLAGS " `"$PKG_CONFIG" sqlite3 --cflags 2>/dev/null`" + as_fn_append PY_SQLITE_LDFLAGS " `"$PKG_CONFIG" sqlite3 --libs 2>/dev/null`" +else + as_fn_append PY_SQLITE_LDFLAGS " -lsqlite3" fi save_CFLAGS=$CFLAGS @@ -10999,7 +11001,6 @@ if ac_fn_c_try_compile "$LINENO"; then : $as_echo "#define HAVE_LIBSQLITE3 1" >>confdefs.h - as_fn_append PY_SQLITE_LDFLAGS " -lsqlite3" fi rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext diff --git a/configure.ac b/configure.ac index 638fc6b8f8802b..26bc25f6f01222 100644 --- a/configure.ac +++ b/configure.ac @@ -3169,8 +3169,10 @@ dnl Check for SQLite library. Use pkg-config if available. AC_SUBST([PY_SQLITE_CFLAGS]) AC_SUBST([PY_SQLITE_LDFLAGS]) if test ! -z "$PKG_CONFIG"; then - AS_VAR_APPEND([PY_SQLITE_CFLAGS], ["`"$PKG_CONFIG" sqlite3 --cflags 2>/dev/null`"]) - AS_VAR_APPEND([PY_SQLITE_LDFLAGS], ["`"$PKG_CONFIG" sqlite3 --libs 2>/dev/null`"]) + AS_VAR_APPEND([PY_SQLITE_CFLAGS], [" `"$PKG_CONFIG" sqlite3 --cflags 2>/dev/null`"]) + AS_VAR_APPEND([PY_SQLITE_LDFLAGS], [" `"$PKG_CONFIG" sqlite3 --libs 2>/dev/null`"]) +else + AS_VAR_APPEND([PY_SQLITE_LDFLAGS], [" -lsqlite3"]) fi AS_VAR_COPY([save_CFLAGS], [CFLAGS]) @@ -3189,7 +3191,6 @@ AC_CHECK_HEADER([sqlite3.h], [ ], []) ], [ AC_DEFINE([HAVE_LIBSQLITE3], [1], [Define if SQLite > 3.7.15 is found]) - AS_VAR_APPEND([PY_SQLITE_LDFLAGS], [" -lsqlite3"]) ]) ]) AC_CHECK_LIB([sqlite3], [sqlite3_load_extension], From 5e851aed51cc7da295021977fdf1cc3ce7831777 Mon Sep 17 00:00:00 2001 From: "Erlend E. Aasland" Date: Thu, 18 Nov 2021 14:18:19 +0100 Subject: [PATCH 07/15] Use pkg-config ac macros --- configure | 178 +++++++++++++++++++++++++++++++++++++++++++++----- configure.ac | 36 +++++----- pyconfig.h.in | 8 +-- setup.py | 22 +------ 4 files changed, 183 insertions(+), 61 deletions(-) diff --git a/configure b/configure index d50382c58527a3..b4dd9c32724c6a 100755 --- a/configure +++ b/configure @@ -624,6 +624,8 @@ ac_includes_default="\ ac_subst_vars='LTLIBOBJS MODULE_BLOCK +MODULE__SQLITE3_FALSE +MODULE__SQLITE3_TRUE MODULE__DECIMAL_FALSE MODULE__DECIMAL_TRUE MODULE__ELEMENTTREE_FALSE @@ -669,8 +671,8 @@ DFLAGS DTRACE TCLTK_LIBS TCLTK_INCLUDES -PY_SQLITE_LDFLAGS -PY_SQLITE_CFLAGS +LIBSQLITE3_LIBS +LIBSQLITE3_CFLAGS LIBMPDEC_INTERNAL LIBMPDEC_LDFLAGS LIBMPDEC_CFLAGS @@ -897,7 +899,9 @@ LDFLAGS LIBS CPPFLAGS CPP -PROFILE_TASK' +PROFILE_TASK +LIBSQLITE3_CFLAGS +LIBSQLITE3_LIBS' # Initialize some variables set by options. @@ -1671,6 +1675,10 @@ Some influential environment variables: CPP C preprocessor PROFILE_TASK Python args for PGO generation task + LIBSQLITE3_CFLAGS + C compiler flags for LIBSQLITE3, overriding pkg-config + LIBSQLITE3_LIBS + linker flags for LIBSQLITE3, overriding pkg-config Use these variables to override the choices made by `configure' or to help it to find libraries and programs with nonstandard names/locations. @@ -10933,18 +10941,90 @@ if test "$have_glibc_memmove_bug" = yes; then fi +pkg_failed=no +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for LIBSQLITE3" >&5 +$as_echo_n "checking for LIBSQLITE3... " >&6; } -if test ! -z "$PKG_CONFIG"; then - as_fn_append PY_SQLITE_CFLAGS " `"$PKG_CONFIG" sqlite3 --cflags 2>/dev/null`" - as_fn_append PY_SQLITE_LDFLAGS " `"$PKG_CONFIG" sqlite3 --libs 2>/dev/null`" +if test -n "$LIBSQLITE3_CFLAGS"; then + pkg_cv_LIBSQLITE3_CFLAGS="$LIBSQLITE3_CFLAGS" + elif test -n "$PKG_CONFIG"; then + if test -n "$PKG_CONFIG" && \ + { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"sqlite3 >= 3.7.15\""; } >&5 + ($PKG_CONFIG --exists --print-errors "sqlite3 >= 3.7.15") 2>&5 + ac_status=$? + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; }; then + pkg_cv_LIBSQLITE3_CFLAGS=`$PKG_CONFIG --cflags "sqlite3 >= 3.7.15" 2>/dev/null` + test "x$?" != "x0" && pkg_failed=yes +else + pkg_failed=yes +fi + else + pkg_failed=untried +fi +if test -n "$LIBSQLITE3_LIBS"; then + pkg_cv_LIBSQLITE3_LIBS="$LIBSQLITE3_LIBS" + elif test -n "$PKG_CONFIG"; then + if test -n "$PKG_CONFIG" && \ + { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"sqlite3 >= 3.7.15\""; } >&5 + ($PKG_CONFIG --exists --print-errors "sqlite3 >= 3.7.15") 2>&5 + ac_status=$? + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; }; then + pkg_cv_LIBSQLITE3_LIBS=`$PKG_CONFIG --libs "sqlite3 >= 3.7.15" 2>/dev/null` + test "x$?" != "x0" && pkg_failed=yes else - as_fn_append PY_SQLITE_LDFLAGS " -lsqlite3" + pkg_failed=yes +fi + else + pkg_failed=untried fi + + +if test $pkg_failed = yes; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } + +if $PKG_CONFIG --atleast-pkgconfig-version 0.20; then + _pkg_short_errors_supported=yes +else + _pkg_short_errors_supported=no +fi + if test $_pkg_short_errors_supported = yes; then + LIBSQLITE3_PKG_ERRORS=`$PKG_CONFIG --short-errors --print-errors --cflags --libs "sqlite3 >= 3.7.15" 2>&1` + else + LIBSQLITE3_PKG_ERRORS=`$PKG_CONFIG --print-errors --cflags --libs "sqlite3 >= 3.7.15" 2>&1` + fi + # Put the nasty error message in config.log where it belongs + echo "$LIBSQLITE3_PKG_ERRORS" >&5 + + + LIBSQLITE3_LIBS="-lsqlite3" + LIBSQLITE3_CFLAGS= + + +elif test $pkg_failed = untried; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } + + LIBSQLITE3_LIBS="-lsqlite3" + LIBSQLITE3_CFLAGS= + + +else + LIBSQLITE3_CFLAGS=$pkg_cv_LIBSQLITE3_CFLAGS + LIBSQLITE3_LIBS=$pkg_cv_LIBSQLITE3_LIBS + { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 +$as_echo "yes" >&6; } + +fi +as_fn_append LIBSQLITE3_CFLAGS ' -I$(srcdir)/Modules/_sqlite' + save_CFLAGS=$CFLAGS save_LDFLAGS=$LDFLAGS -as_fn_append CFLAGS "$PY_SQLITE_CFLAGS" -as_fn_append LDFLAGS "$PY_SQLITE_LDFLAGS" +CFLAGS=$LIBSQLITE3_CFLAGS +LDFLAGS=$LIBSQLITE3_LIBS ac_fn_c_check_header_mongrel "$LINENO" "sqlite3.h" "ac_cv_header_sqlite3_h" "$ac_includes_default" if test "x$ac_cv_header_sqlite3_h" = xyes; then : @@ -10987,6 +11067,7 @@ fi $as_echo "$ac_cv_lib_sqlite3_sqlite3_open_v2" >&6; } if test "x$ac_cv_lib_sqlite3_sqlite3_open_v2" = xyes; then : + have_sqlite3=yes cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ @@ -11006,14 +11087,14 @@ main () _ACEOF if ac_fn_c_try_compile "$LINENO"; then : - - -$as_echo "#define HAVE_LIBSQLITE3 1" >>confdefs.h - - + have_supported_sqlite3=yes +else + have_supported_sqlite3=no fi rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +else + have_sqlite3=no fi { $as_echo "$as_me:${as_lineno-$LINENO}: checking for sqlite3_load_extension in -lsqlite3" >&5 @@ -11053,9 +11134,12 @@ fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_sqlite3_sqlite3_load_extension" >&5 $as_echo "$ac_cv_lib_sqlite3_sqlite3_load_extension" >&6; } if test "x$ac_cv_lib_sqlite3_sqlite3_load_extension" = xyes; then : - have_sqlite3_load_extension=yes -else - have_sqlite3_load_extension=no + cat >>confdefs.h <<_ACEOF +#define HAVE_LIBSQLITE3 1 +_ACEOF + + LIBS="-lsqlite3 $LIBS" + fi @@ -11084,7 +11168,7 @@ $as_echo "$enable_loadable_sqlite_extensions" >&6; } if test "x$enable_loadable_sqlite_extensions" = xyes; then : -$as_echo "#define PY_SQLITE_ENABLE_LOAD_EXTENSION 1" >>confdefs.h +$as_echo "#define LIBSQLITE3_ENABLE_LOAD_EXTENSION 1" >>confdefs.h fi @@ -19569,6 +19653,56 @@ fi $as_echo "$py_cv_module__decimal" >&6; } + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for stdlib extension module _sqlite3" >&5 +$as_echo_n "checking for stdlib extension module _sqlite3... " >&6; } + case $py_stdlib_not_available in #( + *_sqlite3*) : + py_cv_module__sqlite3=n/a ;; #( + *) : + + if test "$have_sqlite3" = "yes"; then : + if test "$have_supported_sqlite3" = "yes"; then : + py_cv_module__sqlite3=yes +else + py_cv_module__sqlite3=missing +fi +else + py_cv_module__sqlite3=disabled + +fi + + ;; +esac + as_fn_append MODULE_BLOCK "MODULE__SQLITE3=$py_cv_module__sqlite3$as_nl" + if test "x$py_cv_module__sqlite3" = xyes; then : + + as_fn_append MODULE_BLOCK "MODULE__SQLITE3_CFLAGS=$LIBSQLITE3_CFLAGS$as_nl" + as_fn_append MODULE_BLOCK "MODULE__SQLITE3_LDFLAGS=$LIBSQLITE3_LIBS$as_nl" + if true; then + MODULE__SQLITE3_TRUE= + MODULE__SQLITE3_FALSE='#' +else + MODULE__SQLITE3_TRUE='#' + MODULE__SQLITE3_FALSE= +fi + + +else + + if false; then + MODULE__SQLITE3_TRUE= + MODULE__SQLITE3_FALSE='#' +else + MODULE__SQLITE3_TRUE='#' + MODULE__SQLITE3_FALSE= +fi + + +fi + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $py_cv_module__sqlite3" >&5 +$as_echo "$py_cv_module__sqlite3" >&6; } + + # substitute multiline block, must come after last PY_STDLIB_MOD() @@ -19719,6 +19853,14 @@ if test -z "${MODULE__DECIMAL_TRUE}" && test -z "${MODULE__DECIMAL_FALSE}"; then as_fn_error $? "conditional \"MODULE__DECIMAL\" was never defined. Usually this means the macro was only invoked conditionally." "$LINENO" 5 fi +if test -z "${MODULE__SQLITE3_TRUE}" && test -z "${MODULE__SQLITE3_FALSE}"; then + as_fn_error $? "conditional \"MODULE__SQLITE3\" was never defined. +Usually this means the macro was only invoked conditionally." "$LINENO" 5 +fi +if test -z "${MODULE__SQLITE3_TRUE}" && test -z "${MODULE__SQLITE3_FALSE}"; then + as_fn_error $? "conditional \"MODULE__SQLITE3\" was never defined. +Usually this means the macro was only invoked conditionally." "$LINENO" 5 +fi : "${CONFIG_STATUS=./config.status}" ac_write_fail=0 diff --git a/configure.ac b/configure.ac index 16c1ea315bdd2e..047747d16d3e70 100644 --- a/configure.ac +++ b/configure.ac @@ -3166,22 +3166,22 @@ if test "$have_glibc_memmove_bug" = yes; then fi dnl Check for SQLite library. Use pkg-config if available. -AC_SUBST([PY_SQLITE_CFLAGS]) -AC_SUBST([PY_SQLITE_LDFLAGS]) -if test ! -z "$PKG_CONFIG"; then - AS_VAR_APPEND([PY_SQLITE_CFLAGS], [" `"$PKG_CONFIG" sqlite3 --cflags 2>/dev/null`"]) - AS_VAR_APPEND([PY_SQLITE_LDFLAGS], [" `"$PKG_CONFIG" sqlite3 --libs 2>/dev/null`"]) -else - AS_VAR_APPEND([PY_SQLITE_LDFLAGS], [" -lsqlite3"]) -fi +PKG_CHECK_MODULES( + [LIBSQLITE3], [sqlite3 >= 3.7.15], [], [ + LIBSQLITE3_LIBS="-lsqlite3" + LIBSQLITE3_CFLAGS= + ] +) +AS_VAR_APPEND([LIBSQLITE3_CFLAGS], [' -I$(srcdir)/Modules/_sqlite']) AS_VAR_COPY([save_CFLAGS], [CFLAGS]) AS_VAR_COPY([save_LDFLAGS], [LDFLAGS]) -AS_VAR_APPEND([CFLAGS], ["$PY_SQLITE_CFLAGS"]) -AS_VAR_APPEND([LDFLAGS], ["$PY_SQLITE_LDFLAGS"]) +AS_VAR_COPY([CFLAGS], [LIBSQLITE3_CFLAGS]) +AS_VAR_COPY([LDFLAGS], [LIBSQLITE3_LIBS]) AC_CHECK_HEADER([sqlite3.h], [ AC_CHECK_LIB([sqlite3], [sqlite3_open_v2], [ + have_sqlite3=yes AC_COMPILE_IFELSE([ AC_LANG_PROGRAM([ #include @@ -3189,13 +3189,9 @@ AC_CHECK_HEADER([sqlite3.h], [ # error "SQLite 3.7.15 or higher required" #endif ], []) - ], [ - AC_DEFINE([HAVE_LIBSQLITE3], [1], [Define if SQLite > 3.7.15 is found]) - ]) - ]) - AC_CHECK_LIB([sqlite3], [sqlite3_load_extension], - [have_sqlite3_load_extension=yes], - [have_sqlite3_load_extension=no]) + ], [have_supported_sqlite3=yes], [have_supported_sqlite3=no]) + ], [have_sqlite3=no]) + AC_CHECK_LIB([sqlite3], [sqlite3_load_extension]) ]) AS_VAR_COPY([CFLAGS], [save_CFLAGS]) @@ -3212,7 +3208,7 @@ AC_ARG_ENABLE(loadable-sqlite-extensions, AC_MSG_RESULT($enable_loadable_sqlite_extensions) AS_VAR_IF([enable_loadable_sqlite_extensions], [yes], [ - AC_DEFINE(PY_SQLITE_ENABLE_LOAD_EXTENSION, 1, + AC_DEFINE(LIBSQLITE3_ENABLE_LOAD_EXTENSION, 1, [Define to 1 to build the sqlite module with loadable extensions support.]) ]) @@ -6036,6 +6032,10 @@ PY_STDLIB_MOD([pyexpat], [], [], [$LIBEXPAT_CFLAGS], [$LIBEXPAT_LDFLAGS]) PY_STDLIB_MOD([_elementtree], [], [], [$LIBEXPAT_CFLAGS], []) PY_STDLIB_MOD([_decimal], [], [], [$LIBMPDEC_CFLAGS], [$LIBMPDEC_LDFLAGS]) +PY_STDLIB_MOD([_sqlite3], + [test "$have_sqlite3" = "yes"], + [test "$have_supported_sqlite3" = "yes"], + [$LIBSQLITE3_CFLAGS], [$LIBSQLITE3_LIBS]) # substitute multiline block, must come after last PY_STDLIB_MOD() AC_SUBST([MODULE_BLOCK]) diff --git a/pyconfig.h.in b/pyconfig.h.in index cb4385bc4566e2..ec9cc13f01475f 100644 --- a/pyconfig.h.in +++ b/pyconfig.h.in @@ -634,7 +634,7 @@ /* Define to 1 if you have the `sendfile' library (-lsendfile). */ #undef HAVE_LIBSENDFILE -/* Define if SQLite > 3.7.15 is found */ +/* Define to 1 if you have the `sqlite3' library (-lsqlite3). */ #undef HAVE_LIBSQLITE3 /* Define to 1 if you have the header file. */ @@ -1399,6 +1399,9 @@ /* Define to 1 if you have the `_getpty' function. */ #undef HAVE__GETPTY +/* Define to 1 to build the sqlite module with loadable extensions support. */ +#undef LIBSQLITE3_ENABLE_LOAD_EXTENSION + /* Define to 1 if `major', `minor', and `makedev' are declared in . */ #undef MAJOR_IN_MKDEV @@ -1449,9 +1452,6 @@ /* Define to printf format modifier for Py_ssize_t */ #undef PY_FORMAT_SIZE_T -/* Define to 1 to build the sqlite module with loadable extensions support. */ -#undef PY_SQLITE_ENABLE_LOAD_EXTENSION - /* Default cipher suites list for ssl module. 1: Python's preferred selection, 2: leave OpenSSL defaults untouched, 0: custom string */ #undef PY_SSL_DEFAULT_CIPHERS diff --git a/setup.py b/setup.py index 119fc1c2f00b00..040f90af601cce 100644 --- a/setup.py +++ b/setup.py @@ -1371,17 +1371,6 @@ def detect_dbm_gdbm(self): self.missing.append('_gdbm') def detect_sqlite(self): - have_sqlite3 = sysconfig.get_config_var("HAVE_LIBSQLITE3") - if not have_sqlite3: - self.missing.append("_sqlite3") - return - - cflags = parse_cflags(sysconfig.get_config_var("PY_SQLITE_CFLAGS")) - include_dirs, define_macros, undef_macros, extra_compile_args = cflags - - ldflags = parse_ldflags(sysconfig.get_config_var("PY_SQLITE_LDFLAGS")) - library_dirs, libraries, extra_link_args = ldflags - sources = [ "_sqlite/connection.c", "_sqlite/cursor.c", @@ -1392,16 +1381,7 @@ def detect_sqlite(self): "_sqlite/statement.c", "_sqlite/util.c", ] - library_dirs.append("Modules/_sqlite") - self.add(Extension("_sqlite3", - include_dirs=include_dirs, - define_macros=define_macros, - undef_macros=undef_macros, - extra_compile_args=extra_compile_args, - library_dirs=library_dirs, - libraries=libraries, - extra_link_args=extra_link_args, - sources=sources)) + self.addext(Extension("_sqlite3", sources=sources)) def detect_platform_specific_exts(self): # Unix-only modules From 7cc1bcc1e6249860a66eb15abd084788e4b97c40 Mon Sep 17 00:00:00 2001 From: "Erlend E. Aasland" Date: Thu, 18 Nov 2021 14:21:54 +0100 Subject: [PATCH 08/15] Module/Setup flags are added automatically --- Modules/Setup | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Modules/Setup b/Modules/Setup index 7b14450be2cdd1..904f2ef210b880 100644 --- a/Modules/Setup +++ b/Modules/Setup @@ -227,7 +227,7 @@ time timemodule.c #_dbm _dbmmodule.c -lgdbm_compat -DUSE_GDBM_COMPAT #_gdbm _gdbmmodule.c -lgdbm #_lzma _lzmamodule.c -llzma -#_sqlite3 _sqlite/connection.c _sqlite/cursor.c _sqlite/microprotocols.c _sqlite/module.c _sqlite/prepare_protocol.c _sqlite/row.c _sqlite/statement.c _sqlite/util.c $(PY_SQLITE_CFLAGS) $(PY_SQLITE_LDFLAGS) +#_sqlite3 _sqlite/connection.c _sqlite/cursor.c _sqlite/microprotocols.c _sqlite/module.c _sqlite/prepare_protocol.c _sqlite/row.c _sqlite/statement.c _sqlite/util.c #_uuid _uuidmodule.c -luuid #zlib zlibmodule.c -lz From f3c920ba76fb8771f2f8f1214b1f531851c79316 Mon Sep 17 00:00:00 2001 From: "Erlend E. Aasland" Date: Thu, 18 Nov 2021 14:29:11 +0100 Subject: [PATCH 09/15] Revert spurious change --- configure | 2 +- configure.ac | 2 +- pyconfig.h.in | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/configure b/configure index b4dd9c32724c6a..2e2b948f5da024 100755 --- a/configure +++ b/configure @@ -11168,7 +11168,7 @@ $as_echo "$enable_loadable_sqlite_extensions" >&6; } if test "x$enable_loadable_sqlite_extensions" = xyes; then : -$as_echo "#define LIBSQLITE3_ENABLE_LOAD_EXTENSION 1" >>confdefs.h +$as_echo "#define PY_SQLITE_ENABLE_LOAD_EXTENSION 1" >>confdefs.h fi diff --git a/configure.ac b/configure.ac index 047747d16d3e70..42a2cbd62bffa4 100644 --- a/configure.ac +++ b/configure.ac @@ -3208,7 +3208,7 @@ AC_ARG_ENABLE(loadable-sqlite-extensions, AC_MSG_RESULT($enable_loadable_sqlite_extensions) AS_VAR_IF([enable_loadable_sqlite_extensions], [yes], [ - AC_DEFINE(LIBSQLITE3_ENABLE_LOAD_EXTENSION, 1, + AC_DEFINE(PY_SQLITE_ENABLE_LOAD_EXTENSION, 1, [Define to 1 to build the sqlite module with loadable extensions support.]) ]) diff --git a/pyconfig.h.in b/pyconfig.h.in index ec9cc13f01475f..0cc593fdfc569e 100644 --- a/pyconfig.h.in +++ b/pyconfig.h.in @@ -1399,9 +1399,6 @@ /* Define to 1 if you have the `_getpty' function. */ #undef HAVE__GETPTY -/* Define to 1 to build the sqlite module with loadable extensions support. */ -#undef LIBSQLITE3_ENABLE_LOAD_EXTENSION - /* Define to 1 if `major', `minor', and `makedev' are declared in . */ #undef MAJOR_IN_MKDEV @@ -1452,6 +1449,9 @@ /* Define to printf format modifier for Py_ssize_t */ #undef PY_FORMAT_SIZE_T +/* Define to 1 to build the sqlite module with loadable extensions support. */ +#undef PY_SQLITE_ENABLE_LOAD_EXTENSION + /* Default cipher suites list for ssl module. 1: Python's preferred selection, 2: leave OpenSSL defaults untouched, 0: custom string */ #undef PY_SSL_DEFAULT_CIPHERS From 1cac68177e429403f436f24601a58f8b5e745b5f Mon Sep 17 00:00:00 2001 From: "Erlend E. Aasland" Date: Thu, 18 Nov 2021 14:34:52 +0100 Subject: [PATCH 10/15] Adjust NEWS wording --- .../next/Build/2021-11-09-23-30-12.bpo-45774.Mwm3ZR.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Misc/NEWS.d/next/Build/2021-11-09-23-30-12.bpo-45774.Mwm3ZR.rst b/Misc/NEWS.d/next/Build/2021-11-09-23-30-12.bpo-45774.Mwm3ZR.rst index a2d943cd044e09..09095ab2cf9f57 100644 --- a/Misc/NEWS.d/next/Build/2021-11-09-23-30-12.bpo-45774.Mwm3ZR.rst +++ b/Misc/NEWS.d/next/Build/2021-11-09-23-30-12.bpo-45774.Mwm3ZR.rst @@ -1,2 +1,2 @@ -The build dependencies for :mod:`sqlite3` are now detected by ``configure``. -Patch by Erlend E. Aasland. +The build dependencies for :mod:`sqlite3` are now detected by ``configure`` and +``pkg-config``. Patch by Erlend E. Aasland. From 338f4d03ed41a0bd6331a6d14e8499f9345a31c0 Mon Sep 17 00:00:00 2001 From: "Erlend E. Aasland" Date: Thu, 18 Nov 2021 15:04:46 +0100 Subject: [PATCH 11/15] Move sqlite3 from Modules/Setup to Modules/Setup.stdlib.in --- Modules/Setup | 1 - Modules/Setup.stdlib.in | 6 ++++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/Modules/Setup b/Modules/Setup index 904f2ef210b880..f8c90ea77721dd 100644 --- a/Modules/Setup +++ b/Modules/Setup @@ -227,7 +227,6 @@ time timemodule.c #_dbm _dbmmodule.c -lgdbm_compat -DUSE_GDBM_COMPAT #_gdbm _gdbmmodule.c -lgdbm #_lzma _lzmamodule.c -llzma -#_sqlite3 _sqlite/connection.c _sqlite/cursor.c _sqlite/microprotocols.c _sqlite/module.c _sqlite/prepare_protocol.c _sqlite/row.c _sqlite/statement.c _sqlite/util.c #_uuid _uuidmodule.c -luuid #zlib zlibmodule.c -lz diff --git a/Modules/Setup.stdlib.in b/Modules/Setup.stdlib.in index 0722eae87a3582..2e87b032e35e8e 100644 --- a/Modules/Setup.stdlib.in +++ b/Modules/Setup.stdlib.in @@ -53,3 +53,9 @@ # Linux and FreeBSD, needs sys/soundcard.h or linux/soundcard.h @MODULE_OSSAUDIODEV_TRUE@ossaudiodev ossaudiodev.c + + +############################################################################ +# Modules with third party dependencies +# +@MODULE__SQLITE3_TRUE@_sqlite3 _sqlite/connection.c _sqlite/cursor.c _sqlite/microprotocols.c _sqlite/module.c _sqlite/prepare_protocol.c _sqlite/row.c _sqlite/statement.c _sqlite/util.c From b8fb844f779b189ca69c768427116a750341694b Mon Sep 17 00:00:00 2001 From: Erlend Egeberg Aasland Date: Thu, 18 Nov 2021 20:42:40 +0100 Subject: [PATCH 12/15] Address review: don't abort on failure to enable loadable SQLite extensions Co-authored-by: Christian Heimes --- configure.ac | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/configure.ac b/configure.ac index a37fd34b79ed13..88b5a18ae99357 100644 --- a/configure.ac +++ b/configure.ac @@ -3203,7 +3203,7 @@ AC_ARG_ENABLE(loadable-sqlite-extensions, AS_HELP_STRING([--enable-loadable-sqlite-extensions], [support loadable extensions in _sqlite module, see Doc/library/sqlite3.rst (default is no)]), [AS_VAR_IF([have_sqlite3_load_extension], [no], - [AC_MSG_ERROR([Your version of SQLite does not support loadable extensions])])], + [AC_MSG_WARN([Your version of SQLite does not support loadable extensions])])], [enable_loadable_sqlite_extensions=no]) AC_MSG_RESULT($enable_loadable_sqlite_extensions) From d7c41801c6d2a78781c67eb570d33ce4765e850f Mon Sep 17 00:00:00 2001 From: "Erlend E. Aasland" Date: Thu, 18 Nov 2021 20:52:09 +0100 Subject: [PATCH 13/15] Regenerate configure --- configure | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/configure b/configure index 6e3783eb8f701d..793a82783c6231 100755 --- a/configure +++ b/configure @@ -11156,7 +11156,8 @@ $as_echo_n "checking for --enable-loadable-sqlite-extensions... " >&6; } # Check whether --enable-loadable-sqlite-extensions was given. if test "${enable_loadable_sqlite_extensions+set}" = set; then : enableval=$enable_loadable_sqlite_extensions; if test "x$have_sqlite3_load_extension" = xno; then : - as_fn_error $? "Your version of SQLite does not support loadable extensions" "$LINENO" 5 + { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: Your version of SQLite does not support loadable extensions" >&5 +$as_echo "$as_me: WARNING: Your version of SQLite does not support loadable extensions" >&2;} fi else enable_loadable_sqlite_extensions=no From 41a78b5b36d9c82ba6ce3bd00688bba32be55ba4 Mon Sep 17 00:00:00 2001 From: "Erlend E. Aasland" Date: Fri, 19 Nov 2021 10:41:39 +0100 Subject: [PATCH 14/15] Address macOS (arm) and FreeBSD buildbot issues --- configure | 8 ++++---- configure.ac | 10 ++++++---- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/configure b/configure index 793a82783c6231..920566b4c02134 100755 --- a/configure +++ b/configure @@ -11021,10 +11021,10 @@ $as_echo "yes" >&6; } fi as_fn_append LIBSQLITE3_CFLAGS ' -I$(srcdir)/Modules/_sqlite' -save_CFLAGS=$CFLAGS +save_CPPFLAGS=$CPPFLAGS save_LDFLAGS=$LDFLAGS -CFLAGS=$LIBSQLITE3_CFLAGS -LDFLAGS=$LIBSQLITE3_LIBS +CPPFLAGS="$LIBSQLITE3_CFLAGS $CFLAGS" +LDFLAGS="$LIBSQLITE3_LIBS $LDFLAGS" ac_fn_c_check_header_mongrel "$LINENO" "sqlite3.h" "ac_cv_header_sqlite3_h" "$ac_includes_default" if test "x$ac_cv_header_sqlite3_h" = xyes; then : @@ -11147,7 +11147,7 @@ fi -CFLAGS=$save_CFLAGS +CPPFLAGS=$save_CPPFLAGS LDFLAGS=$save_LDFLAGS # Check for support for loadable sqlite extensions diff --git a/configure.ac b/configure.ac index 88b5a18ae99357..16bde961d9aa14 100644 --- a/configure.ac +++ b/configure.ac @@ -3174,10 +3174,12 @@ PKG_CHECK_MODULES( ) AS_VAR_APPEND([LIBSQLITE3_CFLAGS], [' -I$(srcdir)/Modules/_sqlite']) -AS_VAR_COPY([save_CFLAGS], [CFLAGS]) +dnl bpo-45774/GH-29507: The CPP check in AC_CHECK_HEADER can fail on FreeBSD, +dnl hence CPPFLAGS instead of CFLAGS. +AS_VAR_COPY([save_CPPFLAGS], [CPPFLAGS]) AS_VAR_COPY([save_LDFLAGS], [LDFLAGS]) -AS_VAR_COPY([CFLAGS], [LIBSQLITE3_CFLAGS]) -AS_VAR_COPY([LDFLAGS], [LIBSQLITE3_LIBS]) +CPPFLAGS="$LIBSQLITE3_CFLAGS $CFLAGS" +LDFLAGS="$LIBSQLITE3_LIBS $LDFLAGS" AC_CHECK_HEADER([sqlite3.h], [ AC_CHECK_LIB([sqlite3], [sqlite3_open_v2], [ @@ -3194,7 +3196,7 @@ AC_CHECK_HEADER([sqlite3.h], [ AC_CHECK_LIB([sqlite3], [sqlite3_load_extension]) ]) -AS_VAR_COPY([CFLAGS], [save_CFLAGS]) +AS_VAR_COPY([CPPFLAGS], [save_CPPFLAGS]) AS_VAR_COPY([LDFLAGS], [save_LDFLAGS]) # Check for support for loadable sqlite extensions From 0173b66cb41c042a195ac72027a8fac2ede927eb Mon Sep 17 00:00:00 2001 From: "Erlend E. Aasland" Date: Fri, 19 Nov 2021 11:34:12 +0100 Subject: [PATCH 15/15] We need to save/restore CFLAGS and LIBS --- configure | 4 ++++ configure.ac | 7 ++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/configure b/configure index 920566b4c02134..657c71dca62bdd 100755 --- a/configure +++ b/configure @@ -11021,8 +11021,10 @@ $as_echo "yes" >&6; } fi as_fn_append LIBSQLITE3_CFLAGS ' -I$(srcdir)/Modules/_sqlite' +save_CFLAGS=$CFLAGS save_CPPFLAGS=$CPPFLAGS save_LDFLAGS=$LDFLAGS +save_LIBS=$LIBS CPPFLAGS="$LIBSQLITE3_CFLAGS $CFLAGS" LDFLAGS="$LIBSQLITE3_LIBS $LDFLAGS" @@ -11147,8 +11149,10 @@ fi +CFLAGS=$save_CFLAGS CPPFLAGS=$save_CPPFLAGS LDFLAGS=$save_LDFLAGS +LIBS=$save_LIBS # Check for support for loadable sqlite extensions { $as_echo "$as_me:${as_lineno-$LINENO}: checking for --enable-loadable-sqlite-extensions" >&5 diff --git a/configure.ac b/configure.ac index 16bde961d9aa14..4bac7ccf2484ea 100644 --- a/configure.ac +++ b/configure.ac @@ -3175,9 +3175,12 @@ PKG_CHECK_MODULES( AS_VAR_APPEND([LIBSQLITE3_CFLAGS], [' -I$(srcdir)/Modules/_sqlite']) dnl bpo-45774/GH-29507: The CPP check in AC_CHECK_HEADER can fail on FreeBSD, -dnl hence CPPFLAGS instead of CFLAGS. +dnl hence CPPFLAGS instead of CFLAGS. We still need to save CFLAGS, because it +dnl is touched by AC_CHECK_HEADER. +AS_VAR_COPY([save_CFLAGS], [CFLAGS]) AS_VAR_COPY([save_CPPFLAGS], [CPPFLAGS]) AS_VAR_COPY([save_LDFLAGS], [LDFLAGS]) +AS_VAR_COPY([save_LIBS], [LIBS]) CPPFLAGS="$LIBSQLITE3_CFLAGS $CFLAGS" LDFLAGS="$LIBSQLITE3_LIBS $LDFLAGS" @@ -3196,8 +3199,10 @@ AC_CHECK_HEADER([sqlite3.h], [ AC_CHECK_LIB([sqlite3], [sqlite3_load_extension]) ]) +AS_VAR_COPY([CFLAGS], [save_CFLAGS]) AS_VAR_COPY([CPPFLAGS], [save_CPPFLAGS]) AS_VAR_COPY([LDFLAGS], [save_LDFLAGS]) +AS_VAR_COPY([LIBS], [save_LIBS]) # Check for support for loadable sqlite extensions AC_MSG_CHECKING(for --enable-loadable-sqlite-extensions)