Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature(coq): add coqdoc_flags field to coq.theory #7676

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ Unreleased
- Load the host context `findlib.conf` when cross-compiling (#7428, fixes
#1701, @rgrinberg, @anmonteiro)

- Add a `coqdoc_flags` field to the `coq.theory` stanza allowing the user to
pass extra arguments to `coqdoc`. (#7676, fixes #7954 @Alizter)

Alizter marked this conversation as resolved.
Show resolved Hide resolved
- Resolve `ppx_runtime_libraries` in the target context when cross compiling
(#7450, fixes #2794, @anmonteiro)

Expand Down
15 changes: 14 additions & 1 deletion doc/coq.rst
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ stanza:
(modules <ordered_set_lang>)
(plugins <ocaml_plugins>)
(flags <coq_flags>)
(coqdoc_flags <coqdoc_flags>)
(stdlib <stdlib_included>)
(mode <coq_native_mode>)
(theories <coq_theories>))
Expand Down Expand Up @@ -106,6 +107,11 @@ The semantics of the fields are:
is taken from the value set in the ``(coq (flags <flags>))`` field in ``env``
profile. See :ref:`dune-env` for more information.

- ``<coqdoc_flags>`` are extra user-configurable flags passed to ``coqdoc``. The
default value for ``:standard`` is ``--toc``. The ``--html`` or ``--latex``
flags are passed separately depending on which mode is targed. See the section
on :ref:`documentation using coqdoc<coqdoc>` for more information.

- ``<stdlib_included>`` can either be ``yes`` or ``no``, currently defaulting to
``yes``. When set to ``no``, Coq's standard library won't be visible from this
theory, which means the ``Coq`` prefix won't be bound, and
Expand Down Expand Up @@ -150,6 +156,7 @@ them in the correct order, even if they are in separate theories. Under the
hood, Dune asks coqdep how to resolve these dependencies, which is why it is
called once per theory.

.. _coqdoc:

Coq Documentation
~~~~~~~~~~~~~~~~~
Expand All @@ -161,7 +168,13 @@ A.tex``, respectively (if the :ref:`dune file<dune-files>` for the theory is the
current directory).

There are also two aliases ``@doc`` and ``@doc-latex`` that will respectively
build the HTML or LaTeX documentation when called.
build the HTML or LaTeX documentation when called. These will determine whether
or not Dune passes a ``--html`` or ``--latex`` flag to ``coqdoc``.

Further flags can also be configured using the ``(coqdoc_flags)`` field in the
``coq.theory`` stanza. These will be passed to ``coqdoc`` and the default value
is ``:standard`` which is ``--toc``. Extra flags can therefore be passed by
writing ``(coqdoc_flags :standard --body-only)`` for example.

.. _include-subdirs-coq:

Expand Down
11 changes: 10 additions & 1 deletion src/dune_rules/coq/coq_rules.ml
Original file line number Diff line number Diff line change
Expand Up @@ -602,8 +602,17 @@ let setup_coqdoc_rules ~sctx ~dir ~theories_deps (s : Coq_stanza.Theory.t)
| `Html -> "--html"
| `Latex -> "--latex"
in
let extra_coqdoc_flags =
(* Standard flags for coqdoc *)
let standard = Action_builder.return [ "--toc" ] in
let open Action_builder.O in
let* expander =
Action_builder.of_memo @@ Super_context.expander sctx ~dir
in
Expander.expand_and_eval_set expander s.coqdoc_flags ~standard
in
[ Command.Args.S file_flags
; A "--toc"
; Command.Args.dyn extra_coqdoc_flags
; A mode_flag
; A "-d"
; Path (Path.build doc_dir)
Expand Down
8 changes: 7 additions & 1 deletion src/dune_rules/coq/coq_stanza.ml
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ module Theory = struct
; boot : bool
; enabled_if : Blang.t
; buildable : Buildable.t
; coqdoc_flags : Ordered_set_lang.Unexpanded.t
}

let coq_public_decode =
Expand Down Expand Up @@ -186,7 +187,11 @@ module Theory = struct
field_b "boot" ~check:(Dune_lang.Syntax.since coq_syntax (0, 2))
and+ modules = Stanza_common.modules_field "modules"
and+ enabled_if = Enabled_if.decode ~allowed_vars:Any ~since:None ()
and+ buildable = Buildable.decode in
and+ buildable = Buildable.decode
and+ coqdoc_flags =
Ordered_set_lang.Unexpanded.field "coqdoc_flags"
~check:(Dune_lang.Syntax.since coq_syntax (0, 8))
in
(* boot libraries cannot depend on other theories *)
check_boot_has_no_deps boot buildable;
let package = merge_package_public ~package ~public in
Expand All @@ -198,6 +203,7 @@ module Theory = struct
; boot
; buildable
; enabled_if
; coqdoc_flags
})

type Stanza.t += T of t
Expand Down
1 change: 1 addition & 0 deletions src/dune_rules/coq/coq_stanza.mli
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ module Theory : sig
; boot : bool
; enabled_if : Blang.t
; buildable : Buildable.t
; coqdoc_flags : Ordered_set_lang.Unexpanded.t
}

type Stanza.t += T of t
Expand Down