简体   繁体   English

如何将我的包裹标记为特定于ghc?

[英]How do I mark my package as depending on ghc specifically?

My package depends on some implementation details in GHC (more than just language extensions). 我的程序包取决于GHC中的一些实现细节(不仅仅是语言扩展)。 How should I express this dependency in my .cabal file? 我应该如何在我的.cabal文件中表达这种依赖性? Should I? 我是不是该? Am I just being paranoid? 我只是偏执吗?

build-depends

I thought that maybe I should just add ghc to the build-depends list, but there's no ghc package . 我认为也许应该将ghc添加到build-depends列表中,但是没有ghc软件包

Inspired by ghc-mod's dependency list , I tried it anyway. ghc-mod的依赖项列表启发,我还是尝试了一下。 I added build-depends: ghc >= 7.20 , and this produced the expected failure when I only had 7.10.3 installed. 我添加了build-depends: ghc >= 7.20 ,这在我仅安装7.10.3时产生了预期的失败。 (7.20 doesn't even exist as of this writing.) (在撰写本文时,7.20甚至还不存在。)

cabal.exe: At least the following dependencies are missing:
ghc >=7.20

Is ghc some sort of magic package? ghc是某种魔术包吗? What are the other magic packages? 还有哪些其他魔术包?

tested-with

There's the tested-with package property . 有一个tested-with包属性 That doesn't seem affect the build, however. 但是,这似乎并不影响构建。 I added tested-with: GHC==7.20 (a version of GHC that doesn't exist but newer than the 7.10.3 I have), but cabal build still built my package and didn't even issue a warning or anything. 我添加了以下tested-with: GHC==7.20 (不存在的GHC版本,但比我的7.10.3更新),但是cabal build仍然构建了我的软件包,甚至没有发出警告或任何警告。

ghc is a package, and not a magic one. ghc 一个软件包,不是一个魔术包。 It is just not a package on Hackage. 它不是关于Hackage的软件包。 Rather it is installed with your ghc install, and hidden by default. 而是它与您的ghc安装一起安装,并且默认情况下是隐藏的。 You can see it listed in the output of ghc-pkg list . 您可以在ghc-pkg list的输出中看到它。 It exposes an API for the compiler. 它为编译器提供了一个API。 If you don't actually use it, you shouldn't depend on it. 如果您实际上没有使用它,则不应依赖它。 In general, most people don't pin themselves to GHC unless they actually need to. 通常,除非真正需要,否则大多数人不会将自己固定在GHC上。 For example, are you sure your package won't compile with GHCjs or with Haste ? 例如,您确定您的软件包不会与GHCjsHaste一起编译吗? So, why limit yourself ahead of time... 所以,为什么要提前限制自己...

If you can use your package without the implementation details in ghc, but can also do things in a "longhand" way that is more expensive, you can use the macros provided by cabal to have CPP conditionals in your code that give different results based on the test for GHC. 如果您可以在ghc中使用没有实现细节的程序包,但也可以以“长期”方式执行更昂贵的操作,则可以使用cabal提供的宏在代码中使用CPP条件,以便根据以下条件提供不同的结果对GHC的测试。

tested-with is indeed a purely informational field used by convention. tested-with确实按照惯例使用一个纯粹的信息场。

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

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