在 haskell 中编译具有一组较新依赖项的库

Compiling a library with a newer set of dependency in haskell

采用一些不太旧的 haskell 项目 hdocs(最后更新于 2020 年 11 月...)。

现在我想更新它的依赖项

#stack.yaml
flags: {}
packages:
- '.'
resolver:  nightly-2022-02-11
extra-deps:
- haddock-api-2.25.1

然后在这两种情况下我都得到 C 预处理错误 (!)

Building library for hdocs-0.5.5.0..

src/HDocs/Base.hs:69:5: error:
     error: function-like macro 'MIN_VERSION_haddock_library' is not defined
   |
69 | #if MIN_VERSION_haddock_library(1,8,0)
   |     ^
#if MIN_VERSION_haddock_library(1,8,0)
    ^
...

错误与某些代码无关,而是与构建过程本身有关。

我是否遗漏了 haskell 生态系统中明显的东西?

根据 the relevant section of the Cabal User Guide, Cabal provides a MIN_VERSION macro "for each package depended on via build-depends. The hdocs.cabal currently on GitHub 仅在 build-depends 的条件部分指定 haddock-library,因此 GHC 8.10 以上的任何内容都将丢失。既然如此,如果我们要以相同的方式组织 cabal 文件,可以通过指定 GHC 9.0 缺少的依赖项来避免这个特定错误:

-- In the library section of hdocs.cabal:
  if impl(ghc == 9.0.*)
    build-depends:
      ghc == 9.0.*,
      haddock-api >= 2.25 && < 2.26,
      haddock-library == 1.10.*