Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 10 additions & 31 deletions pkgs/development/libraries/zlib/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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 = ''
Expand All @@ -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"}"
Comment thread
doronbehar marked this conversation as resolved.
"--libdir=${placeholder (if splitStaticOutput then "static" else "out")}/lib"
# See comment near splitStaticOutput argument
(lib.enableFeature shared "shared")
Expand All @@ -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.
Comment thread
doronbehar marked this conversation as resolved.
+ 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.
Expand All @@ -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"
Comment thread
doronbehar marked this conversation as resolved.
];

passthru.tests = {
Expand Down
13 changes: 13 additions & 0 deletions pkgs/development/libraries/zlib/mingw-shared.patch
Original file line number Diff line number Diff line change
@@ -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)
Loading