使用依赖项 pandoc-citeproc 在 Haskell 中构建独立的二进制可执行文件

Building a self-contained binary executable in Haskell with the dependency pandoc-citeproc

我正在尝试为用 Haskell 编写的 CLI 工具编译一个独立的可执行文件。我按照 this 示例使用 Cabal v3.2 和 ghc v8.10.3 Github 操作自动为不同操作系统构建可执行文件。

这似乎运行良好,可执行文件表面上运行良好,但当实际应用于数据时,我收到以下 Linux 版本的错误消息(我没有测试 Windows 版本, 但有同事确认macOS版本也有同样的问题):

myprogram-0.3.2-Linux-ghc-8.10.3: 
/home/runner/.cabal/store/ghc-8.10.3/pandoc-citeproc-0.17.0.2-
0607b6a3d51d41b0211d235af7fcf6eeb452dc6738775583dac1146860db61b1/
share/locales/locales-en-US.xml: openBinaryFile: does not exist (No such file or directory)

这告诉我,我依赖于 BibTeX 文件解析的 pandoc-citeproc 有一些额外的数据文件没有打包到可执行文件中。我确实在 cabal-install 文档中找到了下面这句话:

Note that copied executables are not self-contained, since they might use data-files from the store. source

我也阅读了 pandoc 文档,它可以以已经包含这些额外文件的方式构建。

It is possible to compile pandoc such that the data files pandoc uses are embedded in the binary. The resulting binary can be run from any directory and is completely self-contained. With cabal, add -fembed_data_files to the cabal configure or cabal install commands. With stack, use --flag pandoc:embed_data_files. source

如何使用 cabal install 构建可执行文件以防止出现上述错误消息?我希望这是可能的,我没有遗漏任何重要的东西。

我试过了

cabal install exe:myprogram --install-method=copy --overwrite-policy=always -fembed_data_files

无济于事。

cabal install exe:myprogram 命令中添加 embed_data_files 标志将不起作用,因为 cabal-install 会将其传递给您的可执行文件,而不是将其转发给 pandoc-citeproc 。最方便的永久设置方式是通过 the cabal.project file。如果您没有,请使用以下最少的内容创建它:

packages: ./*.cabal

package pandoc-citeproc
    flags: +embed_data_files

cabal-install 将在您下次请求构建时使用标志重新编译 pandoc-citeproc 依赖项。