Cabal 3.8 checks for literally all pkg-config packages in the system
Describe the bug
When the .cabal package being built contains pkgconfig-depends, the cabal-install tool checks for every pkg-config package installed. If any of these packages are broken for some reason the build fails even if the Cabal package doesn't use it.
To Reproduce
Find out which directories are searched by pkg-config:
% pkg-config --variable pc_path pkg-config /usr/local/libdata/pkgconfig:/usr/libdata/pkgconfig:/usr/local/share/pkgconfig
Create an invalid aaa.pc package description for pkg-config in one of those dirs:
Name: aaa
Version: 123
Description: asdasd
Requires: asdasd
Trying to get an information for this package will result in error:
% pkg-config --modversion aaa Package asdasd was not found in the pkg-config search path. Perhaps you should add the directory containing `asdasd.pc' to the PKG_CONFIG_PATH environment variable Package 'asdasd', required by 'aaa', not found
Now try to build any Cabal package with pkgconfig-depends:
cabal unpack gi-atk cd gi-atk-2.0.24 cabal build --dry-run -v2
It fails claiming that gi-atk.pc wasn't found even if it is installed:
Error: cabal: Could not resolve dependencies: [__0] next goal: gi-atk (user goal) [__0] rejecting: gi-atk-2.0.24 (conflict: pkg-config package atk>=2.0 && <3, not found in the pkg-config database)
Expected behavior
Package configuration should be successful since the package isn't using aaa.
System information
- FreeBSD 14-CURRENT
cabal3.8.1.0ghc9.2.4
Additional context https://github.com/haskell/cabal/issues/8446
@arrowd wrote
Create an invalid
aaa.pcpackage description forpkg-configin one of those dirs:
Does this make pkg-config --list-all crash? This would point to:
- https://gitlab.freedesktop.org/pkg-config/pkg-config/-/issues/36
@andreasabel Nope, this is a different problem:
# pkg-config --list-all | grep aaa
aaa aaa - asdasd
# pkg-config --modversion aaa
Package asdasd was not found in the pkg-config search path.
Perhaps you should add the directory containing `asdasd.pc'
to the PKG_CONFIG_PATH environment variable
Package 'asdasd', required by 'aaa', not found
pkg-config in this case works fine, the issue is on the Cabal side.
Oh, maybe this has something to do with the fact that FreeBSD uses pkgconf fork, not the original pkg-config.
I think this is due to #8455? Try pkg-config --libs --static YOUR_DEP. --list-all works fine here as well.
@sternenseemann wrote:
I think this is due to #8455? Try
pkg-config --libs --static YOUR_DEP.--list-allworks fine here as well.
In my case not. The --libs --static query works fine, see: https://github.com/andreasabel/text-icu/actions/runs/3217381491/jobs/5260284886
So, upstream came back with an analysis: https://github.com/Homebrew/homebrew-core/issues/112785
Not that the details matter, but the upshot is that one broken package configuration breaks pkg-config --list-all and consequently cabal-3.8.1.0.
So, install imagemagick or highway and suddently your haskell packages fail to build with cabal. Nightmare scenario? Yes!
We just hit this at work. It's quite hard to diagnose, since it manifests a bit obscurely.
If cabal uses pkg-config --list-all and that command can fail, we can do with a better error message. Currently it gives an error message that looks like this, which is not helpful:
Warning: Requested index-state 2022-10-19T00:00:00Z is newer than
'cardano-haskell-packages'! Falling back to older state
(2022-10-17T00:00:00Z).
Resolving dependencies...
Error: cabal: Could not resolve dependencies:
[__0] trying: cardano-api-1.36.0 (user goal)
[__1] next goal: cardano-crypto-class (dependency of cardano-api)
[__1] rejecting: cardano-crypto-class-2.0.0.1 (constraint from project config
/Users/jky/wrk/iohk/cardano-node/cabal.project requires <2.0.0.1)
[__1] rejecting: cardano-crypto-class-2.0.0 (conflict: pkg-config package
libsodium-any, not found in the pkg-config database)
[__1] fail (backjumping, conflict set: cardano-api, cardano-crypto-class)
After searching the rest of the dependency tree exhaustively, these were the
goals I've had most trouble fulfilling: cardano-api, cardano-crypto-class
Perhaps if the invocation of pkg-config --list-all fails, then cabal should say that this failed command has failed and point to an issue that describes how to diagnose the problem.
Additionally the problem was reproduced in with cabal-3.8.1.0 and ghc-8.10.7.
For the same project, cabal-3.6.2.0 and ghc-8.10.7 worked fine.
@arrowd reports https://github.com/haskell/cabal/pull/8496 fixes this ticket, but it's likely other real life scenarios are not fixed, so please kindly test and let us know.