gh-139314: Add support for linking against `zlib-rs` and `libbzip2-rs` (#155119)

StanFromIreland <[email protected]>
Newsgroups gmane.comp.python.cvs
Message-ID <[email protected]>
https://github.com/python/cpython/commit/5d91cf6487eb5aa37107598c792573f61ebe310f
commit: 5d91cf6487eb5aa37107598c792573f61ebe310f
branch: main
author: Stan Ulbrych <[email protected]>
committer: StanFromIreland <[email protected]>
date: 2026-08-14T10:06:14+01:00
summary:

gh-139314: Add support for linking against `zlib-rs` and `libbzip2-rs` (#155119)

files:
A Misc/NEWS.d/next/Build/2025-09-25-01-33-12.gh-issue-139314._m9BUl.rst
M Doc/using/configure.rst
M Doc/whatsnew/3.16.rst
M configure
M configure.ac

diff --git a/Doc/using/configure.rst b/Doc/using/configure.rst
index 28edf0408fd36e8..8b4940ceb9521a7 100644
--- a/Doc/using/configure.rst
+++ b/Doc/using/configure.rst
@@ -71,7 +71,8 @@ Dependencies to build optional modules are:
    * - Dependency
      - Minimum version
      - Python module
-   * - `libbz2 <https://sourceware.org/bzip2/>`_
+   * - `libbz2 <https://sourceware.org/bzip2/>`_ or
+       `libbzip2-rs <https://github.com/trifectatechfoundation/libbzip2-rs>`_ [1]_
      -
      - :mod:`bz2`
    * - `libffi <https://sourceware.org/libffi/>`_
@@ -82,47 +83,54 @@ Dependencies to build optional modules are:
      - :mod:`lzma`
    * - `libmpdec <https://www.bytereef.org/mpdecimal/doc/libmpdec/>`_
      - 2.5.0
-     - :mod:`decimal` [1]_
+     - :mod:`decimal` [2]_
    * - `libreadline <https://tiswww.case.edu/php/chet/readline/rltop.html>`_ or
-       `libedit <https://www.thrysoee.dk/editline/>`_ [2]_
+       `libedit <https://www.thrysoee.dk/editline/>`_ [3]_
      -
      - :mod:`readline`
    * - `libuuid <https://linux.die.net/man/3/libuuid>`_
      -
-     - ``_uuid`` [3]_
-   * - `ncurses <https://gnu.org/software/ncurses/ncurses.html>`_ [4]_
+     - ``_uuid`` [4]_
+   * - `ncurses <https://gnu.org/software/ncurses/ncurses.html>`_ [5]_
      -
      - :mod:`curses`
    * - `OpenSSL <https://openssl-library.org/>`_
      - | 3.0.18 recommended
        | (1.1.1 minimum)
-     - :mod:`ssl`, :mod:`hashlib` [5]_
+     - :mod:`ssl`, :mod:`hashlib` [6]_
    * - `SQLite <https://sqlite.org/>`_
      - 3.15.2
      - :mod:`sqlite3`
    * - `Tcl/Tk <https://www.tcl-lang.org/>`_
      - 8.5.12
      - :mod:`tkinter`, :ref:`IDLE <idle>`, :mod:`turtle`
-   * - `zlib <https://www.zlib.net>`_
-     - 1.2.2.1
+   * - `zlib <https://www.zlib.net>`_,
+       `zlib-ng <https://github.com/zlib-ng/zlib-ng>`_, or
+       `zlib-rs <https://github.com/trifectatechfoundation/zlib-rs/>`_ [7]_
+     - | 1.2.2.1 (zlib, zlib-ng)
+       | 0.6.0 (zlib-rs)
      - :mod:`zlib`, :mod:`gzip`, :mod:`ensurepip`
    * - `zstd <https://facebook.github.io/zstd/>`_
      - 1.4.5
      - :mod:`compression.zstd`
 
-.. [1] If *libmpdec* is not available, the :mod:`decimal` module will use
+.. [1] See :option:`--with-bzip2` for choosing the backend for the
+   :mod:`bz2` module.
+.. [2] If *libmpdec* is not available, the :mod:`decimal` module will use
    a pure-Python implementation.
-.. [2] See :option:`--with-readline` for choosing the backend for the
+.. [3] See :option:`--with-readline` for choosing the backend for the
    :mod:`readline` module.
-.. [3] The :mod:`uuid` module uses ``_uuid`` to generate "safe" UUIDs.
+.. [4] The :mod:`uuid` module uses ``_uuid`` to generate "safe" UUIDs.
    See the module documentation for details.
-.. [4] The :mod:`curses` module requires the ``libncurses`` or ``libncursesw``
+.. [5] The :mod:`curses` module requires the ``libncurses`` or ``libncursesw``
    library.
    The :mod:`curses.panel` module additionally requires the ``libpanel`` or
    ``libpanelw`` library.
-.. [5] If OpenSSL is not available, the :mod:`hashlib` module will use
+.. [6] If OpenSSL is not available, the :mod:`hashlib` module will use
    bundled implementations of several hash functions.
    See :option:`--with-builtin-hashlib-hashes` for *forcing* usage of OpenSSL.
+.. [7] See :option:`--with-zlib` for choosing the backend for the
+   :mod:`zlib` module.
 
 Note that the table does not include all optional modules; in particular,
 platform-specific modules like :mod:`winreg` are not listed here.
@@ -1113,6 +1121,54 @@ Libraries options
 
    .. versionadded:: next
 
+.. option:: --with-zlib=zlib|zlib-ng|zlib-rs
+
+   Designate the zlib implementation to build the :mod:`zlib` module against.
+
+   * ``zlib``: Use the system zlib library, found via ``pkg-config`` or as
+     ``libz``.
+   * ``zlib-ng``: Same detection as ``zlib``, but fail unless the detected
+     library is `zlib-ng <https://github.com/zlib-ng/zlib-ng>`__.
+   * ``zlib-rs``: Use `zlib-rs
+     <https://github.com/trifectatechfoundation/zlib-rs/>`__, found via
+     ``pkg-config`` as ``libz_rs``.
+
+   Without this option (or with ``--with-zlib=auto``, the default), the system
+   zlib is used when found; configure only fails when an implementation was
+   requested explicitly but cannot be found.
+
+   .. versionadded:: next
+
+.. option:: --without-zlib
+
+   Don't build the :mod:`zlib` module, even when a zlib library is present
+   (built by default when one is found).
+
+   .. versionadded:: next
+
+.. option:: --with-bzip2=bzip2|bzip2-rs
+
+   Designate the bzip2 implementation to build the :mod:`bz2` module against.
+
+   * ``bzip2``: Use the system bzip2 library, found via ``pkg-config`` or as
+     ``libbz2``.
+   * ``bzip2-rs``: Use `libbzip2-rs
+     <https://github.com/trifectatechfoundation/libbzip2-rs>`__, found via
+     ``pkg-config`` as ``libbz2_rs``.
+
+   Without this option (or with ``--with-bzip2=auto``, the default), the
+   system bzip2 is used when found; configure only fails when an
+   implementation was requested explicitly but cannot be found.
+
+   .. versionadded:: next
+
+.. option:: --without-bzip2
+
+   Don't build the :mod:`bz2` module, even when a bzip2 library is present
+   (built by default when one is found).
+
+   .. versionadded:: next
+
 .. option:: --with-libm=STRING
 
    Override ``libm`` math library to *STRING* (default is system-dependent).
diff --git a/Doc/whatsnew/3.16.rst b/Doc/whatsnew/3.16.rst
index 9d3bdd21509a9eb..063755e1eadcb53 100644
--- a/Doc/whatsnew/3.16.rst
+++ b/Doc/whatsnew/3.16.rst
@@ -877,6 +877,18 @@ Build changes
 
   (Contributed by Serhiy Storchaka in :gh:`136687`.)
 
+* Add the :option:`--with-zlib` and :option:`--with-bzip2` :program:`configure`
+  options to select the zlib and bzip2 implementations used to build the
+  :mod:`zlib` and :mod:`bz2` modules. In addition to the default system
+  libraries, they can build against `zlib-rs
+  <https://github.com/trifectatechfoundation/zlib-rs/>`__ and `libbzip2-rs
+  <https://github.com/trifectatechfoundation/libbzip2-rs>`__, and
+  ``--with-zlib=zlib-ng`` verifies that the detected zlib is `zlib-ng
+  <https://github.com/zlib-ng/zlib-ng>`__. :option:`--without-zlib` and
+  :option:`--without-bzip2` exclude the modules from the build.
+
+  (Contributed by Stan Ulbrych in :gh:`139314`.)
+
 
 C API changes
 =============
diff --git a/Misc/NEWS.d/next/Build/2025-09-25-01-33-12.gh-issue-139314._m9BUl.rst b/Misc/NEWS.d/next/Build/2025-09-25-01-33-12.gh-issue-139314._m9BUl.rst
new file mode 100644
index 000000000000000..afc78af0d28fc7a
--- /dev/null
+++ b/Misc/NEWS.d/next/Build/2025-09-25-01-33-12.gh-issue-139314._m9BUl.rst
@@ -0,0 +1,9 @@
+Add the :option:`--with-zlib` and :option:`--with-bzip2` :program:`configure`
+options to select the zlib and bzip2 implementations used to build the
+:mod:`zlib` and :mod:`bz2` modules. In addition to the default system
+libraries, they can build against `zlib-rs
+<https://github.com/trifectatechfoundation/zlib-rs/>`__ and `libbzip2-rs
+<https://github.com/trifectatechfoundation/libbzip2-rs>`__, and
+``--with-zlib=zlib-ng`` verifies that the detected zlib is `zlib-ng
+<https://github.com/zlib-ng/zlib-ng>`__. :option:`--without-zlib` and
+:option:`--without-bzip2` exclude the modules from the build.
diff --git a/configure b/configure
index 598a21fb31f7501..ea560d600722592 100755
--- a/configure
+++ b/configure
@@ -1142,6 +1142,8 @@ with_c_locale_coercion
 with_valgrind
 with_dtrace
 enable_epoll
+with_zlib
+with_bzip2
 with_libm
 with_libc
 enable_big_digits
@@ -1964,6 +1966,12 @@ Optional Packages:
                           (default is yes)
   --with-valgrind         enable Valgrind support (default is no)
   --with-dtrace           enable DTrace support (default is no)
+  --with(out)-zlib[=zlib|zlib-ng|zlib-rs|no]
+                          select the zlib implementation to link against, or
+                          disable zlib support (default: auto)
+  --with(out)-bzip2[=bzip2|bzip2-rs|no]
+                          select the bzip2 implementation to link against, or
+                          disable bzip2 support (default: auto)
   --with-libm=STRING      override libm math library to STRING (default is
                           system-dependent)
   --with-libc=STRING      override libc C library to STRING (default is
@@ -22837,6 +22845,30 @@ fi
 
 
 
+{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for --with-zlib" >&5
+printf %s "checking for --with-zlib... " >&6; }
+
+# Check whether --with-zlib was given.
+if test ${with_zlib+y}
+then :
+  withval=$with_zlib; case $with_zlib in #(
+  yes|auto) :
+    with_zlib=auto ;; #(
+  zlib|zlib-ng|zlib-rs|no) :
+     ;; #(
+  *) :
+    as_fn_error $? "proper usage is --with(out)-zlib[=zlib|zlib-ng|zlib-rs|no]" "$LINENO" 5 ;;
+esac
+else case e in #(
+  e) with_zlib=auto ;;
+esac
+fi
+
+{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $with_zlib" >&5
+printf "%s\n" "$with_zlib" >&6; }
+
+case $with_zlib in #(
+  auto|zlib) :
 
 
 
