DEV Community

Yawar Amin
Yawar Amin

Posted on • Edited on

Tagging OCaml packages

TL;DR

Add (tags (org:your-github-username)) to your dune-project file's package stanza.

About

OCAML's opam package manager has an unfortunately little-known feature calling 'tagging'. This allows you to give 'tags' or 'labels' to your packages and search using those tags. This works a lot like popular blogging platforms, like dev.to in fact! And even better, the OCaml.org website package search can already search for tags: https://ocaml.org/packages/search?q=tag:%22org:erratique%22

That's an example of searching for the org:erratique tag, which will find all packages by Daniel Bünzli, who meticulously tags his OCaml packages. In fact the org: prefix for tags is specifically reserved for the 'organization' (or person) who publishes the package: https://opam.ocaml.org/doc/Manual.html#opamfield-tags

How to tag

If you are using the dune build system, add the tag(s) to your dune-project file's package stanza. E.g.:


(package
 (name dream-html)
 (synopsis "HTML generator eDSL for Dream")
 (description
  "Write HTML directly in your OCaml source files with editor support.")
 (documentation "https://yawaramin.github.io/dream-html/")
 (tags (org:yawaramin))
 (depends
  (dream
   (>= 1.0.0~alpha3))))
Enter fullscreen mode Exit fullscreen mode

Of course, you can add multiple tags, e.g. (tags (tag1 tag2 tag3)). Refer to https://dune.readthedocs.io/en/stable/dune-files.html#field-package-tags for the documentation.

Make sure you run dune build so that dune regenerates the package's opam file. Now, commit these changes and the next time you publish your package on opam, these tags will appear and be searchable, e.g. https://ocaml.org/packages/search?q=tag:%22org:your-github-username%22

Namespacing

You might have realized that I am specifically recommending adding the org: tag with high priority, because it enables an ad-hoc form of namespacing. The opam registry doesn't auto-enforce namespacing, of course, but you can always appeal to the registry maintainers if you think someone is squatting on your namespace.

Searchability

Of course, namespacing is not the only benefit–you also improve the searchability of the opam registry by adding this metadata to your projects. For example, if people are looking for web-related projects, they might search for tag:"web" etc. This will benefit the entire OCaml ecosystem. And even better, it's really easy to do.

Top comments (0)