如何在堆栈构建项目(使用nix)之前生成FFI依赖关系?

时间:2019-02-13 03:56:02

标签: c haskell ffi haskell-stack nix

我有一个Haskell + stack + nix项目,该项目大量使用了FFI代码。问题是,我依赖的两个C文件必须先生成 ,然后才能编译我的Haskell项目。这两个文件是(i)./cbits/xdg-shell-protocol.c和(ii)./include/xdg-shell-protocol.h

首先,这是可以生成以下文件的Makefile:

WAYLAND_PROTOCOLS=$(shell pkg-config --variable=pkgdatadir wayland-protocols)
WAYLAND_SCANNER=$(shell pkg-config --variable=wayland_scanner wayland-scanner)

# wayland-scanner is a tool which generates C headers and rigging for Wayland
# protocols, which are specified in XML. wlroots requires you to rig these up
# to your build system yourself and provide them in the include path.
xdg-shell-protocol.h:
 $(WAYLAND_SCANNER) server-header \
   $(WAYLAND_PROTOCOLS)/stable/xdg-shell/xdg-shell.xml $@

xdg-shell-protocol.c: xdg-shell-protocol.h
 $(WAYLAND_SCANNER) private-code \
   $(WAYLAND_PROTOCOLS)/stable/xdg-shell/xdg-shell.xml $@

请注意,我依赖系统程序wayland-protocolswayland-scanner,这两个程序都在我项目的shell.nix中指定:

buildInputs = with pkgs; [ 
                           # ...
                           # These are bleeding edge so I crafted my own nix expressions:
                           (callPackage ./nix/wayland.nix { } )
                           (callPackage ./nix/wayland-protocols.nix { } )
                           # ...
                        ];

最后请注意,我在package.yaml中告诉了Haskell这些文件:

c-sources:
   - cbits/xdg-shell-protocol.c
include-dirs:
  - include

问题:如何做到这一点,以便每次有人运行stack [--nix] build(带有或不带有nix)时,两个文件(i)./cbits/xdg-shell-protocol.c和(ii){确保{1}}是最新的吗?

0 个答案:

没有答案