Description
Currently, pkgconfig-depends
imposes a hard requirement and will fail if the file is not found or pkg-config
doesn't exist. This is not portable, there are a few reasons:
- some distros incorrectly add
.pc
files downstream, causing cross-distro breakage (especially debian) - existence of a
.pc
file may depend on the version of the library - it's not clear how well it works on non-linux platforms, although these are generally supported
In general, I believe users don't really care how cabal figures out the correct library destination etc. Of course pkg-config delivers better results than assuming e.g. FHS, but the latter still works for a majority of use cases, when pkg-config is absent.
As a result, I've come up with a template Setup.hs that sort of makes this optional. However, I feel this is rather fragile. @dcoutts reminded us that cabal-install feeds the pkg-config database into the solver and so should be able to use that information for resolution. A suggested way of triggering this was:
flag use-pkgconfig-foo
description: get foo lib config from pkg-config
manual: False
default: True
library
[...]
if flag(use-pkgconfig-foo)
pkgconfig-depends: libfoo
else
includes: foo.h
extra-libraries: foo
This, however, doesn't work, because Cabal tries to find pkg-config deps during configure stage, before the solver:
cabal/Cabal/Distribution/Simple/Configure.hs
Lines 1617 to 1641 in 867e45e
I tried commenting this out and indeed, cabal doesn't fail prematurely anymore. However, it doesn't seem to pick the alternative resolution (as in: it never disables use-pkgconfig-foo
) and will fail at linking stage.
The pkg-config database is fed during the validation phase:
- https://github.com/haskell/cabal/blob/master/cabal-install/Distribution/Solver/Modular/Solver.hs#L133
- https://github.com/haskell/cabal/blob/master/cabal-install/Distribution/Solver/Modular/Validate.hs#L562
Any pointers would be appreciated.