From f3dd7f7b734eb2c5530d81a88d3e52f776063d74 Mon Sep 17 00:00:00 2001 From: Emma Harper Smith Date: Tue, 6 May 2025 19:55:04 -0700 Subject: [PATCH 1/2] Support finding libzstd not in pkg-config GH-133479 removed the logic to check for libzstd outside of pkg-config. This commit adds that logic back with a check for the version so that users can provide their own libzstd. This is to bring parity with lzma, bz2, and zlib detection. --- configure | 266 +++++++++++++++++++++++++++++++++++++++++++++++++- configure.ac | 22 ++++- pyconfig.h.in | 6 ++ 3 files changed, 291 insertions(+), 3 deletions(-) diff --git a/configure b/configure index c51192f12c8223..ab14d81fcc5464 100755 --- a/configure +++ b/configure @@ -22451,11 +22451,273 @@ fi # Put the nasty error message in config.log where it belongs echo "$LIBZSTD_PKG_ERRORS" >&5 - have_libzstd=no + + save_CFLAGS=$CFLAGS +save_CPPFLAGS=$CPPFLAGS +save_LDFLAGS=$LDFLAGS +save_LIBS=$LIBS + + + CPPFLAGS="$CPPFLAGS $LIBZSTD_CFLAGS" + CFLAGS="$CFLAGS $LIBZSTD_CFLAGS" + LIBS="$LIBS $LIBZSTD_LIBS" + for ac_header in zstd.h zdict.h +do : + as_ac_Header=`printf "%s\n" "ac_cv_header_$ac_header" | sed "$as_sed_sh"` +ac_fn_c_check_header_compile "$LINENO" "$ac_header" "$as_ac_Header" "$ac_includes_default" +if eval test \"x\$"$as_ac_Header"\" = x"yes" +then : + cat >>confdefs.h <<_ACEOF +#define `printf "%s\n" "HAVE_$ac_header" | sed "$as_sed_cpp"` 1 +_ACEOF + + py_check_lib_save_LIBS=$LIBS +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for ZDICT_finalizeDictionary in -lzstd" >&5 +printf %s "checking for ZDICT_finalizeDictionary in -lzstd... " >&6; } +if test ${ac_cv_lib_zstd_ZDICT_finalizeDictionary+y} +then : + printf %s "(cached) " >&6 +else case e in #( + e) ac_check_lib_save_LIBS=$LIBS +LIBS="-lzstd $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. + The 'extern "C"' is for builds by C++ compilers; + although this is not generally supported in C code supporting it here + has little cost and some practical benefit (sr 110532). */ +#ifdef __cplusplus +extern "C" +#endif +char ZDICT_finalizeDictionary (void); +int +main (void) +{ +return ZDICT_finalizeDictionary (); + ; + return 0; +} +_ACEOF +if ac_fn_c_try_link "$LINENO" +then : + ac_cv_lib_zstd_ZDICT_finalizeDictionary=yes +else case e in #( + e) ac_cv_lib_zstd_ZDICT_finalizeDictionary=no ;; +esac +fi +rm -f core conftest.err conftest.$ac_objext conftest.beam \ + conftest$ac_exeext conftest.$ac_ext +LIBS=$ac_check_lib_save_LIBS ;; +esac +fi +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_zstd_ZDICT_finalizeDictionary" >&5 +printf "%s\n" "$ac_cv_lib_zstd_ZDICT_finalizeDictionary" >&6; } +if test "x$ac_cv_lib_zstd_ZDICT_finalizeDictionary" = xyes +then : + + if test "$cross_compiling" = yes +then : + { { printf "%s\n" "$as_me:${as_lineno-$LINENO}: error: in '$ac_pwd':" >&5 +printf "%s\n" "$as_me: error: in '$ac_pwd':" >&2;} +as_fn_error $? "cannot run test program while cross compiling +See 'config.log' for more details" "$LINENO" 5; } +else case e in #( + e) cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +#include "zstd.h" +int +main (void) +{ + + #if ZSTD_VERSION_NUMBER < 10405 + exit(1); + #endif + + ; + return 0; +} + +_ACEOF +if ac_fn_c_try_run "$LINENO" +then : + have_libzstd=yes +else case e in #( + e) have_libzstd=no ;; +esac +fi +rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \ + conftest.$ac_objext conftest.beam conftest.$ac_ext ;; +esac +fi + + +else case e in #( + e) have_libzstd=no ;; +esac +fi + +LIBS=$py_check_lib_save_LIBS + + +else case e in #( + e) have_libzstd=no ;; +esac +fi + +done + if test "x$have_libzstd" = xyes +then : + + LIBZSTD_CFLAGS=${LIBZSTD_CFLAGS-""} + LIBZSTD_LIBS=${LIBZSTD_LIBS-"-lzstd"} + +fi + +CFLAGS=$save_CFLAGS +CPPFLAGS=$save_CPPFLAGS +LDFLAGS=$save_LDFLAGS +LIBS=$save_LIBS + + + elif test $pkg_failed = untried; then { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 printf "%s\n" "no" >&6; } - have_libzstd=no + + save_CFLAGS=$CFLAGS +save_CPPFLAGS=$CPPFLAGS +save_LDFLAGS=$LDFLAGS +save_LIBS=$LIBS + + + CPPFLAGS="$CPPFLAGS $LIBZSTD_CFLAGS" + CFLAGS="$CFLAGS $LIBZSTD_CFLAGS" + LIBS="$LIBS $LIBZSTD_LIBS" + for ac_header in zstd.h zdict.h +do : + as_ac_Header=`printf "%s\n" "ac_cv_header_$ac_header" | sed "$as_sed_sh"` +ac_fn_c_check_header_compile "$LINENO" "$ac_header" "$as_ac_Header" "$ac_includes_default" +if eval test \"x\$"$as_ac_Header"\" = x"yes" +then : + cat >>confdefs.h <<_ACEOF +#define `printf "%s\n" "HAVE_$ac_header" | sed "$as_sed_cpp"` 1 +_ACEOF + + py_check_lib_save_LIBS=$LIBS +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for ZDICT_finalizeDictionary in -lzstd" >&5 +printf %s "checking for ZDICT_finalizeDictionary in -lzstd... " >&6; } +if test ${ac_cv_lib_zstd_ZDICT_finalizeDictionary+y} +then : + printf %s "(cached) " >&6 +else case e in #( + e) ac_check_lib_save_LIBS=$LIBS +LIBS="-lzstd $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. + The 'extern "C"' is for builds by C++ compilers; + although this is not generally supported in C code supporting it here + has little cost and some practical benefit (sr 110532). */ +#ifdef __cplusplus +extern "C" +#endif +char ZDICT_finalizeDictionary (void); +int +main (void) +{ +return ZDICT_finalizeDictionary (); + ; + return 0; +} +_ACEOF +if ac_fn_c_try_link "$LINENO" +then : + ac_cv_lib_zstd_ZDICT_finalizeDictionary=yes +else case e in #( + e) ac_cv_lib_zstd_ZDICT_finalizeDictionary=no ;; +esac +fi +rm -f core conftest.err conftest.$ac_objext conftest.beam \ + conftest$ac_exeext conftest.$ac_ext +LIBS=$ac_check_lib_save_LIBS ;; +esac +fi +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_zstd_ZDICT_finalizeDictionary" >&5 +printf "%s\n" "$ac_cv_lib_zstd_ZDICT_finalizeDictionary" >&6; } +if test "x$ac_cv_lib_zstd_ZDICT_finalizeDictionary" = xyes +then : + + if test "$cross_compiling" = yes +then : + { { printf "%s\n" "$as_me:${as_lineno-$LINENO}: error: in '$ac_pwd':" >&5 +printf "%s\n" "$as_me: error: in '$ac_pwd':" >&2;} +as_fn_error $? "cannot run test program while cross compiling +See 'config.log' for more details" "$LINENO" 5; } +else case e in #( + e) cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +#include "zstd.h" +int +main (void) +{ + + #if ZSTD_VERSION_NUMBER < 10405 + exit(1); + #endif + + ; + return 0; +} + +_ACEOF +if ac_fn_c_try_run "$LINENO" +then : + have_libzstd=yes +else case e in #( + e) have_libzstd=no ;; +esac +fi +rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \ + conftest.$ac_objext conftest.beam conftest.$ac_ext ;; +esac +fi + + +else case e in #( + e) have_libzstd=no ;; +esac +fi + +LIBS=$py_check_lib_save_LIBS + + +else case e in #( + e) have_libzstd=no ;; +esac +fi + +done + if test "x$have_libzstd" = xyes +then : + + LIBZSTD_CFLAGS=${LIBZSTD_CFLAGS-""} + LIBZSTD_LIBS=${LIBZSTD_LIBS-"-lzstd"} + +fi + +CFLAGS=$save_CFLAGS +CPPFLAGS=$save_CPPFLAGS +LDFLAGS=$save_LDFLAGS +LIBS=$save_LIBS + + + else LIBZSTD_CFLAGS=$pkg_cv_LIBZSTD_CFLAGS LIBZSTD_LIBS=$pkg_cv_LIBZSTD_LIBS diff --git a/configure.ac b/configure.ac index a7b2f62579b0e9..d223fa33334b52 100644 --- a/configure.ac +++ b/configure.ac @@ -5387,7 +5387,27 @@ PKG_CHECK_MODULES([LIBLZMA], [liblzma], [have_liblzma=yes], [ ]) dnl zstd 1.4.5 stabilised ZDICT_finalizeDictionary -PKG_CHECK_MODULES([LIBZSTD], [libzstd >= 1.4.5], [have_libzstd=yes], [have_libzstd=no]) +PKG_CHECK_MODULES([LIBZSTD], [libzstd >= 1.4.5], [have_libzstd=yes], [ + WITH_SAVE_ENV([ + CPPFLAGS="$CPPFLAGS $LIBZSTD_CFLAGS" + CFLAGS="$CFLAGS $LIBZSTD_CFLAGS" + LIBS="$LIBS $LIBZSTD_LIBS" + AC_CHECK_HEADERS([zstd.h zdict.h], [ + PY_CHECK_LIB([zstd], [ZDICT_finalizeDictionary], [ + AC_RUN_IFELSE([AC_LANG_PROGRAM([@%:@include "zstd.h"], [ + #if ZSTD_VERSION_NUMBER < 10405 + exit(1); + #endif + ]) + ], [have_libzstd=yes], [have_libzstd=no]) + ], [have_libzstd=no]) + ], [have_libzstd=no]) + AS_VAR_IF([have_libzstd], [yes], [ + LIBZSTD_CFLAGS=${LIBZSTD_CFLAGS-""} + LIBZSTD_LIBS=${LIBZSTD_LIBS-"-lzstd"} + ]) + ]) +]) dnl PY_CHECK_NETDB_FUNC(FUNCTION) AC_DEFUN([PY_CHECK_NETDB_FUNC], [PY_CHECK_FUNC([$1], [@%:@include ])]) diff --git a/pyconfig.h.in b/pyconfig.h.in index 7586ad3f266705..c91facbedf94e5 100644 --- a/pyconfig.h.in +++ b/pyconfig.h.in @@ -1630,12 +1630,18 @@ /* Define to 1 if you have the 'writev' function. */ #undef HAVE_WRITEV +/* Define to 1 if you have the header file. */ +#undef HAVE_ZDICT_H + /* Define if the zlib library has inflateCopy */ #undef HAVE_ZLIB_COPY /* Define to 1 if you have the header file. */ #undef HAVE_ZLIB_H +/* Define to 1 if you have the header file. */ +#undef HAVE_ZSTD_H + /* Define to 1 if you have the '_getpty' function. */ #undef HAVE__GETPTY From 235fe6941f5dbe0235885f7e65782854154da33f Mon Sep 17 00:00:00 2001 From: Emma Harper Smith Date: Wed, 7 May 2025 08:54:34 -0700 Subject: [PATCH 2/2] Use AC_COMPILE_IFELSE and checking message when looking for zstd Co-authored-by: Adam Turner <9087854+AA-Turner@users.noreply.github.com> --- configure | 62 +++++++++++++++++++++++++--------------------------- configure.ac | 11 ++++++++-- 2 files changed, 39 insertions(+), 34 deletions(-) diff --git a/configure b/configure index ab14d81fcc5464..f51ec9bcd06654 100755 --- a/configure +++ b/configure @@ -22518,14 +22518,9 @@ printf "%s\n" "$ac_cv_lib_zstd_ZDICT_finalizeDictionary" >&6; } if test "x$ac_cv_lib_zstd_ZDICT_finalizeDictionary" = xyes then : - if test "$cross_compiling" = yes -then : - { { printf "%s\n" "$as_me:${as_lineno-$LINENO}: error: in '$ac_pwd':" >&5 -printf "%s\n" "$as_me: error: in '$ac_pwd':" >&2;} -as_fn_error $? "cannot run test program while cross compiling -See 'config.log' for more details" "$LINENO" 5; } -else case e in #( - e) cat confdefs.h - <<_ACEOF >conftest.$ac_ext + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking ZSTD_VERSION_NUMBER >= 1.4.5" >&5 +printf %s "checking ZSTD_VERSION_NUMBER >= 1.4.5... " >&6; } + cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #include "zstd.h" int @@ -22541,18 +22536,22 @@ main (void) } _ACEOF -if ac_fn_c_try_run "$LINENO" +if ac_fn_c_try_compile "$LINENO" then : - have_libzstd=yes + + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: yes" >&5 +printf "%s\n" "yes" >&6; } + have_libzstd=yes + else case e in #( - e) have_libzstd=no ;; -esac -fi -rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \ - conftest.$ac_objext conftest.beam conftest.$ac_ext ;; + e) + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 +printf "%s\n" "no" >&6; } + have_libzstd=no + ;; esac fi - +rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext else case e in #( e) have_libzstd=no ;; @@ -22653,14 +22652,9 @@ printf "%s\n" "$ac_cv_lib_zstd_ZDICT_finalizeDictionary" >&6; } if test "x$ac_cv_lib_zstd_ZDICT_finalizeDictionary" = xyes then : - if test "$cross_compiling" = yes -then : - { { printf "%s\n" "$as_me:${as_lineno-$LINENO}: error: in '$ac_pwd':" >&5 -printf "%s\n" "$as_me: error: in '$ac_pwd':" >&2;} -as_fn_error $? "cannot run test program while cross compiling -See 'config.log' for more details" "$LINENO" 5; } -else case e in #( - e) cat confdefs.h - <<_ACEOF >conftest.$ac_ext + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking ZSTD_VERSION_NUMBER >= 1.4.5" >&5 +printf %s "checking ZSTD_VERSION_NUMBER >= 1.4.5... " >&6; } + cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #include "zstd.h" int @@ -22676,18 +22670,22 @@ main (void) } _ACEOF -if ac_fn_c_try_run "$LINENO" +if ac_fn_c_try_compile "$LINENO" then : - have_libzstd=yes + + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: yes" >&5 +printf "%s\n" "yes" >&6; } + have_libzstd=yes + else case e in #( - e) have_libzstd=no ;; -esac -fi -rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \ - conftest.$ac_objext conftest.beam conftest.$ac_ext ;; + e) + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 +printf "%s\n" "no" >&6; } + have_libzstd=no + ;; esac fi - +rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext else case e in #( e) have_libzstd=no ;; diff --git a/configure.ac b/configure.ac index d223fa33334b52..bc72fa982ff809 100644 --- a/configure.ac +++ b/configure.ac @@ -5394,12 +5394,19 @@ PKG_CHECK_MODULES([LIBZSTD], [libzstd >= 1.4.5], [have_libzstd=yes], [ LIBS="$LIBS $LIBZSTD_LIBS" AC_CHECK_HEADERS([zstd.h zdict.h], [ PY_CHECK_LIB([zstd], [ZDICT_finalizeDictionary], [ - AC_RUN_IFELSE([AC_LANG_PROGRAM([@%:@include "zstd.h"], [ + AC_MSG_CHECKING([ZSTD_VERSION_NUMBER >= 1.4.5]) + AC_COMPILE_IFELSE([AC_LANG_PROGRAM([@%:@include "zstd.h"], [ #if ZSTD_VERSION_NUMBER < 10405 exit(1); #endif ]) - ], [have_libzstd=yes], [have_libzstd=no]) + ], [ + AC_MSG_RESULT([yes]) + have_libzstd=yes + ], [ + AC_MSG_RESULT([no]) + have_libzstd=no + ]) ], [have_libzstd=no]) ], [have_libzstd=no]) AS_VAR_IF([have_libzstd], [yes], [