我如何才能有条件? [英] How can I have a conditional on cabal?

查看:88
本文介绍了我如何才能有条件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Haskell库,可以导出几个模块。我用 GHC GHCJS 编译该库。我正在使用 stack 来构建库。这些模块之一取决于 reflex-dom 。问题是由于无法链接 gtk + 3 reflex-dom >在OSX上。因此,如果编译器为 GHC ,我想排除该库。我该如何实现?

I have a Haskell library which exports several modules. I compile that library with both GHC and GHCJS. I'm using stack to build the library. One of those modules depends on reflex-dom. The issue is that I am not able to compile reflex-dom on GHC due to not being able to link gtk+3 on OSX. As such, I'd like to exclude that library if the compiler is GHC. How can I achieve that?

exposed-modules:
  MyLib.Foo
  MyLib.Bar
  MyLib.App.Backend.Reflex
  MyLib.App.Backend.Gloss
  ...

build-depends:
    base ...
    reflex-dom >= 0.2 && <0.3


推荐答案

虽然您可能不想这样做,在cabal用户手册的配置部分中介绍了执行此操作的方法:

While you may not want to do this, the way to do this is described in the "configurations" section of the cabal user manual:

https://www.haskell.org/cabal/users-guide/developing-packages.html#configurations

特别是,您应该能够这样写相关的部分:

In particular, you should be able to write the relevant sections as such:

exposed-modules:
    MyLib.Foo
    MyLib.Bar
    MyLib.App.Backend.Reflex
    MyLib.App.Backend.Gloss
if !impl(ghc)
  exposed-modules:
    OtherModule

build-depends: etc, etc, etc
if !impl(ghc)
   build-depends: etc1, etc2

这篇关于我如何才能有条件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