haskell / haskell/cabal

Per-cabal-file `constraints`

Open
#8,912 12 comments 3 reactions 0 assignees View on GitHub
Cabal: file format type: enhancement
Dominant language
Haskell
Stars
1.7k
Forks
750
Avg merge
4d 3h
Merged PRs (30d)
28

Description

It is possible to have a lot of components in a package. This is especially true once you start to make use of support for multiple public libraries, since this allows merging what have in the past been forced to be separate packages.

However, you then end up in this situation:
```
library foo
build-depends: base ^>= 4.17
...

library bar
build-depends: base ^>= 4.17
...

library baz
build-depends: base ^>= 4.17
...
```
etc.

If you stare hard at your dependencies, you can sometimes cut this down by finding a single component that the others depend on, and then only putting the constraint there. But this is manual and error-prone. And duplicating the constraints everywhere is also manual and tedious.

One workaround is to use lots of common stanzas:
```
common base { build-depends: base >= 4.7 && < 5 }
```
and include it everywhere. See [cabal-cache](https://github.com/haskell-works/cabal-cache/blob/main/cabal-cache.cabal#L22) for an example in the wild. This is... okay-ish, but still a bit clumsy.

What I would _like_ to be able to say is:
- `foo`, `bar`, and `baz` depend on `base`
- All things that depend on `base` in this cabal file have the following constraint on it, i.e. something similar to the `constraints` stanza in a `cabal.project` file

That seems to me to be a somewhat viable proposal: allow a `constraints` stanza in `.cabal` files, behaving just the same as in `cabal.project` files. I think that would be fairly intuitive and pretty useful.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.