diff mbox series

package/python3: really disable zlib

Message ID 20231011163408.32325-1-romain.naour@gmail.com
State New
Headers show
Series package/python3: really disable zlib | expand

Commit Message

Romain Naour Oct. 11, 2023, 4:34 p.m. UTC
The Bootlin toolchain 2023.08-1 provide (by mistake [1]) libz.so in its
sysroot and break several python test in the gitlab-ci [2] since the
python package detect zlib while the zlib package is not build. So
there is no zlib library installed to the target rootfs.

The issue [1] has been fixed in Buildroot [3] but the Bootlin toolchain
needs to be rebuild with the fix to remove libz.so from the sysroot.

With Bootlin toolchain 2023.08-1, zlib is detected by pkg-config and
enable zlib support in binascii python module (-DUSE_ZLIB_CRC32) even
if the zlib module is disabled.
If binascii python module is used at runtime, it fail to load zlib:

  Failed to run: python sample_python_pyyaml_enc.py
  output was:
    Traceback (most recent call last):
      File "/root/sample_python_pyyaml_enc.py", line 1, in <module>
        import yaml
      File "/usr/lib/python3.11/site-packages/yaml/__init__.py", line 8, in <module>
      File "/usr/lib/python3.11/site-packages/yaml/loader.py", line 8, in <module>
      File "/usr/lib/python3.11/site-packages/yaml/constructor.py", line 14, in <module>
      File "/usr/lib/python3.11/base64.py", line 11, in <module>
    ImportError: libz.so.1: cannot open shared object file: No such file or directory

This is also a reproducible build issue since python doesn't provide
the same features if zlib is buid before or after the python build.

Fix this issue by disabling zlib support along with the zlib python
module (--disable-zlib).

Fixes:
https://gitlab.com/buildroot.org/buildroot/-/jobs/5201302864 (TestPythonPy3Pyyaml)
https://gitlab.com/buildroot.org/buildroot/-/jobs/5201302828 (TestPythonPy3Mako)
(and many other)

[1] 3341ceb1e58536cf43a4c000e4bb3cdbff3f6de5 (package/gdb: zlib is mandatory, not optional)
[2] https://gitlab.com/buildroot.org/buildroot/-/jobs/5201302864
[3] 8ce33fed49aea319da556eab388211a705afe7d0 (package/gdb: gdbserver does not need zlib)

Cc; Asaf Kahlon <asafka7@gmail.com>
Cc: James Hilliard <james.hilliard1@gmail.com>
Cc: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
Cc: Yegor Yefremov <yegorslists@googlemail.com>
Signed-off-by: Romain Naour <romain.naour@gmail.com>
---
runtime tested:
  TestPythonPy3Flask.test_run (with zlib & zlib python module enabled)
  TestPythonPy3Pyyaml (without zlib)
---
 ...032-configure.ac-really-disable-zlib.patch | 96 +++++++++++++++++++
 1 file changed, 96 insertions(+)
 create mode 100644 package/python3/0032-configure.ac-really-disable-zlib.patch
diff mbox series

Patch

