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 clear when pkg-config is not present #10122

Merged
merged 2 commits into from
Jun 28, 2024

Conversation

jasagredo
Copy link
Collaborator

@jasagredo jasagredo commented Jun 18, 2024

When no pkg-config program was found, cabal would claim that the package is not in the db, instead of telling clearly that no pkg-config was found at all.

QA Notes

On a system which has no pkg-config, with this package (for example):

cabal-version:      3.0
name:               aaaaa
version:            0.1.0.0
build-type:         Simple
library
    pkgconfig-depends: zlib
    hs-source-dirs:   src
    default-language: Haskell2010

The following message will be shown:

$ cabal build
Resolving dependencies...
Error: [Cabal-7107]
Could not resolve dependencies:
[__0] next goal: aaaaa (user goal)
[__0] rejecting: bb-0.1.0.0 (pkg-config package zlib-any is needed but no pkg-config executable was found or querying it failed)
[__0] fail (backjumping, conflict set: aaaaa)
After searching the rest of the dependency tree exhaustively, these were the goals I've had most trouble fulfilling: aaaaa

In verbose mode, the following warning will also be printed:

$ cabal build -v
Warning: Failed to query pkg-config, Cabal will backtrack if a package from
pkg-config is requested. Error message: cannot find pkg-config program

To emulate this one can do the following invocation that temporarily renames pkg-config executable:

mv $(which pkg-config) "$(dirname $(which pkg-config))/pkg-config-bak"
cabal build -v
mv $(which pkg-config-bak) "$(dirname $(which pkg-config-bak))/pkg-config"

  • Patches conform to the coding conventions.
  • Any changes that could be relevant to users have been recorded in the changelog.
  • The documentation has been updated, if necessary.
  • Manual QA notes have been included.
  • Tests have been added. (Ask for help if you don’t know how to write them! Ask for an exemption if tests are too complex for too little coverage!)

@jasagredo jasagredo marked this pull request as ready for review June 18, 2024 15:09
@Kleidukos
Copy link
Member

Oh god I had this exact problem happen recently. Thank you so much!

Copy link
Member

@Kleidukos Kleidukos left a comment

Choose a reason for hiding this comment

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

LGTM. Could you please add some QA notes? :)

@jasagredo
Copy link
Collaborator Author

jasagredo commented Jun 18, 2024

Sure! QA and changelog will come as soon as I have some time to write them.

Thanks!

@grayjay grayjay added cabal-install: solver re: pkg-config Concerning pkg-config and pkgconfig-depends constraints labels Jun 18, 2024
@andreabedini
Copy link
Collaborator

It looks like the messaging is inconsistent. Apparently the solver used to ignore pkg-config dependencies when pkg-config is missing (which is what this message says) but in 68e2737 the behaviour was changed to backtrack.

Do we need to reconsider this? Is backtracking (and likely failing) without pkg-config the right thing to do? Maybe we could instead make sure Cabal has the same behaviour? (that is, to ignore pkg-config dependencies if pkg-config is missing)

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.

In terms of implementation, I'd prefer to change the call site (validateTree).

The value I see in the pkgConfigPkgIsPresent function is to merge the NoPkgConfig case into False, but if we want to keep them separate, we should propagate the change up:

We turn functions producing PkgConfigDb into producing Maybe PkgConfigDb where