@@ -22849,23 +22881,47 @@ then :
 fi
 
 
+ ;; #(
+  *) :
+     ;;
+esac
+
+if test "x$with_zlib" = xzlib-rs
+then :
+
+  zlib_name="libz_rs"
+  zlib_version="0.6.0"
+  zlib_libname="z_rs"
 
+else case e in #(
+  e)
+  zlib_name="zlib"
+  zlib_version="1.2.2.1"
+  zlib_libname="z"
+ ;;
+esac
+fi
 
+if test "x$with_zlib" = xno
+then :
+  have_zlib=no
+else case e in #(
+  e)
 
 pkg_failed=no
-{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for zlib >= 1.2.2.1" >&5
-printf %s "checking for zlib >= 1.2.2.1... " >&6; }
+{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $zlib_name >= $zlib_version" >&5
+printf %s "checking for $zlib_name >= $zlib_version... " >&6; }
 
 if test -n "$ZLIB_CFLAGS"; then
     pkg_cv_ZLIB_CFLAGS="$ZLIB_CFLAGS"
  elif test -n "$PKG_CONFIG"; then
     if test -n "$PKG_CONFIG" && \
-    { { printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"zlib >= 1.2.2.1\""; } >&5
-  ($PKG_CONFIG --exists --print-errors "zlib >= 1.2.2.1") 2>&5
+    { { printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"\$zlib_name >= \$zlib_version\""; } >&5
+  ($PKG_CONFIG --exists --print-errors "$zlib_name >= $zlib_version") 2>&5
   ac_status=$?
   printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
   test $ac_status = 0; }; then
-  pkg_cv_ZLIB_CFLAGS=`$PKG_CONFIG --cflags "zlib >= 1.2.2.1" 2>/dev/null`
+  pkg_cv_ZLIB_CFLAGS=`$PKG_CONFIG --cflags "$zlib_name >= $zlib_version" 2>/dev/null`
 		      test "x$?" != "x0" && pkg_failed=yes
 else
   pkg_failed=yes
@@ -22877,12 +22933,12 @@ if test -n "$ZLIB_LIBS"; then
     pkg_cv_ZLIB_LIBS="$ZLIB_LIBS"
  elif test -n "$PKG_CONFIG"; then
     if test -n "$PKG_CONFIG" && \
-    { { printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"zlib >= 1.2.2.1\""; } >&5
-  ($PKG_CONFIG --exists --print-errors "zlib >= 1.2.2.1") 2>&5
+    { { printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"\$zlib_name >= \$zlib_version\""; } >&5
+  ($PKG_CONFIG --exists --print-errors "$zlib_name >= $zlib_version") 2>&5
   ac_status=$?
   printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
   test $ac_status = 0; }; then
-  pkg_cv_ZLIB_LIBS=`$PKG_CONFIG --libs "zlib >= 1.2.2.1" 2>/dev/null`
+  pkg_cv_ZLIB_LIBS=`$PKG_CONFIG --libs "$zlib_name >= $zlib_version" 2>/dev/null`
 		      test "x$?" != "x0" && pkg_failed=yes
 else
   pkg_failed=yes
@@ -22903,9 +22959,9 @@ else
         _pkg_short_errors_supported=no
 fi
         if test $_pkg_short_errors_supported = yes; then
-                ZLIB_PKG_ERRORS=`$PKG_CONFIG --short-errors --print-errors --cflags --libs "zlib >= 1.2.2.1" 2>&1`
+                ZLIB_PKG_ERRORS=`$PKG_CONFIG --short-errors --print-errors --cflags --libs "$zlib_name >= $zlib_version" 2>&1`
         else
-                ZLIB_PKG_ERRORS=`$PKG_CONFIG --print-errors --cflags --libs "zlib >= 1.2.2.1" 2>&1`
+                ZLIB_PKG_ERRORS=`$PKG_CONFIG --print-errors --cflags --libs "$zlib_name >= $zlib_version" 2>&1`
         fi
         # Put the nasty error message in config.log where it belongs
         echo "$ZLIB_PKG_ERRORS" >&5
@@ -22927,14 +22983,15 @@ then :
   printf "%s\n" "#define HAVE_ZLIB_H 1" >>confdefs.h
 
       py_check_lib_save_LIBS=$LIBS
-{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for gzread in -lz" >&5
-printf %s "checking for gzread in -lz... " >&6; }
-if test ${ac_cv_lib_z_gzread+y}
+as_ac_Lib=`printf "%s\n" "ac_cv_lib_$zlib_libname""_gzread" | sed "$as_sed_sh"`
+{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for gzread in -l$zlib_libname" >&5
+printf %s "checking for gzread in -l$zlib_libname... " >&6; }
+if eval test \${$as_ac_Lib+y}
 then :
   printf %s "(cached) " >&6
 else case e in #(
   e) ac_check_lib_save_LIBS=$LIBS
-LIBS="-lz  $LIBS"
+LIBS="-l$zlib_libname  $LIBS"
 cat confdefs.h - <<_ACEOF >conftest.$ac_ext
 /* end confdefs.h.  */
 
@@ -22958,9 +23015,9 @@ return gzread ();
 _ACEOF
 if ac_fn_c_try_link "$LINENO"
 then :
-  ac_cv_lib_z_gzread=yes
+  eval "$as_ac_Lib=yes"
 else case e in #(
-  e) ac_cv_lib_z_gzread=no ;;
+  e) eval "$as_ac_Lib=no" ;;
 esac
 fi
 rm -f core conftest.err conftest.$ac_objext conftest.beam \