diff --git a/package/python3/0032-configure.ac-really-disable-zlib.patch b/package/python3/0032-configure.ac-really-disable-zlib.patch
new file mode 100644
index 0000000000..6d9fb2c3f1
--- /dev/null
+++ b/package/python3/0032-configure.ac-really-disable-zlib.patch
@@ -0,0 +1,96 @@ 
+From 9b5a79f7b5bc5ccfa8f3909ee6d3a94b2efb617d Mon Sep 17 00:00:00 2001
+From: Romain Naour <romain.naour@gmail.com>
+Date: Wed, 11 Oct 2023 15:33:54 +0200
+Subject: [PATCH] configure.ac: really disable zlib
+
+Commit "Add options to disable zlib, bzip2 and xz modules" allowed
+to disable the python zlib module but the configure script still
+check for zlib library using pkg-config even if --disable-zlib is
+provided.
+
+If zlib is detected by pkg-config it enable zlib support in binascii
+python module (-DUSE_ZLIB_CRC32) even if the zlib module is disabled.
+This is also a reproducible build issue since python doesn't provide
+the same features if zlib is buid before or after the python build.
+
+Fix this issue by disabling zlib support along with the zlib python
+module (--disable-zlib).
+
+Upstream: Not applicable
+(patching a BR patch 0025-Add-options-to-disable-zlib-bzip2-and-xz-modules.patch)
+
+Signed-off-by: Romain Naour <romain.naour@gmail.com>
+---
+ configure.ac | 45 ++++++++++++++++++++++++---------------------
+ 1 file changed, 24 insertions(+), 21 deletions(-)
+
+diff --git a/configure.ac b/configure.ac
+index 3f5e7400c6..fa7cdfa0df 100644
+--- a/configure.ac
++++ b/configure.ac
+@@ -4288,7 +4288,8 @@ AC_ARG_ENABLE(zlib,
+ 	AS_HELP_STRING([--disable-zlib], [disable zlib]),
+ 	[ if test "$enableval" = "no"; then
+ 	     DISABLED_EXTENSIONS="${DISABLED_EXTENSIONS} zlib"
+-	  fi])
++	     enable_zlib=${enableval}
++	  fi], [enable_zlib=auto])
+ 
+ AC_ARG_ENABLE(xz,
+ 	AS_HELP_STRING([--disable-xz], [disable xz]),
+@@ -4899,30 +4900,32 @@ if test "$ac_cv_have_lchflags" = yes ; then
+   AC_DEFINE(HAVE_LCHFLAGS, 1, [Define to 1 if you have the 'lchflags' function.])
+ fi
+ 
+-dnl Check for compression libraries
+-AH_TEMPLATE([HAVE_ZLIB_COPY], [Define if the zlib library has inflateCopy])
++if test "x$enable_zlib" != xno; then
++  dnl Check for compression libraries
++  AH_TEMPLATE([HAVE_ZLIB_COPY], [Define if the zlib library has inflateCopy])
+ 
+-dnl detect zlib from Emscripten emport
+-PY_CHECK_EMSCRIPTEN_PORT([ZLIB], [-sUSE_ZLIB])
++  dnl detect zlib from Emscripten emport
++  PY_CHECK_EMSCRIPTEN_PORT([ZLIB], [-sUSE_ZLIB])
+ 
+-PKG_CHECK_MODULES([ZLIB], [zlib >= 1.2.0], [
+-  have_zlib=yes
+-  dnl zlib 1.2.0 (2003) added inflateCopy
+-  AC_DEFINE([HAVE_ZLIB_COPY], [1])
+-], [
+-  WITH_SAVE_ENV([
+-    CPPFLAGS="$CPPFLAGS $ZLIB_CFLAGS"
+-    LDFLAGS="$LDFLAGS $ZLIB_LIBS"
+-    AC_CHECK_HEADERS([zlib.h], [
+-      PY_CHECK_LIB([z], [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])])
++  PKG_CHECK_MODULES([ZLIB], [zlib >= 1.2.0], [
++    have_zlib=yes
++    dnl zlib 1.2.0 (2003) added inflateCopy
++    AC_DEFINE([HAVE_ZLIB_COPY], [1])
++  ], [
++    WITH_SAVE_ENV([
++      CPPFLAGS="$CPPFLAGS $ZLIB_CFLAGS"
++      LDFLAGS="$LDFLAGS $ZLIB_LIBS"
++      AC_CHECK_HEADERS([zlib.h], [
++        PY_CHECK_LIB([z], [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])])
++      ])
+     ])
+   ])
+-])
++fi
+ 
+ dnl binascii can use zlib for optimized crc32.
+ AS_VAR_IF([have_zlib], [yes], [
+-- 
+2.41.0
+