Haskell / Stack / Nix 构建失败,需要 pkg-config >= 0.9.0 和 cairo >= 1.2.0,但最新版本是 pkg-config 0.29.2 和 cairo 1.15.4。

4
我正在使用Stack和Nix构建一个Haskell项目,并依赖于Hackage中的cairo库。
当我构建项目时,出现错误:找不到“pkg-config >= 0.9.0”或“cairo >= 1.2.0”。然而,根据它们的网站,最新版本是“pkg-config 0.29.2”和“cairo-1.15.4”,Nix包管理器也反映了这一点。
另一方面,有一篇2006年发布的文章this article from 2006 announcing the release of Cairo 1.2.0,进一步混淆了问题。
问题:
  1. 为什么预期版本与 nixpkgspkg-config / cairo 网站上发布的版本如此不同?

  2. 您有什么建议可以让 cairo 在 macOS 上构建(最好的情况是:使用 Nix 用于系统包和 Stack 用于 Haskell 包)

重现步骤:

> stack new cairo-test simple && cd cairo-test

# Now, to get Cairo
> stack install cairo

cairo-0.13.3.1: configure ...
Process exited with code: ExitFailure 1
Configuring cairo-0.13.3.1...
setup: The program 'pkg-config' version >=0.9.0 is required but it could not be found.

# This version doesn't seem to exist (not on the pkg-config website, either).
> nix-env -qaP pkg-config
nixpkgs.pkgconfig          pkg-config-0.29.2
nixpkgs.pkgconfigUpstream  pkg-config-0.29.2

# However, if installed, a new error:
> nix-env -i pkg-config
installing ‘pkg-config-0.29.2’
building path(s) ‘/nix/store/m4ks2si7b78757c1rc43r0833pxkvjb3-user-environment’
created 102 symlinks in user environment
> stack install cairo
setup: The pkg-config package 'cairo' version >=1.2.0 is required but 
it could not be found.

# Again, this version doesn't seem to exist, either on the site on in `nixpkgs`
> nix-env -qaP cairo
nixpkgs.cairo  cairo-1.14.8

# Installing it anyway, to see what the next error is
> nix-env -i cairo
installing ‘cairo-1.14.8’
building path(s) ‘/nix/store/dcx0in96wcd7yd8q71y93jd5306vag8g-user-environment’
created 112 symlinks in user environment

# Get the same version error now that Cairo is installed
setup: The pkg-config package 'cairo' version >=1.2.0 is required but it could not be found.

我在Haskell开发和Nix方面远非专家,但通常要使用Nix的库包,您必须打开一个nix-shell:nix-shell -p pkg-config cairo - Zimm i48
2个回答

6
问题不在于库的版本,1.14.81.2.0 更高。问题在于 Cairo 开发文件没有链接到你的环境中,也就是说,$PKG_CONFIG_PATH 没有设置。

有三种解决方案:

  1. Find the cairo-dev directory in /nix/store, and add it to PKG_CONFIG_PATH. E.g.,

     $ cairodev=$(nix-store --query --outputs $(nix-instantiate '<nixpkgs>' -A cairo) | grep dev$)
     $ export PKG_CONFIG_PATH=$cairodev:$PKG_CONFIG_PATH
    
  2. Run stack from within a nix shell, nix-shell -p pkgconfig cairo.

  3. Use stack's nix support, by adding the following to stack.yml:

    nix:
      enable: true
      packages: [pkgconfig, cairo]
    

0
通过安装Homebrew,然后使用brew install cairo安装cairo,我成功地构建了项目。
然而,这安装的是Cairo 1.14版本——与Nix安装的相同!当我使用brew info cairo进行检查时,我看到了更多的信息:
cairo: stable 1.14.8 (bottled), devel 1.15.4, HEAD

==> Dependencies
Build: pkg-config ✘
Required: freetype ✔, fontconfig ✔, libpng ✔, pixman ✔, glib ✔

我尝试使用Nix安装这些依赖项,并卸载Homebrew。但是没有成功--出现了大量的链接错误。因此,我重新安装了Homebrew,现在它可以正常工作。

这不是我想要的好的、干净的解决方案(需要安装外部包管理器),但它暂时解决了问题。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接