From 51044d203a8bab081284a88bf23a25de1fba5d32 Mon Sep 17 00:00:00 2001 From: Doron Behar Date: Wed, 19 Aug 2026 17:49:33 +0300 Subject: [PATCH 1/2] zlib: remove not needed anymore lld linker workaround Tested that with this change the packages `pkgsCross.x86_64-{freebsd,openbsd}.zlib` build from an `x86_64-linux` build platform, and that their hashes actually are changed due to this. --- pkgs/development/libraries/zlib/default.nix | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/pkgs/development/libraries/zlib/default.nix b/pkgs/development/libraries/zlib/default.nix index a400e4b60c63c..2db92fe529203 100644 --- a/pkgs/development/libraries/zlib/default.nix +++ b/pkgs/development/libraries/zlib/default.nix @@ -108,20 +108,13 @@ stdenv.mkDerivation (finalAttrs: { ln -s zlib1.dll $out/bin/libz.dll ''; - env = - lib.optionalAttrs (!stdenv.hostPlatform.isDarwin) { - # As zlib takes part in the stdenv building, we don't want references - # to the bootstrap-tools libgcc (as uses to happen on arm/mips) - NIX_CFLAGS_COMPILE = toString ( - [ "-static-libgcc" ] ++ lib.optional stdenv.hostPlatform.isCygwin "-DHAVE_UNISTD_H" - ); - } - // lib.optionalAttrs (stdenv.hostPlatform.linker == "lld") { - # lld 16 enables --no-undefined-version by default - # This makes configure think it can't build dynamic libraries - # this may be removed when a version is packaged with https://github.com/madler/zlib/issues/960 fixed - NIX_LDFLAGS = "--undefined-version"; - }; + env = lib.optionalAttrs (!stdenv.hostPlatform.isDarwin) { + # As zlib takes part in the stdenv building, we don't want references + # to the bootstrap-tools libgcc (as uses to happen on arm/mips) + NIX_CFLAGS_COMPILE = toString ( + [ "-static-libgcc" ] ++ lib.optional stdenv.hostPlatform.isCygwin "-DHAVE_UNISTD_H" + ); + }; # We don't strip on static cross-compilation because of reports that native # stripping corrupted the target library; see commit 12e960f5 for the report. From 785ec6b49ad9b9448579828e32d46a8e0289c0c7 Mon Sep 17 00:00:00 2001 From: seth Date: Fri, 20 Dec 2024 15:00:03 -0500 Subject: [PATCH 2/2] zlib: use default configure script on windows This avoids the pitfalls of win32/Makefile.gcc (which prevents building on compilers other than gcc without patching and has non-standard installation behavior) and fixes cross compilation for ucrtAarch64 Putting the DLL's in `$out/bin` was given the approval of: John Ericson --- pkgs/development/libraries/zlib/default.nix | 20 +++---------------- .../libraries/zlib/mingw-shared.patch | 13 ++++++++++++ 2 files changed, 16 insertions(+), 17 deletions(-) create mode 100644 pkgs/development/libraries/zlib/mingw-shared.patch diff --git a/pkgs/development/libraries/zlib/default.nix b/pkgs/development/libraries/zlib/default.nix index 2db92fe529203..6d985093d9d35 100644 --- a/pkgs/development/libraries/zlib/default.nix +++ b/pkgs/development/libraries/zlib/default.nix @@ -49,6 +49,8 @@ stdenv.mkDerivation (finalAttrs: { # https://github.com/madler/zlib/pull/1171 patches = [ ./export-variable.patch + # https://github.com/madler/zlib/pull/1296 + ./mingw-shared.patch ]; postPatch = '' @@ -69,15 +71,13 @@ stdenv.mkDerivation (finalAttrs: { setOutputFlags = false; outputDoc = "dev"; # single tiny man3 page - dontConfigure = (stdenv.hostPlatform.isMinGW || stdenv.hostPlatform.isCygwin); - preConfigure = lib.optionalString (stdenv.hostPlatform != stdenv.buildPlatform) '' export CHOST=${stdenv.hostPlatform.config} ''; configureFlags = [ "--includedir=${placeholder "dev"}/include" - "--sharedlibdir=${placeholder "out"}/lib" + "--sharedlibdir=${placeholder "out"}/${if stdenv.hostPlatform.isWindows then "bin" else "lib"}" "--libdir=${placeholder (if splitStaticOutput then "static" else "out")}/lib" # See comment near splitStaticOutput argument (lib.enableFeature shared "shared") @@ -101,11 +101,6 @@ stdenv.mkDerivation (finalAttrs: { for file in $out/lib/*.so* $out/lib/*.dylib* ; do ${stdenv.cc.bintools.targetPrefix}install_name_tool -id "$file" $file done - '' - # Non-typical naming confuses libtool which then refuses to use zlib's DLL - # in some cases, e.g. when compiling libpng. - + lib.optionalString (stdenv.hostPlatform.isMinGW && shared) '' - ln -s zlib1.dll $out/bin/libz.dll ''; env = lib.optionalAttrs (!stdenv.hostPlatform.isDarwin) { @@ -134,18 +129,9 @@ stdenv.mkDerivation (finalAttrs: { "PREFIX=${stdenv.cc.targetPrefix}" "pkgconfigdir=${placeholder "dev"}/share/pkgconfig" ] - ++ lib.optionals (stdenv.hostPlatform.isMinGW || stdenv.hostPlatform.isCygwin) [ - "-f" - "win32/Makefile.gcc" - ] ++ lib.optionals stdenv.hostPlatform.isCygwin [ "SHAREDLIB=cygz.dll" "IMPLIB=libz.dll.a" - ] - ++ lib.optionals shared [ - # Note that as of writing (zlib 1.2.11), this flag only has an effect - # for Windows as it is specific to `win32/Makefile.gcc`. - "SHARED_MODE=1" ]; passthru.tests = { diff --git a/pkgs/development/libraries/zlib/mingw-shared.patch b/pkgs/development/libraries/zlib/mingw-shared.patch new file mode 100644 index 0000000000000..9f08476a3a263 --- /dev/null +++ b/pkgs/development/libraries/zlib/mingw-shared.patch @@ -0,0 +1,13 @@ +diff --git a/configure b/configure +index c55098a..07f7c08 100755 +--- a/configure ++++ b/configure +@@ -243,6 +243,8 @@ if test "$gcc" -eq 1 && ($cc -c $test.c) >> configure.log 2>&1; then + echo "If this doesn't work for you, try win32/Makefile.gcc." | tee -a configure.log + LDSHARED=${LDSHARED-"$cc -shared"} + LDSHAREDLIBC="" ++ shared_ext='.dll' ++ SHAREDLIB='libz.dll' + EXE='.exe' ;; + QNX*) # This is for QNX6. I suppose that the QNX rule below is for QNX2,QNX4 + # (alain.bonnefoy@icbt.com)