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?
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.
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.
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).
There are a couple of ways to constrain the version for installation.
Add lower and upper bounds to package versions in the cabal file like Mikhail mentioned above, example of such a file here
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
来源:https://stackoverflow.com/questions/23523869/is-there-any-way-to-define-flags-for-cabal-dependencies