diff --git a/pkgs/development/libraries/zlib/default.nix b/pkgs/development/libraries/zlib/default.nix index a400e4b60c63c..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,27 +101,15 @@ 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) { - # 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. @@ -141,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)