newtype PkgConfigDb = PkgConfigDb (M.Map PkgconfigName (Maybe 

Other than changing few types, only code changes I found are in two places:

  • Distribution.Solver.Modular.Validate.validateTree which is perfect because it's were you want to deal with the absence of pkg-config.
  • Distribution.Client.ProjectPlanning.elaborateInstallPlan which is a bit surprising but good that we found it! 😂

WDYT?

@jasagredo
Copy link
Collaborator Author

It looks like the messaging is inconsistent. Apparently the solver used to ignore pkg-config dependencies when pkg-config is missing (which is what this message says) but in 68e2737 the behaviour was changed to backtrack.

Do we need to reconsider this? Is backtracking (and likely failing) without pkg-config the right thing to do? Maybe we could instead make sure Cabal has the same behaviour? (that is, to ignore pkg-config dependencies if pkg-config is missing)

Perhaps that is something to consider. The very least I want to do with this PR is to clarify the error message on the current logic, a follow-up PR could deal with whether or not the current behaviour is the wanted one.

@Bodigrim
Copy link
Collaborator

Apparently the solver used to ignore pkg-config dependencies when pkg-config is missing (which is what this message says) but in 68e2737 the behaviour was changed to backtrack.

Do we need to reconsider this? Is backtracking (and likely failing) without pkg-config the right thing to do?

Yes, backtracking is a right thing to do and it is a crucial ingredient in multiple packages (e. g., zlib). Please do not break this behaviour. This allows packages to enable pkg-config flag by default so that platforms with pkg-config benefit from relying system packages (less to build, more secure), but platforms without easily available pkg-config (think Windows or thing JavaScript) do not degrade in user experience.

@andreabedini
Copy link
Collaborator

Yes, backtracking is a right thing to do and it is a crucial ingredient in multiple packages (e. g., zlib). Please do not break this behaviour. This allows packages to enable pkg-config flag by default so that platforms with pkg-config benefit from relying system packages (less to build, more secure), but platforms without easily available pkg-config (think Windows or thing JavaScript) do not degrade in user experience.

I had no intention to change that behaviour. You make a good argument. In this case we should make sure the behaviour (and its reason) is documented and that the code is consistent with it.

@jasagredo
Copy link
Collaborator Author

@andreabedini I unified your branch and mine into this one, and fixed some compilation errors plus some rewording on the error message. Let me know how it looks 👍

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.

Note that, in readPkgConfigDb, we use ioErrorHandler to call noPkgConfig in case something fails.

So if pkg-config is available but calling it fails for some reason, we will still return Nothing and backtrack on all pkg-config constraints. This possibiliy is mentioned in the comment right above.

Do we need to worry about this? Recent experience showed that querying pkg-config can be unreliable (see #8930, #9134, #9360, #9478, and my own #9422, ping @georgefst).

Ping @Mikolaj @Kleidukos @ulysses4ever @Bodigrim @georgefst

@jasagredo beside updating that message above, the implementation looks good to me now 👍.

@Kleidukos
Copy link
Member

So if pkg-config is available but calling it fails for some reason, we will still return Nothing and backtrack on all pkg-config constraints.

Ah, indeed the loss of granularity is problematic. That being said I am not knowledgeable enough to assert that calling pkg-config twice will produce a reliable result (reliably failed or unreliably succeeded on the second time).

@jasagredo jasagredo force-pushed the js/warn-missing-pkgconfig branch 2 times, most recently from e3ee938 to 727acd8 Compare June 22, 2024 09:21
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.

👍

@andreabedini andreabedini added the merge me Tell Mergify Bot to merge label Jun 25, 2024
Copy link
Collaborator

@grayjay grayjay left a comment

Choose a reason for hiding this comment

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

Thanks for simplifying PkgConfigDb, too!

@jasagredo
Copy link
Collaborator Author

@grayjay I think both of your comments are very valid points. I will incorporate them, then merge. Thanks!

@jasagredo jasagredo removed the merge me Tell Mergify Bot to merge label Jun 25, 2024
@jasagredo jasagredo force-pushed the js/warn-missing-pkgconfig branch 2 times, most recently from a03daba to 1dfae21 Compare June 25, 2024 08:50
@jasagredo
Copy link
Collaborator Author

Rebased on latest master

@jasagredo jasagredo added the merge me Tell Mergify Bot to merge label Jun 25, 2024
@mergify mergify bot added the merge delay passed Applied (usually by Mergify) when PR approved and received no updates for 2 days label Jun 27, 2024
andreabedini and others added 2 commits June 27, 2024 08:51
When no pkg-config program was found, cabal would
claim that the package is not in the db, instead
of telling clearly that no pkg-config was found at
all.
@mergify mergify bot merged commit a407863 into haskell:master Jun 28, 2024
53 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cabal-install: solver 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.

6 participants