Is there any way to define flags for cabal dependencies?

后端 未结 5 1434
天命终不由人
天命终不由人 2020-12-30 20:11

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 be

相关标签:
5条回答
  • 2020-12-30 20:56

    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
    0 讨论(0)
  • 2020-12-30 21:00

    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.

    0 讨论(0)
  • 2020-12-30 21:03

    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.

    0 讨论(0)
  • 2020-12-30 21:12

    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 讨论(0)
  • 2020-12-30 21:13

    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).

    0 讨论(0)
提交回复
热议问题