@@ -22968,9 +23025,10 @@ rm -f core conftest.err conftest.$ac_objext conftest.beam \
 LIBS=$ac_check_lib_save_LIBS ;;
 esac
 fi
-{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_z_gzread" >&5
-printf "%s\n" "$ac_cv_lib_z_gzread" >&6; }
-if test "x$ac_cv_lib_z_gzread" = xyes
+eval ac_res=\$$as_ac_Lib
+	       { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5
+printf "%s\n" "$ac_res" >&6; }
+if eval test \"x\$"$as_ac_Lib"\" = x"yes"
 then :
   have_zlib=yes
 else case e in #(
@@ -22991,16 +23049,17 @@ done
 then :
 
       ZLIB_CFLAGS=${ZLIB_CFLAGS-""}
-      ZLIB_LIBS=${ZLIB_LIBS-"-lz"}
+      ZLIB_LIBS=${ZLIB_LIBS-"-l$zlib_libname"}
       py_check_lib_save_LIBS=$LIBS
-{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for inflateCopy in -lz" >&5
-printf %s "checking for inflateCopy in -lz... " >&6; }
-if test ${ac_cv_lib_z_inflateCopy+y}
+as_ac_Lib=`printf "%s\n" "ac_cv_lib_$zlib_libname""_inflateCopy" | sed "$as_sed_sh"`
+{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for inflateCopy in -l$zlib_libname" >&5
+printf %s "checking for inflateCopy in -l$zlib_libname... " >&6; }
+if eval test \${$as_ac_Lib+y}
 then :
   printf %s "(cached) " >&6
 else case e in #(
   e) ac_check_lib_save_LIBS=$LIBS
