From f3d9b73059fcd804d4f4718cd28831f119d87acc Mon Sep 17 00:00:00 2001 From: seth Date: Fri, 20 Dec 2024 15:00:03 -0500 Subject: [PATCH] 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 --- pkgs/development/libraries/zlib/default.nix | 15 +++++++-------- .../development/libraries/zlib/mingw-shared.patch | 13 +++++++++++++ 2 files changed, 20 insertions(+), 8 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 e67d912246788..85bdd2d326bd9 100644 --- a/pkgs/development/libraries/zlib/default.nix +++ b/pkgs/development/libraries/zlib/default.nix @@ -43,6 +43,10 @@ stdenv.mkDerivation (finalAttrs: { hash = "sha256-mpOyt9/ax3zrpaVYpYDnRmfdb+3kWFuR7vtg8Dty3yM="; }; + patches = [ + ./mingw-shared.patch + ]; + postPatch = lib.optionalString stdenv.hostPlatform.isDarwin '' substituteInPlace configure \ --replace '/usr/bin/libtool' '${stdenv.cc.targetPrefix}ar' \ @@ -58,8 +62,6 @@ stdenv.mkDerivation (finalAttrs: { setOutputFlags = false; outputDoc = "dev"; # single tiny man3 page - dontConfigure = stdenv.hostPlatform.isMinGW; - preConfigure = lib.optionalString (stdenv.hostPlatform != stdenv.buildPlatform) '' export CHOST=${stdenv.hostPlatform.config} ''; @@ -104,7 +106,8 @@ stdenv.mkDerivation (finalAttrs: { # 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 + mkdir -p $out/bin + mv $out/lib/*.dll* $out/bin ''; env = @@ -113,7 +116,7 @@ stdenv.mkDerivation (finalAttrs: { # to the bootstrap-tools libgcc (as uses to happen on arm/mips) NIX_CFLAGS_COMPILE = "-static-libgcc"; } - // lib.optionalAttrs (stdenv.hostPlatform.linker == "lld") { + // lib.optionalAttrs (stdenv.hostPlatform.linker == "lld" && !stdenv.hostPlatform.isWindows) { # 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 @@ -138,10 +141,6 @@ stdenv.mkDerivation (finalAttrs: { [ "PREFIX=${stdenv.cc.targetPrefix}" ] - ++ lib.optionals stdenv.hostPlatform.isMinGW [ - "-f" - "win32/Makefile.gcc" - ] ++ 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`. 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)