使用 Stack 构建时如何包含从 haskell 源文件生成的 'xxx_stub.h' 文件

How to include the 'xxx_stub.h' file generated from a haskell source file when building with Stack

使用 Stack 构建,我在 src/ 中有一个 lib.hs,在 app/ 中有一个 main.c。构建时,在.stack-work/dist/x86_64-linux/Cabal-2.2.0.1/build下生成lib_stub.h

要将此文件包含在 main.c 中,我要么在 #include 指令后面写一个完整的绝对路径,要么在手动第二次传递之前,手动将 lib_stub.h 文件复制到 app/,这有点愚蠢。

有没有更好的方法?

更多信息:

我的package.yaml长得像

name:                mylib
version:             0.1.0.0
github:              "gituser/mylib"
license:             BSD3
author:              "Author name here"
maintainer:          "example@example.com"
copyright:           "2018 Author name here"

extra-source-files:
- README.md
- ChangeLog.md

# Metadata used when publishing your package
# synopsis:            Short description of your package
# category:            Web

# To avoid duplicated efforts in documentation and dealing with the
# complications of embedding Haddock markup inside cabal files, it is
# common to point users to the README.md file.
description:         Please see the README on GitHub at <https://github.com/gituser/mylib#readme>

dependencies:
- base >= 4.7 && < 5

library:
  source-dirs: src
  dependencies:
  - free
  - mtl

executables:
  cont-demo:
    main:                main.c
    source-dirs:         app
    ghc-options:
    - -threaded
    # - -rtsopts
    # - -with-rtsopts=-N
    dependencies:
    - mylib

tests:
  mylib-test:
    main:                Spec.hs
    source-dirs:         test
    ghc-options:
    - -threaded
    - -rtsopts
    - -with-rtsopts=-N
    dependencies:
    - mylib

我的路径结构看起来像

.
├── app
│   ├── MyLib_stub.h
│   └── main.c
├── ChangeLog.md
├── mylib.cabal
├── LICENSE
├── package.yaml
├── README.md
├── Setup.hs
├── src
│   └── MyLib.hs
├── stack.yaml
└── test
    └── Spec.hs

其中 app/MyLib_stub.h 是手动复制的,不会自动放置在那里。

如果 Stack 有一些正确的方法来做到这一点,我真的很喜欢它,但据我所知,它没有。

我目前在具有类似要求的项目中所做的是,我symlink 不是复制 _stub.h 文件到更方便的位置它。这只需要做一次,符号链接可以置于版本控制之下,然后对 LONG_PATH/....h 文件的更新将自动显示在方便的

$ ln -s dist/build/bla/bla/long/path/MyLib_stub.h app/MyLib_stub.h
$ git add app/MyLib_stub.h

恐怕这不适用于 Windows,但可能有类似的替代方法。