-LIBS="-lz  $LIBS"
+LIBS="-l$zlib_libname  $LIBS"
 cat confdefs.h - <<_ACEOF >conftest.$ac_ext
 /* end confdefs.h.  */
 
@@ -23024,9 +23083,9 @@ return inflateCopy ();
 _ACEOF
 if ac_fn_c_try_link "$LINENO"
 then :
-  ac_cv_lib_z_inflateCopy=yes
+  eval "$as_ac_Lib=yes"
 else case e in #(
-  e) ac_cv_lib_z_inflateCopy=no ;;
+  e) eval "$as_ac_Lib=no" ;;
 esac
 fi
 rm -f core conftest.err conftest.$ac_objext conftest.beam \
@@ -23034,9 +23093,10 @@ rm -f core conftest.err conftest.$ac_objext conftest.beam \
 LIBS=$ac_check_lib_save_LIBS ;;
 esac
 fi
-{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_z_inflateCopy" >&5
-printf "%s\n" "$ac_cv_lib_z_inflateCopy" >&6; }
-if test "x$ac_cv_lib_z_inflateCopy" = xyes
+eval ac_res=\$$as_ac_Lib
+	       { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5
+printf "%s\n" "$ac_res" >&6; }
+if eval test \"x\$"$as_ac_Lib"\" = x"yes"
 then :
   printf "%s\n" "#define HAVE_ZLIB_COPY 1" >>confdefs.h
 
@@ -23074,14 +23134,15 @@ then :
   printf "%s\n" "#define HAVE_ZLIB_H 1" >>confdefs.h
 
       py_check_lib_save_LIBS=$LIBS
-{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for gzread in -lz" >&5
-printf %s "checking for gzread in -lz... " >&6; }
-if test ${ac_cv_lib_z_gzread+y}
+as_ac_Lib=`printf "%s\n" "ac_cv_lib_$zlib_libname""_gzread" | sed "$as_sed_sh"`
+{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for gzread in -l$zlib_libname" >&5
+printf %s "checking for gzread in -l$zlib_libname... " >&6; }
+if eval test \${$as_ac_Lib+y}
 then :
   printf %s "(cached) " >&6
 else case e in #(
   e) ac_check_lib_save_LIBS=$LIBS
-LIBS="-lz  $LIBS"
+LIBS="-l$zlib_libname  $LIBS"
 cat confdefs.h - <<_ACEOF >conftest.$ac_ext
 /* end confdefs.h.  */
 
@@ -23105,9 +23166,9 @@ return gzread ();
 _ACEOF
 if ac_fn_c_try_link "$LINENO"
 then :
-  ac_cv_lib_z_gzread=yes
+  eval "$as_ac_Lib=yes"
 else case e in #(
-  e) ac_cv_lib_z_gzread=no ;;
+  e) eval "$as_ac_Lib=no" ;;
 esac
 fi
 rm -f core conftest.err conftest.$ac_objext conftest.beam \
@@ -23115,9 +23176,10 @@ rm -f core conftest.err conftest.$ac_objext conftest.beam \
 LIBS=$ac_check_lib_save_LIBS ;;
 esac
 fi
-{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_z_gzread" >&5
-printf "%s\n" "$ac_cv_lib_z_gzread" >&6; }
-if test "x$ac_cv_lib_z_gzread" = xyes
+eval ac_res=\$$as_ac_Lib
+	       { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5
+printf "%s\n" "$ac_res" >&6; }
+if eval test \"x\$"$as_ac_Lib"\" = x"yes"
 then :
   have_zlib=yes
 else case e in #(
