From 6ce811487ca46cbe242786246932f6b2ab6424a9 Mon Sep 17 00:00:00 2001 From: Bodigrim Date: Sun, 21 Apr 2024 19:36:35 +0100 Subject: [PATCH] Use zlib-clib on Windows, unless pkg-config is available --- zlib/zlib.cabal | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/zlib/zlib.cabal b/zlib/zlib.cabal index 4a4f38a..914ea0f 100644 --- a/zlib/zlib.cabal +++ b/zlib/zlib.cabal @@ -60,13 +60,14 @@ flag non-blocking-ffi flag pkg-config default: True manual: False - description: Use @pkg-config(1)@ to locate foreign @zlib@ library. + description: Use @pkg-config@ executable to locate foreign @zlib@ library. flag bundled-c-zlib default: False manual: True - description: Use the bundled zlib C sources. - For GHCJS and WASM this is the default. + description: Use @zlib-clib@ package with C sources instead of a system library. + C sources are used for GHCJS and WASM unconditionally + and on Windows unless @pkg-config@ flag is on. library exposed-modules: Codec.Compression.GZip, @@ -99,15 +100,21 @@ library if flag(non-blocking-ffi) cpp-options: -DNON_BLOCKING_FFI - if flag(bundled-c-zlib) || impl(ghcjs) || os(ghcjs) || arch(wasm32) - build-depends: zlib-clib + -- Cross-platform builds (such as JS and WASM) must have access + -- to C sources, so using zlib-clib unconditionally. + -- + -- On Windows zlib is shipped with GHC starting from 7.10 + -- at mingw/lib/libz.a. Yet linking against it proves unreliable: + -- while GHC always links against mingw/lib whatever the PATH, + -- there are no guarantees that zlib1.dll will be in PATH afterwards. + -- Thus resorting to zlib-clib again, unless pkg-config is available. + if flag(bundled-c-zlib) || impl(ghcjs) || os(ghcjs) || arch(wasm32) || (!flag(pkg-config) && os(windows)) + build-depends: zlib-clib < 2 else if flag(pkg-config) -- NB: pkg-config is available on windows as well when using msys2 pkgconfig-depends: zlib else - -- On Windows zlib is shipped with GHC starting from 7.10 - -- at mingw/lib/libz.a extra-libraries: z test-suite tests