Developing Coq plugins and libraries using Dune as their build system does offer some extra features and flexibility when compared to the traditional coq_makefile
setup:
- compositional build: you can drop your plugin inside the
coq
folder or thecoq
folder inside your plugin’s and Dune will know how to build them together in one go. That leads to significantly shorter edit/compile cycles, - Dune extra features: for example
dune build @check
,dune utop
, ordune build -w
, - easy linking with external packages or C libraries: using the standard Dune toolset.
In order to get started with Dune, you must add dune
and dune-project
files to your plugin. Typical content of the dune
file is:
(library
(name equations_plugin)
(public_name equations.plugin)
(libraries coq.stm))
This will properly compile the OCaml files. If you have some mlg
grammar files, you must add rules to process them:
(coq.pp (modules g_equations))
dune-project
helps determine the root directory of the project and typically contains something such as:
(lang dune 2.0)
(name equations)
The above does take care of the ML part, starting with Dune 1.9, support for .v -> .vo
file compilation has also been added. In order to enable the compilation of Coq files, you should add to your dune-project
file:
(using coq 0.1)
that will enable a (coq.theory ...)
stanza; typical use is:
(coq.theory
; This determines the -R flag
(name Equations)
(package equations)
(synopsis "Equations Plugin")
(libraries coq.plugins.extraction equations.plugin)
(modules :standard \ IdDec NoCycle))
(include_subdirs qualified)
Note that the .v
files can depend on the ML plugin, this will rebuild everything correctly!
There is an ongoing template here https://github.com/ejgallego/coq-plugin-template
For now, the official documentation resources are:
- https://dune.readthedocs.io/en/stable/dune-files.html#coq-theory
- https://coq.github.io/doc/master/refman/practical-tools/utilities.html#building-a-coq-project-with-dune
- A guide to building your Coq libraries and plugins with Dune
- https://github.com/ejgallego/coq-plugin-template
help us to make them better!