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

Cabal 3.8 checks for literally all pkg-config packages in the system #8494

Closed
arrowd opened this issue Sep 26, 2022 · 9 comments · Fixed by #8496
Closed

Cabal 3.8 checks for literally all pkg-config packages in the system #8494

arrowd opened this issue Sep 26, 2022 · 9 comments · Fixed by #8496
Assignees
Labels
attention: needs-backport 3.8 re: pkg-config Concerning pkg-config and pkgconfig-depends constraints regression in 3.8 type: bug
Projects

Comments

@arrowd
Copy link
Collaborator

arrowd commented Sep 26, 2022

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
  • cabal 3.8.1.0
  • ghc 9.2.4

Additional context
#8446

@andreasabel
Copy link
Member

@arrowd wrote

Create an invalid aaa.pc package description for pkg-config in one of those dirs:

Does this make pkg-config --list-all crash? This would point to:

@arrowd
Copy link
Collaborator Author

arrowd commented Oct 7, 2022

@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.

@arrowd
Copy link
Collaborator Author

arrowd commented Oct 7, 2022

Oh, maybe this has something to do with the fact that FreeBSD uses pkgconf fork, not the original pkg-config.

@sternenseemann
Copy link

sternenseemann commented Oct 9, 2022

I think this is due to #8455? Try pkg-config --libs --static YOUR_DEP. --list-all works fine here as well.

@andreasabel
Copy link
Member

@sternenseemann wrote:

I think this is due to #8455? Try pkg-config --libs --static YOUR_DEP. --list-all works 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

@andreasabel
Copy link
Member

So, upstream came back with an analysis: Homebrew/homebrew-core#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!

@michaelpj
Copy link
Collaborator

We just hit this at work. It's quite hard to diagnose, since it manifests a bit obscurely.

@newhoggy
Copy link

newhoggy commented Oct 24, 2022

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.

@Mikolaj
Copy link
Member

Mikolaj commented Oct 24, 2022

@arrowd reports #8496 fixes this ticket, but it's likely other real life scenarios are not fixed, so please kindly test and let us know.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
attention: needs-backport 3.8 re: pkg-config Concerning pkg-config and pkgconfig-depends constraints regression in 3.8 type: bug
Projects
No open projects
Development

Successfully merging a pull request may close this issue.

8 participants