我有一个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-protocols
和wayland-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}}是最新的吗?