问题描述
我在 OCaml 中编写了一个库,其所有源代码都位于 lib
文件夹中。
我还在 bin
文件夹中准备了“facade”可执行文件。
现在我想准备一些如何使用上述可执行文件的示例。
为此,我需要事先复制一个可执行文件,或者(最好)告诉 Dune 在构建后使用新创建的一个。
这是我的问题。
Dune 的 copy_files
节不允许 1 我从 _build
文件夹复制。
有没有其他方法可以在每次构建后使用新的可执行文件,或者我是否需要在某个时候复制它们并保持最新?
以下是项目的结构(以防口头描述以任何方式误导)。
root
lib <- source
bin <- frontend for source
examples <- how to use the above frontend
1 不允许我是指本节的以下用法:
( copy_files %{project_root}/_build/default/bin/program.exe )
解决方法
@Lhooq 建议的解决方案可能是使用带有 dune exec
参数的 --root
命令。
关于提供的场景,如果我们制作一个脚本:
dune exec --root=../.. ./bin/some_program.exe
(*
Where 'some_program' is the name of an .ml file located in bin folder.
I assumed here that the program is compiled to native code,not to bytecode (hence the .exe).
*)
并将其放在 examples
目录中,然后通过调用它,我们实际上将运行位于 some_program.ml
文件夹中的 bin
中定义的程序的最新版本。
为了说明清楚:bin
文件夹不包含任何编译文件(既不是 .exe 也不是 .bc)。