@@ -23138,16 +23200,17 @@ done
 then :
 
       ZLIB_CFLAGS=${ZLIB_CFLAGS-""}
-      ZLIB_LIBS=${ZLIB_LIBS-"-lz"}
+      ZLIB_LIBS=${ZLIB_LIBS-"-l$zlib_libname"}
       py_check_lib_save_LIBS=$LIBS
-{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for inflateCopy in -lz" >&5
-printf %s "checking for inflateCopy in -lz... " >&6; }
-if test ${ac_cv_lib_z_inflateCopy+y}
+as_ac_Lib=`printf "%s\n" "ac_cv_lib_$zlib_libname""_inflateCopy" | sed "$as_sed_sh"`
+{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for inflateCopy in -l$zlib_libname" >&5
+printf %s "checking for inflateCopy in -l$zlib_libname... " >&6; }
+if eval test \${$as_ac_Lib+y}
 then :
   printf %s "(cached) " >&6
 else case e in #(
   e) ac_check_lib_save_LIBS=$LIBS
-LIBS="-lz  $LIBS"
+LIBS="-l$zlib_libname  $LIBS"
 cat confdefs.h - <<_ACEOF >conftest.$ac_ext
 /* end confdefs.h.  */
 
@@ -23171,9 +23234,9 @@ return inflateCopy ();
 _ACEOF
 if ac_fn_c_try_link "$LINENO"
 then :
-  ac_cv_lib_z_inflateCopy=yes
+  eval "$as_ac_Lib=yes"
 else case e in #(
-  e) ac_cv_lib_z_inflateCopy=no ;;
+  e) eval "$as_ac_Lib=no" ;;
 esac
 fi
 rm -f core conftest.err conftest.$ac_objext conftest.beam \
@@ -23181,9 +23244,10 @@ rm -f core conftest.err conftest.$ac_objext conftest.beam \
 LIBS=$ac_check_lib_save_LIBS ;;
 esac
 fi
-{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_z_inflateCopy" >&5
-printf "%s\n" "$ac_cv_lib_z_inflateCopy" >&6; }
-if test "x$ac_cv_lib_z_inflateCopy" = xyes
+eval ac_res=\$$as_ac_Lib
+	       { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5
+printf "%s\n" "$ac_res" >&6; }
+if eval test \"x\$"$as_ac_Lib"\" = x"yes"
 then :
   printf "%s\n" "#define HAVE_ZLIB_COPY 1" >>confdefs.h
 
@@ -23211,8 +23275,53 @@ printf "%s\n" "yes" >&6; }
     printf "%s\n" "#define HAVE_ZLIB_COPY 1" >>confdefs.h
 
 
+fi
+ ;;
+esac
 fi
 
+if test "x$with_zlib" = xzlib-ng
+then :
+  if test "x$have_zlib" = xyes
+then :
+
+  save_CFLAGS=$CFLAGS
+save_CPPFLAGS=$CPPFLAGS
+save_LDFLAGS=$LDFLAGS
+save_LIBS=$LIBS
+
+
+    CPPFLAGS="$CPPFLAGS $ZLIB_CFLAGS"
+    ac_fn_check_decl "$LINENO" "ZLIBNG_VERSION" "ac_cv_have_decl_ZLIBNG_VERSION" "#include <zlib.h>
+" "$ac_c_undeclared_builtin_options" "CFLAGS"
+if test "x$ac_cv_have_decl_ZLIBNG_VERSION" = xyes
+then :
+
+else case e in #(
+  e) as_fn_error $? "--with-zlib=zlib-ng: the detected zlib library is not zlib-ng" "$LINENO" 5 ;;
+esac
+fi
+
+CFLAGS=$save_CFLAGS
+CPPFLAGS=$save_CPPFLAGS
+LDFLAGS=$save_LDFLAGS
+LIBS=$save_LIBS
+
+
+
+fi
+fi
+
+case $with_zlib in #(
+  auto|no) :
+     ;; #(
+  *) :
+    if test "x$have_zlib" = xno
+then :
+  as_fn_error $? "--with-zlib=$with_zlib requested but $zlib_name was not found" "$LINENO" 5
+fi ;;
+esac
+
 if test "x$have_zlib" = xyes
 then :
 
@@ -23221,6 +23330,30 @@ then :
 
 fi
 
+{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for --with-bzip2" >&5
+printf %s "checking for --with-bzip2... " >&6; }
+
+# Check whether --with-bzip2 was given.
+if test ${with_bzip2+y}
+then :
+  withval=$with_bzip2; case $with_bzip2 in #(
+  yes|auto) :
+    with_bzip2=auto ;; #(
+  bzip2|bzip2-rs|no) :
+     ;; #(
+  *) :
+    as_fn_error $? "proper usage is --with(out)-bzip2[=bzip2|bzip2-rs|no]" "$LINENO" 5 ;;
+esac
+else case e in #(
+  e) with_bzip2=auto ;;
+esac
+fi
+
+{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $with_bzip2" >&5
+printf "%s\n" "$with_bzip2" >&6; }
+
+case $with_bzip2 in #(
+  auto|bzip2) :
 
 
 
@@ -23233,23 +23366,45 @@ then :
 fi
 
 
+ ;; #(
+  *) :
+     ;;
+esac
+
+if test "x$with_bzip2" = xbzip2-rs
+then :
+
+  bzip2_name="libbz2_rs"
+  bzip2_libname="bz2_rs"
 
+else case e in #(
+  e)
+  bzip2_name="bzip2"
+  bzip2_libname="bz2"
+ ;;
+esac
+fi
 
