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

Try each pkg-config query separatedly #9134

Merged
merged 2 commits into from
Oct 7, 2023

Conversation

jasagredo
Copy link
Collaborator

@jasagredo jasagredo commented Jul 17, 2023

MinGW's pkg-config returns only one version even if queried for multiple libraries. This PR makes it so that cabal will invoke pkg-config once for each requested library if the result is not of the expected length, therefore supporting these pkg-config implementations, in particular mingw-w64-x86_64-pkgconf (which is also installed by GHCup when bootstrapping MSYS2).

Javier@DESKTOP-JDT20GG MINGW64 ~
$ pkg-config --modversion libcrypto libffi
3.1.1

In the same spirit as rust-lang/pkg-config-rs#92, as we also are not GCC, we also set PKG_CONFIG_ALLOW_SYSTEM_(CFLAGS|LIBS) when calling pkg-config

QA Notes

Building a package that depends on more than one library provided by pkg-config on MinGW should now be able to find the required library.

@Kleidukos
Copy link
Member

@jasagredo Thank you for the initiative! Would you mind adding QA notes and check the boxes in the description? :)

@michaelpj
Copy link
Collaborator

A bit of git blame turns up some previous discussion on the PR that added the individual fallback. It would be good to get this reasoning into the code in comments! #8496 (comment)

@andreabedini
Copy link
Collaborator

Related #8930

@andreabedini andreabedini added the re: pkg-config Concerning pkg-config and pkgconfig-depends constraints label Jul 18, 2023
@jasagredo jasagredo force-pushed the jasagredo/each-pkgconfig-once branch 2 times, most recently from bf9de80 to 4b87276 Compare July 19, 2023 11:23
@jasagredo
Copy link
Collaborator Author

I've modified the logic to fallback to individual query if the length of the returned list doesn't match the length of the query, which is precisely what happens on Windows. On any other flows, the behavior should be the same.

@andreabedini
Copy link
Collaborator

I'm good with this, @michaelpj?

Copy link
Collaborator

@andreabedini andreabedini left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@michaelpj
Copy link
Collaborator

Personally I think the argument for doing the batch query didn't seem that strong, and it seems to regularly cause problems. So I'd be in favour of the original change in this PR, but perhaps it's best to be conservative. Unless @gbaz wants to weigh in?

@fgaz fgaz added the squash+merge me Tell Mergify Bot to squash-merge label Jul 23, 2023
@mergify mergify bot added the merge delay passed Applied (usually by Mergify) when PR approved and received no updates for 2 days label Jul 25, 2023
pkgConfigDbFromList . catMaybes <$> mapM (getIndividualVersion pkgConfig) pkgNames
if exitCode == ExitSuccess && length pkgNames == length pkgList
then (return . pkgConfigDbFromList . zip pkgNames) (lines pkgVersions)
else -- if there's a single broken pc file the above fails, so we fall back into calling it individually
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would help to add the second reason for the fallback to this comment.

@jasagredo
Copy link
Collaborator Author

jasagredo commented Jul 31, 2023

I have not yet confirmed my suspicions, but I think this is due to faulty pkg-configs installed in MSYS2, see this.

In particular:

  • Strawberry perl's pkg-config (included by default in GH runners) does not work as expected at all
  • pkgconf can't interpret C:... paths.
  • mingw-w64-x86_64-pkgconf returns only one version when queried for multiple.
  • mingw-w64-x86_64-pkg-config will work OK if and when we provide PKG_CONFIG_ALLOW_SYSTEM_(CFLAGS|LIBS) env vars

@Mikolaj
Copy link
Member

Mikolaj commented Sep 4, 2023

@jasagredo: how can we help to move this forward?

@Mikolaj Mikolaj removed squash+merge me Tell Mergify Bot to squash-merge merge delay passed Applied (usually by Mergify) when PR approved and received no updates for 2 days labels Sep 4, 2023
@jasagredo
Copy link
Collaborator Author

@jasagredo: how can we help to move this forward?

I think the right way forward is to:

  1. Close this PR

2a. GHCup in Windows checks if pkg-config installed is the appropriate one (see my comment above) and if so, offers the user to add those env vars to .bashrc or equivalent.

2b. Cabal in Windows detects if pkg-config is the appropriate one and if so, sets the env vars when calling it.

