`just` OCaml
Richard Mortier · February 07, 2025 · #tech #code #ocamlIn similar vein to a recent post, I have also started using just
when I periodically need to rebuild my OCaml tool1 ocal
. So I ended up replacing the old Makefile
with a shiny new Justfile
.
As it also proved useful in another (more esoteric) tool I wrote for parsing out exam results for my students so I can paste into email easily, I thought I’d put it here for the record. So here it is…
Largely due to NixOS upgrades moving tools into different locations.
Usual preamble of course:
:
@just --list
Then set some common variables:
PWD := env("PWD")
DOCDIR := "_build/default/_doc/_html"
BUILDDIR := "_build/install/default/bin"
Then set the target — the tool name, in this case ocal
(so named as this is an OCaml re-implementation of a tool approximating the trad Unix cal
tool):
TARGET := "ocal"
Now for the actually useful stuff: some targets. Mostly these just call out to dune
but in a way I find more intuitive.
# build targets
:
dune build @all
# cleanup
:
dune clean
# uninstall targets
:
dune uninstall
# run any tests
:
dune runtest
# format sources
:
dune fmt
Some compound calls next.
First, before building we might need to install dependencies, so do so in the time-honoured fashion:
# install dependencies
:
opam install --yes dune-release odoc
opam install --yes . --deps-only
Next, to install I first build ready to install, then symlink the resulting binary into the right place in my home directory:
# install targets
: build
dune build @install
ln -sf / / ~/.local/bin/
To lint all the things, invoke dune
twice:
# lint everything
:
dune build @lint
dune-release lint
Similarly, to build the docs, build all the docs:
# build docs
:
dune build @doc
dune build @doc-private
Try to open the docs on Linux and if that fails, on MacOS:
# open the docs for reading
: doc
handlr open /index.html || open
Finally, tag and create a release; not actually done this in ages so no idea if dune-release
invocations are still a thing, let alone correct!
# tag and create a release
:
dune-release tag
dune-release -vv