+if test "x$with_bzip2" = xno
+then :
+  have_bzip2=no
+else case e in #(
+  e)
 
 pkg_failed=no
-{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for bzip2" >&5
-printf %s "checking for bzip2... " >&6; }
+{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $bzip2_name" >&5
+printf %s "checking for $bzip2_name... " >&6; }
 
 if test -n "$BZIP2_CFLAGS"; then
     pkg_cv_BZIP2_CFLAGS="$BZIP2_CFLAGS"
  elif test -n "$PKG_CONFIG"; then
     if test -n "$PKG_CONFIG" && \
-    { { printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"bzip2\""; } >&5
-  ($PKG_CONFIG --exists --print-errors "bzip2") 2>&5
+    { { printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"\$bzip2_name\""; } >&5
+  ($PKG_CONFIG --exists --print-errors "$bzip2_name") 2>&5
   ac_status=$?
   printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
   test $ac_status = 0; }; then
-  pkg_cv_BZIP2_CFLAGS=`$PKG_CONFIG --cflags "bzip2" 2>/dev/null`
+  pkg_cv_BZIP2_CFLAGS=`$PKG_CONFIG --cflags "$bzip2_name" 2>/dev/null`
 		      test "x$?" != "x0" && pkg_failed=yes
 else
   pkg_failed=yes
@@ -23261,12 +23416,12 @@ if test -n "$BZIP2_LIBS"; then
     pkg_cv_BZIP2_LIBS="$BZIP2_LIBS"
  elif test -n "$PKG_CONFIG"; then
     if test -n "$PKG_CONFIG" && \
-    { { printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"bzip2\""; } >&5
-  ($PKG_CONFIG --exists --print-errors "bzip2") 2>&5
+    { { printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"\$bzip2_name\""; } >&5
+  ($PKG_CONFIG --exists --print-errors "$bzip2_name") 2>&5
   ac_status=$?
   printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
   test $ac_status = 0; }; then
-  pkg_cv_BZIP2_LIBS=`$PKG_CONFIG --libs "bzip2" 2>/dev/null`
+  pkg_cv_BZIP2_LIBS=`$PKG_CONFIG --libs "$bzip2_name" 2>/dev/null`
 		      test "x$?" != "x0" && pkg_failed=yes
 else
   pkg_failed=yes
@@ -23287,9 +23442,9 @@ else
         _pkg_short_errors_supported=no
 fi
         if test $_pkg_short_errors_supported = yes; then
-                BZIP2_PKG_ERRORS=`$PKG_CONFIG --short-errors --print-errors --cflags --libs "bzip2" 2>&1`
+                BZIP2_PKG_ERRORS=`$PKG_CONFIG --short-errors --print-errors --cflags --libs "$bzip2_name" 2>&1`
         else
-                BZIP2_PKG_ERRORS=`$PKG_CONFIG --print-errors --cflags --libs "bzip2" 2>&1`
+                BZIP2_PKG_ERRORS=`$PKG_CONFIG --print-errors --cflags --libs "$bzip2_name" 2>&1`
         fi
         # Put the nasty error message in config.log where it belongs
         echo "$BZIP2_PKG_ERRORS" >&5
@@ -23310,14 +23465,15 @@ if test "x$ac_cv_header_bzlib_h" = xyes
 then :
   printf "%s\n" "#define HAVE_BZLIB_H 1" >>confdefs.h
 
-      { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for BZ2_bzCompress in -lbz2" >&5
-printf %s "checking for BZ2_bzCompress in -lbz2... " >&6; }
-if test ${ac_cv_lib_bz2_BZ2_bzCompress+y}
+      as_ac_Lib=`printf "%s\n" "ac_cv_lib_$bzip2_libname""_BZ2_bzCompress" | sed "$as_sed_sh"`
+{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for BZ2_bzCompress in -l$bzip2_libname" >&5
+printf %s "checking for BZ2_bzCompress in -l$bzip2_libname... " >&6; }
+if eval test \${$as_ac_Lib+y}
 then :
   printf %s "(cached) " >&6
 else case e in #(
   e) ac_check_lib_save_LIBS=$LIBS
-LIBS="-lbz2  $LIBS"
+LIBS="-l$bzip2_libname  $LIBS"
 cat confdefs.h - <<_ACEOF >conftest.$ac_ext
 /* end confdefs.h.  */
 
@@ -23341,9 +23497,9 @@ return BZ2_bzCompress ();
 _ACEOF
 if ac_fn_c_try_link "$LINENO"
 then :
-  ac_cv_lib_bz2_BZ2_bzCompress=yes
+  eval "$as_ac_Lib=yes"
 else case e in #(
-  e) ac_cv_lib_bz2_BZ2_bzCompress=no ;;
+  e) eval "$as_ac_Lib=no" ;;
 esac
 fi
 rm -f core conftest.err conftest.$ac_objext conftest.beam \
@@ -23351,9 +23507,10 @@ rm -f core conftest.err conftest.$ac_objext conftest.beam \
 LIBS=$ac_check_lib_save_LIBS ;;
 esac
 fi
-{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_bz2_BZ2_bzCompress" >&5
-printf "%s\n" "$ac_cv_lib_bz2_BZ2_bzCompress" >&6; }
-if test "x$ac_cv_lib_bz2_BZ2_bzCompress" = xyes
+eval ac_res=\$$as_ac_Lib
+	       { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5
+printf "%s\n" "$ac_res" >&6; }
+if eval test \"x\$"$as_ac_Lib"\" = x"yes"
 then :
   have_bzip2=yes
 else case e in #(
@@ -23372,7 +23529,7 @@ done
 then :
 
       BZIP2_CFLAGS=${BZIP2_CFLAGS-""}
