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

Flag field in cabal.project package stanza does not apply to build tools #7787

Open
pranaysashank opened this issue Oct 31, 2021 · 9 comments
Labels
can-workaround There is a (maybe partial) workaround for the issue or missing feature re: build-tool Concerning `build-tools` and `build-tool-depends` re: flag Concerning user-defined flags in cabal files re: project-file Concerning cabal.project files type: bug

Comments

@pranaysashank
Copy link

Describe the bug
The solver doesn't seem to take into account constraints placed on packages in build-tool-depends.

To Reproduce
With the following cabal file & the cabal.project file:
--- chc.cabal

cabal-version:      3.6
name:               chc
version:            0.1.0.0
author:             pranaysashank
maintainer:         pranaysashank@gmail.com

executable chc
    main-is:          Main.hs
    build-depends:    base ^>=4.16.0.0
    build-tool-depends: happy:happy ^>=1.21.0
    hs-source-dirs:   app
    default-language: Haskell2010
-- cabal.project
packages:  ./

package happy
  flags: -bootstrap
$ cabal v2-build
Resolving dependencies...
Build profile: -w ghc-9.2.1 -O1
In order, the following will be built (use -v for more details):
 - happy-1.21.0 (exe:happy) (requires build)
 - chc-0.1.0.0 (exe:chc) (first run)
Starting     happy-1.21.0 (exe:happy)
Building     happy-1.21.0 (exe:happy)

Failed to build exe:happy from happy-1.21.0.
Build log (
/home/pranaysashank/.cabal/logs/ghc-9.2.1/happy-1.21.0-e-happy-60bda9d03a0488981bf080d8b712a1922aef99a5d52432048bbaabc1659bece1.log
):
Configuring executable 'happy' for happy-1.21.0..
Preprocessing executable 'happy' for happy-1.21.0..
cabal: The program 'happy' is required but it could not be found

cabal: Failed to build exe:happy from happy-1.21.0 (which is required by
exe:chc from chc-0.1.0.0). See the build log above for details.

Expected behavior
Expect the build to succeed with happy package built with -bootstrap flag.

System information

  • Operating system: nixos
  • cabal: 3.6.0.0, master
  • ghc: ghc-9.2.1
@fgaz
Copy link
Member

fgaz commented Oct 31, 2021

Looks related to #7189

@pranaysashank
Copy link
Author

I saw that issue but don't think it's related.

I did some digging around in the code base and it looks like the issue is in constraintScopeMatches function, it gets a top level scope which is set in resolverParams function. Because of this constraintScopeMatches function returns False and the solver doesn't fail here in processPackageConstraintF and it doesn't reject the constraint with default flag +bootstrap.

I haven't seen the solver code before, so I could be wrong. But with that fixed I could get the package to build.

@pranaysashank
Copy link
Author

Another reason I don't think it's related is because I can get it to build if I download it and add it to the packages list in cabal.project.

@pranaysashank
Copy link
Author

See pranaysashank@73669e4 which works for me.

@pranaysashank
Copy link
Author

@grayjay looks like you have last touched this part of the code. Perhaps you can help?

@grayjay
Copy link
Collaborator

grayjay commented Nov 4, 2021

I think that the problem is that there currently isn't a way to specify whether a package section in cabal.project applies to all uses of the package (including use as a build tool) or only the top-level use. I think there is an issue for this, but I wasn't able to find it just now.

I was able to make the reproduction progress by using the more expressive constraint field to specify that all uses of happy should be built with -bootstrap, by adding "constraints: any.happy -bootstrap" to the top of cabal.project.

Another related issue is #3502, which would add constraint syntax for more of the constraint scope functionality that is already implemented in the solver. For example, it would allow constraining the bootstrap flag of happy only when it is used as a build tool for chc.

@grayjay grayjay added re: project-file Concerning cabal.project files and removed cabal-install: solver labels Nov 4, 2021
@grayjay grayjay changed the title Constraints aren't solved properly for build-tool-depends Flag field in cabal.project package stanza does not apply to build tools Nov 4, 2021
@pranaysashank
Copy link
Author

@grayjay Thanks for the breakdown. The package also builds successfully with the flag if I unpack the happy package and add it to the packages section of the project file. Is this difference from when you're downloading from Hackage part of the same issue? I am assuming it works because the flag is applied to the package because its a target.

@phadej
Copy link
Collaborator

phadej commented Nov 4, 2021

The package also builds successfully with the flag if I unpack the happy package and add it to the packages section of the project file.

Then it is also a local i.e. "top-level" package. i.e. package ... flags applies to it.

@andreasabel andreasabel added the re: build-tool Concerning `build-tools` and `build-tool-depends` label Nov 8, 2021
@andreasabel andreasabel added the re: flag Concerning user-defined flags in cabal files label Nov 13, 2021
sevanspowell added a commit to sevanspowell/gtk2hs that referenced this issue Jul 7, 2022
- ouroboros-network-lib requires hashtables < 1.3. We would typically constrain
  hashtables with a constraint in a cabal.project or cabal file. However,
  because gtk2hs-buildtools is used as a build tool, cabal has no way of
  applying constraints to gtk2hs-buildtools, so any constraint we enforce from
  above is ignored.

  We have to fork the package and apply the constraint at the source.

  See haskell/cabal#7787
@mpickering
Copy link
Collaborator

You could also write.. which I imagine will satisfy this use case.

constraints:
    any.happy -bootstrap

@ulysses4ever ulysses4ever added the can-workaround There is a (maybe partial) workaround for the issue or missing feature label Nov 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
can-workaround There is a (maybe partial) workaround for the issue or missing feature re: build-tool Concerning `build-tools` and `build-tool-depends` re: flag Concerning user-defined flags in cabal files re: project-file Concerning cabal.project files type: bug
Projects
None yet
Development

No branches or pull requests

8 participants