我怎样才能对 cabal 有条件?
How can I have a conditional on cabal?
我有一个 Haskell 库,可以导出多个模块。我用 GHC
和 GHCJS
编译那个库。我正在使用 stack
来构建库。其中一个模块依赖于 reflex-dom
。问题是我无法在 GHC 上编译 reflex-dom
,因为无法在 OSX 上编译 link gtk+3
。因此,如果编译器是 GHC
,我想排除该库。我怎样才能做到这一点?
exposed-modules:
MyLib.Foo
MyLib.Bar
MyLib.App.Backend.Reflex
MyLib.App.Backend.Gloss
...
build-depends:
base ...
reflex-dom >= 0.2 && <0.3
虽然您可能不想这样做,但在 cabal 用户手册的 "configurations" 部分中描述了这样做的方法:
https://www.haskell.org/cabal/users-guide/developing-packages.html#configurations
特别是,您应该能够这样编写相关部分:
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
我有一个 Haskell 库,可以导出多个模块。我用 GHC
和 GHCJS
编译那个库。我正在使用 stack
来构建库。其中一个模块依赖于 reflex-dom
。问题是我无法在 GHC 上编译 reflex-dom
,因为无法在 OSX 上编译 link gtk+3
。因此,如果编译器是 GHC
,我想排除该库。我怎样才能做到这一点?
exposed-modules:
MyLib.Foo
MyLib.Bar
MyLib.App.Backend.Reflex
MyLib.App.Backend.Gloss
...
build-depends:
base ...
reflex-dom >= 0.2 && <0.3
虽然您可能不想这样做,但在 cabal 用户手册的 "configurations" 部分中描述了这样做的方法:
https://www.haskell.org/cabal/users-guide/developing-packages.html#configurations
特别是,您应该能够这样编写相关部分:
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