-      BZIP2_LIBS=${BZIP2_LIBS-"-lbz2"}
+      BZIP2_LIBS=${BZIP2_LIBS-"-l$bzip2_libname"}
 
 fi
 
@@ -23402,14 +23559,15 @@ if test "x$ac_cv_header_bzlib_h" = xyes
 then :
   printf "%s\n" "#define HAVE_BZLIB_H 1" >>confdefs.h
 
-      { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for BZ2_bzCompress in -lbz2" >&5
-printf %s "checking for BZ2_bzCompress in -lbz2... " >&6; }
-if test ${ac_cv_lib_bz2_BZ2_bzCompress+y}
+      as_ac_Lib=`printf "%s\n" "ac_cv_lib_$bzip2_libname""_BZ2_bzCompress" | sed "$as_sed_sh"`
+{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for BZ2_bzCompress in -l$bzip2_libname" >&5
+printf %s "checking for BZ2_bzCompress in -l$bzip2_libname... " >&6; }
+if eval test \${$as_ac_Lib+y}
 then :
   printf %s "(cached) " >&6
 else case e in #(
   e) ac_check_lib_save_LIBS=$LIBS
-LIBS="-lbz2  $LIBS"
+LIBS="-l$bzip2_libname  $LIBS"
 cat confdefs.h - <<_ACEOF >conftest.$ac_ext
 /* end confdefs.h.  */
 
@@ -23433,9 +23591,9 @@ return BZ2_bzCompress ();
 _ACEOF
 if ac_fn_c_try_link "$LINENO"
 then :
-  ac_cv_lib_bz2_BZ2_bzCompress=yes
+  eval "$as_ac_Lib=yes"
 else case e in #(
-  e) ac_cv_lib_bz2_BZ2_bzCompress=no ;;
+  e) eval "$as_ac_Lib=no" ;;
 esac
 fi
 rm -f core conftest.err conftest.$ac_objext conftest.beam \
@@ -23443,9 +23601,10 @@ rm -f core conftest.err conftest.$ac_objext conftest.beam \
 LIBS=$ac_check_lib_save_LIBS ;;
 esac
 fi
-{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_bz2_BZ2_bzCompress" >&5
-printf "%s\n" "$ac_cv_lib_bz2_BZ2_bzCompress" >&6; }
-if test "x$ac_cv_lib_bz2_BZ2_bzCompress" = xyes
+eval ac_res=\$$as_ac_Lib
+	       { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5
+printf "%s\n" "$ac_res" >&6; }
+if eval test \"x\$"$as_ac_Lib"\" = x"yes"
 then :
   have_bzip2=yes
 else case e in #(
@@ -23464,7 +23623,7 @@ done
 then :
 
       BZIP2_CFLAGS=${BZIP2_CFLAGS-""}
-      BZIP2_LIBS=${BZIP2_LIBS-"-lbz2"}
+      BZIP2_LIBS=${BZIP2_LIBS-"-l$bzip2_libname"}
 
 fi
 
@@ -23482,6 +23641,19 @@ else
 printf "%s\n" "yes" >&6; }
         have_bzip2=yes
 fi
+ ;;
+esac
+fi
+
+case $with_bzip2 in #(
+  auto|no) :
+     ;; #(
+  *) :
+    if test "x$have_bzip2" = xno
+then :
+  as_fn_error $? "--with-bzip2=$with_bzip2 requested but $bzip2_name was not found" "$LINENO" 5
+fi ;;
+esac
 
 
 pkg_failed=no
diff --git a/configure.ac b/configure.ac
index 47c5f7e49422a5d..7dfc6ca29297a8b 100644
--- a/configure.ac
+++ b/configure.ac
@@ -5706,10 +5706,34 @@ fi
 dnl Check for compression libraries
 AH_TEMPLATE([HAVE_ZLIB_COPY], [Define if the zlib library has inflateCopy])
 
+AC_MSG_CHECKING([for --with-zlib])
+AC_ARG_WITH(
+  [zlib],
+  [AS_HELP_STRING([--with(out)-zlib@<:@=zlib|zlib-ng|zlib-rs|no@:>@],
+                  [select the zlib implementation to link against, or disable
+                   zlib support (default: auto)])],
+  [AS_CASE([$with_zlib],
+     [yes|auto], [with_zlib=auto],
+     [zlib|zlib-ng|zlib-rs|no], [],
+     [AC_MSG_ERROR([proper usage is --with(out)-zlib@<:@=zlib|zlib-ng|zlib-rs|no@:>@])])],
+  [with_zlib=auto])
+AC_MSG_RESULT([$with_zlib])
+
 dnl detect zlib from Emscripten emport
-PY_CHECK_EMSCRIPTEN_PORT([ZLIB], [-sUSE_ZLIB])
+AS_CASE([$with_zlib], [auto|zlib], [PY_CHECK_EMSCRIPTEN_PORT([ZLIB], [-sUSE_ZLIB])])
+
+AS_VAR_IF([with_zlib], [zlib-rs], [
+  AS_VAR_SET([zlib_name], ["libz_rs"])
+  AS_VAR_SET([zlib_version], ["0.6.0"])
+  AS_VAR_SET([zlib_libname], ["z_rs"])
+], [
+  AS_VAR_SET([zlib_name], ["zlib"])
+  AS_VAR_SET([zlib_version], ["1.2.2.1"])
+  AS_VAR_SET([zlib_libname], ["z"])
+])
 