I do think that GHCup should fail in Windows if a non-appropriate pkg-config is found, the same way it might fail if gcc is non existent. (I might be wrong, I don't recall if it installs gcc for you if it is not present)

Probably @hasufell has some thoughts on this.

@hasufell
Copy link
Member

I do think that GHCup should fail in Windows if a non-appropriate pkg-config is found

GHCup doesn't track your system tools.

These things are installed by the powershell bootstrap script and only on windows, because of how special the situation is with msys2.

But in general, this is not GHCup's business to take care of your non-Haskell stuff.

I might be wrong, I don't recall if it installs gcc for you if it is not present

It does not.

@jasagredo
Copy link
Collaborator Author

Sorry @hasufell it seems I was confused with the scope of the responsibilities for GHCup. However, in the case of GHCup bootstrapping MSYS2, would it make sense to install an appropriate pkg-config there?

In any case, if we cannot rely on an appropriate pkg-config being installed, we can use this PR to query for each pkg individually when the list of results is not the expected length, but also we could make cabal set PKG_CONFIG_ALLOW_SYSTEM_CFLAGS=1 and PKG_CONFIG_ALLOW_SYSTEM_LIBS=1 when calling pkg-config. This should be innocuous on systems without this problem.

TL;DR: I propose setting those 2 env vars when cabal calls pkg-config as a defensive measure, on top of what this PR already does.

What do you think? @Mikolaj

@hasufell
Copy link
Member

However, in the case of GHCup bootstrapping MSYS2, would it make sense to install an appropriate pkg-config there?

We currently install mingw-w64-x86_64-pkgconf: https://github.com/haskell/ghcup-hs/blob/371eda962f713fe483616310291004a82e5b029d/scripts/bootstrap/bootstrap-haskell.ps1#L471

The end user might however uninstall it or install arbitrary other ones. This is just a convenience feature in the bootstrapper. We can't control what pacman has installed. Cabal should be maximally compatible here.

@jasagredo
Copy link
Collaborator Author

@hasufell alright, so this PR will make it work in presence of mingw-w64-x86_64-pkgconf by calling multiple times, one for each needed package. So that is OK. Thanks!!

@jasagredo jasagredo force-pushed the jasagredo/each-pkgconfig-once branch 5 times, most recently from 15e8fc8 to 2d6dcd9 Compare September 19, 2023 07:55
@Mikolaj
Copy link
Member

Mikolaj commented Sep 19, 2023

Makes sense. Thank you all for the effective discussion.

@jasagredo, before you set the merge label, does the description of the PR still match the new code? Do you think it makes sense to ping all four reviewers and tell them what changed since they've reviewed last time?

…query length

MinGW's pkg-config returns only one version even if queried for
multiple libraries.
@Mikolaj Mikolaj force-pushed the jasagredo/each-pkgconfig-once branch from 2d6dcd9 to 9f15045 Compare October 7, 2023 11:15
@mergify mergify bot merged commit a0538d9 into haskell:master Oct 7, 2023
45 checks passed
@juhp juhp mentioned this pull request Nov 3, 2023
@juhp
Copy link
Collaborator

juhp commented Nov 3, 2023

Though honestly I think we should only query individual pkgconf's separately going forward.

Does cabal really needs all the pkgconf's even? I also wonder what the use-case is?

@gbaz
Copy link
Collaborator

gbaz commented Nov 3, 2023

The solver needs to know the installed packages on the system so it can make use of them in creating a build-plan. They are needed together rather than individually so that the solver can be pure rather than performing IO queries over the course of its execution.

@juhp
Copy link
Collaborator

juhp commented Nov 3, 2023

At least pkgconf-2.0 seems to revert to the old pkgconf-1.8 behavior

But quite a few distros are currently on pkgconf-1.9 so we really need to fix this properly

@jasagredo
Copy link
Collaborator Author

This PR targeted solving the inability of Mingw's pkg-conf to return multiple results.

I think it is very reasonable to start discussions about what you propose @juhp but maybe in a new issue/PR? I think #8930 is in the same line you are proposing.

@juhp
Copy link
Collaborator

juhp commented Nov 3, 2023

Yep, thanks I did that in #9391- I think I am addressing #8923 and I hope it also covers this case.

The mingw issue is different to Linux? That part is still unclear to me - does pkgconf-2.0 help?

@jasagredo
Copy link
Collaborator Author

jasagredo commented Nov 3, 2023

Perhaps it does help? I have not tried (I'm not developing on windows nowadays). However the environment variables flags should be mandatory in Windows and harmless in Linux.

Mingw has this weird inconvenience where there are 3 pkgconf implementations and each one produces different outputs.

@Mikolaj
Copy link
Member

Mikolaj commented Dec 21, 2023

@jasagredo (and presumably @grayjay) suggest to backport this to 3.10 branch for the 3.10.3.0 release. Let me mark it provisionally with a label, create a backport PR to see the conflicts and let's discuss.

@Mikolaj
Copy link
Member

Mikolaj commented Dec 21, 2023

@mergify backport

Copy link
Contributor

mergify bot commented Dec 21, 2023

backport

❌ No backport have been created

No destination branches found

@Mikolaj
Copy link
Member

Mikolaj commented Dec 21, 2023

@mergify backport 3.10

Copy link
Contributor

mergify bot commented Dec 21, 2023

backport 3.10

✅ Backports have been created

@Mikolaj
Copy link
Member

Mikolaj commented Dec 21, 2023

The conflicts don't seem terrible.

@Mikolaj
Copy link
Member

Mikolaj commented Dec 21, 2023

Here's the relevant comment by @grayjay: #9520 (comment)

mergify bot added a commit that referenced this pull request Dec 22, 2023
Try each pkg-config query separatedly (backport #9134)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merge delay passed Applied (usually by Mergify) when PR approved and received no updates for 2 days merge me Tell Mergify Bot to merge re: pkg-config Concerning pkg-config and pkgconfig-depends constraints
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet