dune icon indicating copy to clipboard operation
dune copied to clipboard

Support odoc 3's hierarchy when installing files

Open panglesd opened this issue 7 months ago • 2 comments

Hello!

This PR is about adding dune support for odoc 3's new hierarchy. To recall briefly, odoc 3 can be driven to generate a hierarchy of mld (and asset) files. When building docs for installed packages (as odig or ocaml.org do), the odoc driver gets the intended hierarchy from the hierarchy of files and folders in <switch root>/doc/odoc-pages/. See #11620.

To support this, dune needs to:

  1. Provide a way for the author to specify the hierarchy,
  2. Install the files according to this hierarchy,
  3. Drive odoc according to this hierarchy.

This PR tackles the first two points, through the introduction of the files field in the documentation stanza. It is the same field as the one in the install stanza.

The third point is not tackled at all, but the user is warned that some files are ignored until the support for 3. is added.

I hope the added test and documentation are clear enough!

It may make sense to also add other fields from install, such as dirs and source_trees, but I'd prefer to start with a simpler PR, which contains most of the value anyway.

Also, I'd like to extend dune init proj to contain a doc/ folder, with a toplevel dune adding the whole doc/ as documentation. I believe this would encourage library authors to write mld files, such introduction/examples/tutorials more. What do you think?

Thanks!

(Note that this is independent from #11716.)

panglesd avatar May 13 '25 15:05 panglesd

Small :ping_pong: @rgrinberg @Leonidas-from-XIV as this PR is ready for review. (Sorry if I'm pinging the wrong person!)

I think I'll make a more practical description of what is in this PR, than my intro message:

This PR adds a (files ...) field to the (documentation ...) stanza. This fields has the same syntax as the files field from the install stanza.

The listed files are installed relative to doc/<pkgname>/odoc-pages/. If they have mld extensions, they are also considered as pages by dune when building the docs (although, dune build @doc will ignore the files that are in subfolders for now as it does not support that odoc 3 feature yet).

A simple example of usage of the new file field is:

(documentation
 (files
  (glob_files_rec
   (doc/* with_prefix .))))

which installs all files from the doc folder in doc/<pkgname>/odoc-pages/, respecting the relative hierarchy.

panglesd avatar Jun 11 '25 12:06 panglesd

I'll try reviewing this week

rgrinberg avatar Jun 17 '25 22:06 rgrinberg

CI seems to be failing. @panglesd could you have a look?

rgrinberg avatar Jun 27 '25 22:06 rgrinberg