-PKG_CHECK_MODULES([ZLIB], [zlib >= 1.2.2.1], [
+AS_VAR_IF([with_zlib], [no], [have_zlib=no], [
+PKG_CHECK_MODULES([ZLIB], [$zlib_name >= $zlib_version], [
   have_zlib=yes
   dnl zlib 1.2.0 (2003) added inflateCopy
   AC_DEFINE([HAVE_ZLIB_COPY], [1])
@@ -5718,15 +5742,30 @@ PKG_CHECK_MODULES([ZLIB], [zlib >= 1.2.2.1], [
     CPPFLAGS="$CPPFLAGS $ZLIB_CFLAGS"
     LIBS="$LIBS $ZLIB_LIBS"
     AC_CHECK_HEADERS([zlib.h], [
-      PY_CHECK_LIB([z], [gzread], [have_zlib=yes], [have_zlib=no])
+      PY_CHECK_LIB([$zlib_libname], [gzread], [have_zlib=yes], [have_zlib=no])
     ], [have_zlib=no])
     AS_VAR_IF([have_zlib], [yes], [
       ZLIB_CFLAGS=${ZLIB_CFLAGS-""}
-      ZLIB_LIBS=${ZLIB_LIBS-"-lz"}
-      PY_CHECK_LIB([z], [inflateCopy], [AC_DEFINE([HAVE_ZLIB_COPY], [1])])
+      ZLIB_LIBS=${ZLIB_LIBS-"-l$zlib_libname"}
+      PY_CHECK_LIB([$zlib_libname], [inflateCopy], [AC_DEFINE([HAVE_ZLIB_COPY], [1])])
     ])
   ])
 ])
+])
+
+AS_VAR_IF([with_zlib], [zlib-ng], [AS_VAR_IF([have_zlib], [yes], [
+  WITH_SAVE_ENV([
+    CPPFLAGS="$CPPFLAGS $ZLIB_CFLAGS"
+    AC_CHECK_DECL([ZLIBNG_VERSION], [],
+      [AC_MSG_ERROR([--with-zlib=zlib-ng: the detected zlib library is not zlib-ng])],
+      [@%:@include <zlib.h>])
+  ])
+])])
+
+AS_CASE([$with_zlib],
+  [auto|no], [],
+  [AS_VAR_IF([have_zlib], [no],
+    [AC_MSG_ERROR([--with-zlib=$with_zlib requested but $zlib_name was not found])])])
 
 dnl binascii can use zlib for optimized crc32.
 AS_VAR_IF([have_zlib], [yes], [
@@ -5734,22 +5773,50 @@ AS_VAR_IF([have_zlib], [yes], [
   BINASCII_LIBS="$ZLIB_LIBS"
 ])
 
+AC_MSG_CHECKING([for --with-bzip2])
+AC_ARG_WITH(
+  [bzip2],
+  [AS_HELP_STRING([--with(out)-bzip2@<:@=bzip2|bzip2-rs|no@:>@],
+                  [select the bzip2 implementation to link against, or disable
+                   bzip2 support (default: auto)])],
+  [AS_CASE([$with_bzip2],
+     [yes|auto], [with_bzip2=auto],
+     [bzip2|bzip2-rs|no], [],
+     [AC_MSG_ERROR([proper usage is --with(out)-bzip2@<:@=bzip2|bzip2-rs|no@:>@])])],
+  [with_bzip2=auto])
+AC_MSG_RESULT([$with_bzip2])
+
 dnl detect bzip2 from Emscripten emport
-PY_CHECK_EMSCRIPTEN_PORT([BZIP2], [-sUSE_BZIP2])
+AS_CASE([$with_bzip2], [auto|bzip2], [PY_CHECK_EMSCRIPTEN_PORT([BZIP2], [-sUSE_BZIP2])])
 
-PKG_CHECK_MODULES([BZIP2], [bzip2], [have_bzip2=yes], [
+AS_VAR_IF([with_bzip2], [bzip2-rs], [
+  AS_VAR_SET([bzip2_name], ["libbz2_rs"])
+  AS_VAR_SET([bzip2_libname], ["bz2_rs"])
+], [
+  AS_VAR_SET([bzip2_name], ["bzip2"])
+  AS_VAR_SET([bzip2_libname], ["bz2"])
+])
+
+AS_VAR_IF([with_bzip2], [no], [have_bzip2=no], [
+PKG_CHECK_MODULES([BZIP2], [$bzip2_name], [have_bzip2=yes], [
   WITH_SAVE_ENV([
     CPPFLAGS="$CPPFLAGS $BZIP2_CFLAGS"
     LIBS="$LIBS $BZIP2_LIBS"
     AC_CHECK_HEADERS([bzlib.h], [
-      AC_CHECK_LIB([bz2], [BZ2_bzCompress], [have_bzip2=yes], [have_bzip2=no])
+      AC_CHECK_LIB([$bzip2_libname], [BZ2_bzCompress], [have_bzip2=yes], [have_bzip2=no])
     ], [have_bzip2=no])
     AS_VAR_IF([have_bzip2], [yes], [
       BZIP2_CFLAGS=${BZIP2_CFLAGS-""}
-      BZIP2_LIBS=${BZIP2_LIBS-"-lbz2"}
+      BZIP2_LIBS=${BZIP2_LIBS-"-l$bzip2_libname"}
     ])
   ])
 ])
+])
+
+AS_CASE([$with_bzip2],
+  [auto|no], [],
+  [AS_VAR_IF([have_bzip2], [no],
+    [AC_MSG_ERROR([--with-bzip2=$with_bzip2 requested but $bzip2_name was not found])])])
 
 PKG_CHECK_MODULES([LIBLZMA], [liblzma], [have_liblzma=yes], [
   WITH_SAVE_ENV([

_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3//lists/python-checkins.python.org
Member address: [email protected]
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.