简体   繁体   English

如何管理单个Haskell程序的多个配置?

[英]How can I manage multiple configurations of a single Haskell program?

What is an alternative to autotools in Haskell world? 在Haskell世界中,什么是autotools的替代品? I want to be able to choose between different configurations of the same source code. 我希望能够在相同源代码的不同配置之间进行选择。

For example, there are at least two implementations of MD5 in Haskell: Data.Digest.OpenSSL.MD5 and Data.Digest.Pure.MD5 . 例如,Haskell中至少有两个MD5实现: Data.Digest.OpenSSL.MD5Data.Digest.Pure.MD5 I'd like to write code in such a way that it can figure out which library is already installed, and didn't require to install the other. 我想以这样的方式编写代码,它可以找出已安装的库,并且不需要安装另一个库。

In CI can use Autotools/Scons/CMake + cpp . 在CI中可以使用Autotools / Scons / CMake + cpp In Python I can catch ImportError . 在Python中我可以捕获ImportError Which tools should I use in Haskell? 我应该在Haskell中使用哪些工具?

In Haskell you use Cabal configurations. 在Haskell中,您使用Cabal配置。 At your project top-level directory, you put a file with the extension .cabal , eg, <yourprojectname>.cabal . 在项目顶级目录中,放置扩展名为.cabal的文件,例如<yourprojectname>.cabal The contents are roughly: 内容大致如下:

Name:                myfancypackage
Version:             0.0
Description:         myfancypackage
License:             BSD3
License-file:        LICENSE
Author:              John Doe
Maintainer:          john@example.com
Build-Type:          Simple
Cabal-Version:       >=1.4

Flag pure-haskell-md5
  Description: Choose the purely Haskell MD5 implementation
  Default: False

Executable haq
  Main-is:           Haq.hs
  Build-Depends:     base-4.*
  if flag(pure-haskell-md5)
    Build-Depends:   pureMD5-0.2.*
  else
    Build-Depends:   hopenssl-1.1.*

The Cabal documentation has more details, in particular the section on Configurations . Cabal文档有更多详细信息,特别是有关配置的部分。

As nominolo says, Cabal is the tool to use. 正如nominolo所说,Cabal是使用的工具。 In particular, the 'configurations" syntax. 特别是'配置'语法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM