Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make pkgconfig-depends usable #7448

Closed
bgamari opened this issue Jun 19, 2021 · 3 comments · Fixed by #7621
Closed

Make pkgconfig-depends usable #7448

bgamari opened this issue Jun 19, 2021 · 3 comments · Fixed by #7621
Labels
re: pkg-config Concerning pkg-config and pkgconfig-depends constraints type: discussion

Comments

@bgamari
Copy link
Contributor

bgamari commented Jun 19, 2021

Describe the bug
Cabal has for a long time supported discovering native library dependencies through pkgconfig-depends. This is extremely useful as:

  • it can be used by some distributions to transparently provide native dependencies to cabal-install (e.g. see nix-pkgconfig)
  • it makes Cabal packages more robust against non-traditional packaging decisions
  • it eliminates the need for Cabal to guess whether the target platform has a particular library

However, due to the fact that pkg-config is not available by default on some platforms, libraries tend to either not use pkgconfig-depends (e.g. see regex-posix) or guard it behind a default-off flag (e.g. see zlib). This severely cripples the usefulness of the mechanism.

Even worse, the tendency for packages to assume library non-availability on Windows can blow up catastrophically in some cases. This was the case in GHC #19945 where an ABI mismatch triggered by the assumption that Windows environments do not offer a POSIX regex implementation caused an innocuous-looking program to segfault, requiring many hours of debugging.

Proposed design

Users avoid using pkgconfig-depends by default because it can cause builds to fail when pkg-config is not available. I suggest one of the following (roughly in order of decreasing desirability):

  • cabal-install learn to backtrack if a pkg-config probe fails due to the executable not being available
  • cabal-install implement support for setting/clearing the pkgconfig flag on its own depending upon whether the pkg-config executable is available, sanctioning the current flag-based convention
  • cabal-install assume that the pkgconfig-depends are available in the event that pkg-config is not available
@phadej
Copy link
Collaborator

phadej commented Jun 19, 2021

There are related issues:

If these are implemented, then both first and second @bgamari suggestions will be possible.

@gbaz
Copy link
Collaborator

gbaz commented Sep 4, 2021

I think I can have a go at option 1. Would appreciate someone pointing me to the simplest possible package that uses pkgconfig-depends they can think of so I can use it as a test case :-)

(And ideally this would have a cabal file example of how to build it in the no pkg-config case too!)

@phadej
Copy link
Collaborator

phadej commented Sep 4, 2021

About any, e.g. https://hackage.haskell.org/package/zlib-0.6.2.3/zlib.cabal has manual flag to select pkg-config, while on my system:

% pkg-config --list-all|grep zlib
zlib                                zlib - zlib compression library

(I forgot to install zlib1g-dev in CI environments so many times, I remember that by heart). lzma is another.

https://hackage.haskell.org/package/HsOpenSSL is more complicated, where you start to wish pkg-config told things to avoid:

    if os(darwin) && flag(homebrew-openssl)
        Include-Dirs: /usr/local/opt/openssl/include
        Extra-Lib-Dirs: /usr/local/opt/openssl/lib

    if os(darwin) && flag(macports-openssl)
        Include-Dirs: /opt/local/include
        Extra-Lib-Dirs: /opt/local/lib

@mergify mergify bot closed this as completed in #7621 Sep 10, 2021
@andreasabel andreasabel added the re: pkg-config Concerning pkg-config and pkgconfig-depends constraints label May 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
re: pkg-config Concerning pkg-config and pkgconfig-depends constraints type: discussion
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants