From c407e3cbbaaba05db64c8e1ec929c75cfa4eba50 Mon Sep 17 00:00:00 2001 From: Randy Eckenrode Date: Tue, 11 Jul 2023 10:33:43 -0600 Subject: zip: fix build with clang 16 Fix implicit declarations of `memset` and `open/closedir` resulting in incorrect feature detection and conflicts with libc headers. --- pkgs/tools/archivers/zip/default.nix | 11 +++++++++-- .../archivers/zip/fix-implicit-declarations.patch | 21 +++++++++++++++++++++ pkgs/tools/archivers/zip/fix-memset-detection.patch | 15 +++++++++++++++ 3 files changed, 45 insertions(+), 2 deletions(-) create mode 100644 pkgs/tools/archivers/zip/fix-implicit-declarations.patch create mode 100644 pkgs/tools/archivers/zip/fix-memset-detection.patch (limited to 'pkgs/tools') diff --git a/pkgs/tools/archivers/zip/default.nix b/pkgs/tools/archivers/zip/default.nix index 82329537251e..75a7c81f3276 100644 --- a/pkgs/tools/archivers/zip/default.nix +++ b/pkgs/tools/archivers/zip/default.nix @@ -13,7 +13,7 @@ stdenv.mkDerivation rec { ]; sha256 = "0sb3h3067pzf3a7mlxn1hikpcjrsvycjcnj9hl9b1c3ykcgvps7h"; }; - patchPhase = '' + prePatch = '' substituteInPlace unix/Makefile --replace 'CC = cc' "" ''; @@ -26,7 +26,14 @@ stdenv.mkDerivation rec { "INSTALL=cp" ]; - patches = lib.optionals (enableNLS && !stdenv.isCygwin) [ ./natspec-gentoo.patch.bz2 ]; + patches = [ + # Trying to use `memset` without declaring it is flagged as an error with clang 16, causing + # the `configure` script to incorrectly define `ZMEM`. That causes the build to fail due to + # incompatible redeclarations of `memset`, `memcpy`, and `memcmp` in `zip.h`. + ./fix-memset-detection.patch + # Implicit declaration of `closedir` and `opendir` cause dirent detection to fail with clang 16. + ./fix-implicit-declarations.patch + ] ++ lib.optionals (enableNLS && !stdenv.isCygwin) [ ./natspec-gentoo.patch.bz2 ]; buildInputs = lib.optional enableNLS libnatspec ++ lib.optional stdenv.isCygwin libiconv; diff --git a/pkgs/tools/archivers/zip/fix-implicit-declarations.patch b/pkgs/tools/archivers/zip/fix-implicit-declarations.patch new file mode 100644 index 000000000000..df19bf1722f9 --- /dev/null +++ b/pkgs/tools/archivers/zip/fix-implicit-declarations.patch @@ -0,0 +1,21 @@ +--- a/unix/configure 2009-04-16 15:25:12.000000000 -0400 ++++ b/unix/configure 2023-05-30 15:18:33.670321348 -0400 +@@ -408,7 +408,7 @@ + echo Check for errno declaration + cat > conftest.c << _EOF_ + #include +-main() ++int main() + { + errno = 0; + return 0; +@@ -419,6 +419,8 @@ + + echo Check for directory libraries + cat > conftest.c << _EOF_ ++#include ++#include + int main() { return closedir(opendir(".")); } + _EOF_ + + diff --git a/pkgs/tools/archivers/zip/fix-memset-detection.patch b/pkgs/tools/archivers/zip/fix-memset-detection.patch new file mode 100644 index 000000000000..55bda33a2573 --- /dev/null +++ b/pkgs/tools/archivers/zip/fix-memset-detection.patch @@ -0,0 +1,15 @@ +diff -ur a/unix/configure b/unix/configure +--- a/unix/configure 2008-06-19 21:32:20.000000000 -0600 ++++ b/unix/configure 2023-07-11 10:02:57.809867694 -0600 +@@ -519,7 +519,10 @@ + + + echo Check for memset +-echo "int main(){ char k; memset(&k,0,0); return 0; }" > conftest.c ++cat > conftest.c << _EOF_ ++#include ++int main(){ char k; memset(&k,0,0); return 0; } ++_EOF_ + $CC -o conftest conftest.c >/dev/null 2>/dev/null + [ $? -ne 0 ] && CFLAGS="${CFLAGS} -DZMEM" + -- cgit 1.4.1