简体   繁体   English

如何从 cabal 文件中排除以避免破坏我的包的 GHC 错误?

[英]How do I exclude from cabal file to avoid GHC bug that breaks my package?

Since my package will not work with a known issue in GHC 9.0.1 , if I want to exclude versions (of what; base ?) that have the bug that causes the issue from my .cabal , what do I need to specify there?由于我的包无法处理 GHC 9.0.1 中的已知问题,如果我想从我的.cabal排除具有导致问题错误的版本(什么; base ?),我需要在那里指定什么? It works with every other person of GHC back through 7-something.它与 GHC 的每个其他人一起工作,直到 7 岁左右。

Edit: Just as I posted this, I remembered that there is another trick to exclude GHC versions by writing this in a cabal file:编辑:就像我发布这个一样,我记得还有另一个技巧可以通过将其写入 cabal 文件来排除 GHC 版本:

library
    ...
    -- This package does not work with GHC 9.0.1 due to a bug
    -- See: https://github.com/orome/crypto-enigma-hs/issues/35#issuecomment-865260187
    if impl(ghc == 9.0.1)
      buildable: False

This won't give a very descriptive error, but it will prevent GHC 9.0.1 from building your package.这不会给出非常描述性的错误,但会阻止 GHC 9.0.1 构建您的包。


There is a Haskell wiki page about which base versions correspond to which GHC versions: https://wiki.haskell.org/Base_package .有一个 Haskell wiki 页面,关于哪些基本版本对应于哪些 GHC 版本: https : //wiki.haskell.org/Base_package Notably " 9.0.1 (Feb 2021) 4.15.0.0 ", so you can add base <4.15.0.0 to your cabal file to exclude GHC 9.0.1.值得注意的是“ 9.0.1 (Feb 2021) 4.15.0.0 ”,因此您可以将base <4.15.0.0添加到您的 cabal 文件中以排除 GHC 9.0.1。 But this is not a foolproof method, because base versions do not always change when the GHC version changes.但这并不是万无一失的方法,因为当 GHC 版本更改时,基础版本并不总是更改。 When the bug is fixed it might not necessarily be accompanied by a new base version.当错误被修复时,它可能不一定伴随着新的base版本。

I don't think there is a way to explicitly exclude GHC versions in your cabal file, but that is also kind of reasonable because versions of GHC with bugs in them should not be used to compile any package at all;我认为没有办法在您的 cabal 文件中明确排除 GHC 版本,但这也是合理的,因为其中存在错误的 GHC 版本根本不应用于编译任何包; users should not expect GHC 9.0.1 to compile any package correctly.用户不应期望 GHC 9.0.1 能够正确编译任何包。 I think it is acceptable for library authors to simply warn somewhere in the documentation about this specific bug if it is known to cause issues in their package.我认为库作者可以在文档中的某个地方简单地警告这个特定的错误,如果已知它会导致他们的包中出现问题,这是可以接受的。

Another option is to enforce compilation failure using CPP in the module containing the bug to check if it is compiled with a specific GHC version as explained in this stackoverflow question , which links to this section in the GHC manual .另一种选择是在包含错误的模块中使用 CPP 强制编译失败,以检查它是否使用特定 GHC 版本编译,如此 stackoverflow 问题中所述,该问题链接到GHC 手册中的此部分

So you could add something like this to the top of your file:所以你可以在文件的顶部添加这样的东西:

{-# LANGUAGE CPP, TemplateHaskell #-}

#if __GLASGOW_HASKELL__==900 && __GLASGOW_HASKELL_PATCHLEVEL1__==1
$(error "This library does not work with GHC 9.0.1 due to a bug\n\
  \      See: https://github.com/orome/crypto-enigma-hs/issues/35#issuecomment-865260187.")
#endif

That will at least prevent anyone from building that module with GHC 9.0.1 and it will give a reasonably readable error message:这至少会阻止任何人使用 GHC 9.0.1 构建该模块,并且会给出合理可读的错误消息:

CPPTest.hs:1:1: error:
    Exception when trying to run compile-time code:
      This library does not work with GHC 9.0.1 due to a bug
      See: https://github.com/orome/crypto-enigma-hs/issues/35#issuecomment-865260187
CallStack (from HasCallStack):
  error, called at CPPTest.hs:4:1 in main:Main
    Code: error
            "This library does not work with GHC 9.0.1 due to a bug\n      See: https://github.com/orome/crypto-enigma-hs/issues/35#issuecomment-865260187"
  |
1 | {-# LANGUAGE CPP, TemplateHaskell #-}
  | ^

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

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