Building project for release and adding manpages with cmdliner

Hey!

I have my project setup with dune and use it to generate my .opam file.

Now I’d like to do my first release of my package, and so I’m trying to figure out how to setup dune for building a release with manpages included.

When I run dune build *.opam, it generates an opam file for me with build instructions that are later on used by nix to build my project.

Since I use cmdliner to generate my man pages, they are not generated in the default command, which is

build: [
  ["dune" "subst"] {dev}
  [
    "dune"
    "build"
    "-p"
    name
    "-j"
    jobs
    "@install"
    "@runtest" {with-test}
    "@doc" {with-doc}
  ]
]

I also notice that it’s not using the release profile, which I’d like to use.

So my questions are:

  • How can I specify dune-project to generate a opam file where it uses the release profile for building the project?

  • When running dune build, how do I also include manpages that are generated with cmdliner and package these together in the final result (I.E. binary under /bin and manpages under /man).

1 Like

For your first point, dune will automatically use the release profile when compiling and installing as part of an opam package (if I recall correctly, that’s set by the -p option).

On to your second point, I have used the following rules in a dune file to make dune generate and install man pages (for a project that uses cmdliner).

4 Likes

Wow this is great! Thank you.

I was also able to explicitly add the --profile flag by adding an overwrite in projectname.opam.template with my own build step.

1 Like

So this worked fine with dynamic bindings. But I’ve tried again now with static bindings and I’m getting the error

File "bin/dune", line 18, characters 0-99:
18 | (rule
19 |   (target        prgm.1)
20 |   (action (with-outputs-to %{target} (run prgm --help=groff)))
21 | )
Command exited with code 2.

Kinda curious if anyone knows what’s up.

EDIT:

I was able to resolve it! The following worked for me:

(rule
  (target prgn.1)
  (action (with-stdout-to %{target} (run prgn --help=groff)))
)