36

I recently ran into a Cabal issue that I only managed to solve by manually installing transformers-compat with the -f transformers3 flag in my cabal sandbox before running cabal install for my project.

Is there any way to indicate in my application's .cabal file that I depend on a library so that it is built with the specific build flag?

2
  • At a glance, it looks like transformers-compat is supposed to be a shim used for old projects with old dependencies. Can you update your package to depend on the newer version of transformers? Commented May 7, 2014 at 17:55
  • 5
    Aside: calling any kind of technical problem with Cabal "Cabal hell" is not very informative. It'd be easier to help you if you described which error message you were getting. Commented May 8, 2014 at 2:17

6 Answers 6

18

Newer versions of Cabal let you specify constraints in your cabal.project.local or cabal.project file. For example:

constraints: hmatrix +openblas

Is there any way to indicate in my application's .cabal file that I depend on a library so that it is built with the specific build flag?

No, but in your case this is not actually a problem in the solver and is rather and uninformative error (caused by someone's less than judicious uses of flags).

1
17

Looks like it's not possible to specify such a dependency via the build-depends field in your .cabal file. buildDepends is defined as [Dependency], where data Dependency = Dependency PackageName VersionRange. You can use cabal install --constraint="transformers-compat +transformers3", though.

Looking at the transformers-compat.cabal file, I think that the solver should be able to figure out the correct flag assignment if you constrain your dependency on transformers appropriately. E.g. build-depends: transformers >= 0.3 && < 0.4 should force the solver to choose transformers-compat +transformers3. If this doesn't work, it may be a bug in the solver.

11

I also struggled for a long time to find a solution to this problem. I just found one! You have to modify the global cabal configuration file at ~/.cabal/config. Add a constraints line like this to the initial section of the file:

constraints: hmatrix +openblas

This enables the openblas flag for the hmatrix package. It will be used automatically the next time the package is installed. If there is a way to set such a flag locally for a sandbox, I could not find it.

0
7

You cannot do this with Cabal.

One way to do this is to use Stack. Edit your stack.yaml to include

flags:
  transformers-compat:
    transformers3: true
    

See also the section on flags.

1
  • Hi, is the first sentence here this still valid? Apparently cabal got the same functionality quite recently.
    – exa
    Commented Jun 28, 2022 at 18:30
6

cabal now supports an elegant way to do this similar to stack, through cabal.project configuration options.

package transformers-compat
    flags: +transformers3

will add the flag transformers3 when building the package transformers-compat.

-1

There are a couple of ways to constrain the version for installation.

  1. Add lower and upper bounds to package versions in the cabal file like Mikhail mentioned above, example of such a file here

  2. Additionally, you can override the settings in the .cabal file with the flag cabal install --constraint="bar-2.1"

To remove a specific version of a package:

  • In a sandbox you can unregister a version with cabal sandbox hc-pkg unregister bar-2.1
  • Global unregistering can be done with this command outside of sandbox ghc-pkg unregister bar-2.1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.