如何使用Cabal将Haskell依赖关系的版本固定到基础原生依赖关系的版本? [英] How can I pin a version of a Haskell dependency to a version of an underlying native dependency with Cabal?
问题描述
在我的特殊情况下,我在Haskell软件包 bindings-libzip
的Cabal文件中有一个依赖项。特别是,我可以接受 libzip
的几种不同版本,例如 bindings-libzip-0.11
或 bindings-libzip-0.10
。这些反过来又依赖于各自的本机C libzip
库版本 0.11
和 0.10
。
In my particuar case, I have a dependency in my Cabal file on the Haskell package bindings-libzip
. In particular, I could accept several different versions of libzip
, e.g. bindings-libzip-0.11
or bindings-libzip-0.10
. These in turn have a dependency on the respective native C libzip
libraries versions 0.11
and 0.10
.
因此,我有 bindings-libzip> = 0.10<我的
。 .cabal
文件中的0.12
Therefore I have bindings-libzip >= 0.10 < 0.12
in my .cabal
file.
Haskell软件包 bindings-libzip-x
用 PkgConfig-Depends
指定 libzip
版本<$ c客户端计算机上必须存在$ c> x 。假设下游用户安装了 0.10
版本的 libzip
。但是,当拉下我的包时,该用户拉下了可能的最新依赖关系,并以可传递的方式拉下了 bindings-libzip $ c $的版本
0.11
c>。这将导致生成过程出错,并显示一条有关安装的 libzip
版本不正确的消息。
The Haskell package bindings-libzip-x
specifies with PkgConfig-Depends
that libzip
version x
must be present on a client machine. Let's say a downstream user has version 0.10
of libzip
installed. However, when pulling down my package, this user pulls down the latest dependencies possible and transitively pulls down version 0.11
of bindings-libzip
. This causes the build process to error out with a message about an incorrect version of libzip
installed.
我是否可以在.cabal文件中指定以任何方式使用 bindings-libzip-0.11
如果 pkg-config
检测到 libzip
的版本 0.11
,并仅当 pkg-config
检测到版本 0.10 时,使用
bindings-libzip-0.10
code>的 libzip
?
Is there any way I can specify in my .cabal file to use bindings-libzip-0.11
if and only if pkg-config
detects version 0.11
of libzip
and to use bindings-libzip-0.10
if and only if pkg-config
detects version 0.10
of libzip
?
推荐答案
我正在提交另一个答案,因为这使用了另一个主意...
I'm submitting another answer because this uses another idea...
使用自定义Setup.hs和 defaultMainWithHooksArgs
可以使您检查并将args修改为 cabal configure
命令。
Using a custom Setup.hs with defaultMainWithHooksArgs
allows you to inspect and modify the args to the cabal configure
command.
这是Setup.hs,它不做任何修改:
This is a Setup.hs which does no modification:
import Distribution.Simple
import Distribution.Simple.Configure
import System.Environment
main = do
args <- getArgs
defaultMainWithHooksArgs simpleUserHooks args
如果您的.cabal文件已定义标志,例如:
If your .cabal file has a flag defined, e.g.:
Flag Foo
Default: False
然后在args中您将看到-flags = -foo
。因此,想法是:
then in the args you will see "--flags=-foo"
. So the idea is:
- 在.cabal文件中定义两个标志-
use10
和use11
选择要使用的bindings-libzip
版本。 - 在自定义的Setup.hs中确定要使用的版本。
- 找到
-flags = ...
arg并进行修改在将其传递给defaultMainWithHooksArgs
之前进行适当的设置。
- Define two flags in the .cabal file -
use10
anduse11
to select which version ofbindings-libzip
to use. - In your custom Setup.hs determine which version to use.
- Find the
"--flags=..."
arg and modify it appropriately before passing it along todefaultMainWithHooksArgs
.
这篇关于如何使用Cabal将Haskell依赖关系的版本固定到基础原生依赖关系的版本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!