Thicket data repository for the EEG
at main 11 kB view raw
1{ 2 "id": "https://mort.io/blog/just-ocaml/", 3 "title": "`just` OCaml", 4 "link": "https://mort.io/blog/just-ocaml/", 5 "updated": "2025-02-07T00:00:00", 6 "published": "2025-02-07T00:00:00", 7 "summary": "<p>In similar vein to a <a href=\"https://mort.io/blog/just-latex\">recent post</a>, I have also started using\n<a href=\"https://just.systems/\"><code>just</code></a> when I periodically need to rebuild my\n<a href=\"https://ocaml.org/\">OCaml</a> tool<a href=\"https://mort.io/blog/just-ocaml/#1\">1</a> <a href=\"https://github.com/mor1/ocal\"><code>ocal</code></a>. So\nI ended up replacing the old\n<a href=\"https://github.com/mor1/ocal/blob/6bb129627f9d1f27ab31cee810013b362ab80067/Makefile\"><code>Makefile</code></a>\nwith a shiny new\n<a href=\"https://github.com/mor1/ocal/blob/8ef8631ae5bbe0315e359d725d467e7d0403fd31/Justfile\"><code>Justfile</code></a>.</p>\n<p>As it also proved useful in another (more esoteric) tool I wrote <a href=\"https://github.com/mor1/cst-tools\">for parsing\nout exam results for my students so I can paste into email\neasily</a>, I thought I’d put it here for the\nrecord. So here it is…</p>\n<div>1\n<p>Largely due to <a href=\"https://nixos.org/\">NixOS</a> upgrades moving tools into\ndifferent locations.</p>\n</div>\n<p>Usual preamble of course:</p>\n<pre><code><span><span><span>_default</span></span>:\n</span><span> <span>@</span>just --list\n</span></code></pre>\n<p>Then set some common variables:</p>\n<pre><code><span><span>PWD</span> <span>:=</span> <span>env</span><span>(</span><span><span>&quot;</span>PWD<span>&quot;</span></span>)\n</span><span><span>DOCDIR</span> <span>:=</span> <span><span>&quot;</span>_build/default/_doc/_html<span>&quot;</span></span>\n</span><span><span>BUILDDIR</span> <span>:=</span> <span><span>&quot;</span>_build/install/default/bin<span>&quot;</span></span>\n</span></code></pre>\n<p>Then set the target — the tool name, in this case <code>ocal</code> (so named as this is\nan OCaml re-implementation of a tool approximating the trad Unix\n<a href=\"https://en.wikipedia.org/wiki/Cal_(command)\"><code>cal</code></a> tool):</p>\n<pre><code><span><span>TARGET</span> <span>:=</span> <span><span>&quot;</span>ocal<span>&quot;</span></span>\n</span></code></pre>\n<p>Now for the actually useful stuff: some targets. Mostly these just call out to\n<code>dune</code> but in a way I find more intuitive.</p>\n<pre><code><span><span><span># </span>build targets</span>\n</span><span><span><span>build</span></span>:\n</span><span> dune build @all\n</span><span>\n</span><span><span><span># </span>cleanup</span>\n</span><span><span><span>clean</span></span>:\n</span><span> dune clean\n</span><span>\n</span><span><span><span># </span>uninstall targets</span>\n</span><span><span><span>uninstall</span></span>:\n</span><span> dune uninstall\n</span><span>\n</span><span><span><span># </span>run any tests</span>\n</span><span><span><span>test</span></span>:\n</span><span> dune runtest\n</span><span>\n</span><span><span><span># </span>format sources</span>\n</span><span><span><span>format</span></span>:\n</span><span> dune fmt\n</span></code></pre>\n<p>Some compound calls next.</p>\n<p>First, before building we might need to install dependencies, so do so in the\ntime-honoured fashion:</p>\n<pre><code><span><span><span># </span>install dependencies</span>\n</span><span><span><span>depends</span></span>:\n</span><span> opam install --yes dune-release odoc\n</span><span> opam install --yes . --deps-only\n</span></code></pre>\n<p>Next, to install I first build ready to install, then symlink the resulting\nbinary into the right place in my home directory:</p>\n<pre><code><span><span><span># </span>install targets</span>\n</span><span><span><span>install</span></span>: build\n</span><span> dune build @install\n</span><span> ln -sf <span><span>{{</span><span>PWD</span><span>}}</span></span>/<span><span>{{</span><span>BUILDDIR</span><span>}}</span></span>/<span><span>{{</span><span>TARGET</span><span>}}</span></span> ~/.local/bin/\n</span></code></pre>\n<p>To lint all the things, invoke <code>dune</code> twice:</p>\n<pre><code><span><span><span># </span>lint everything</span>\n</span><span><span><span>lint</span></span>:\n</span><span> dune build @lint\n</span><span> dune-release lint\n</span></code></pre>\n<p>Similarly, to build the docs, build <em>all</em> the docs:</p>\n<pre><code><span><span><span># </span>build docs</span>\n</span><span><span><span>doc</span></span>:\n</span><span> dune build @doc\n</span><span> dune build @doc-private\n</span></code></pre>\n<p>Try to open the docs on Linux and if that fails, on MacOS:</p>\n<pre><code><span><span><span># </span>open the docs for reading</span>\n</span><span><span><span>read</span></span>: doc\n</span><span> handlr open <span><span>{{</span><span>DOCDIR</span><span>}}</span></span>/index.html || open <span><span>{{</span><span>DOCDIR</span><span>}}</span></span>\n</span></code></pre>\n<p>Finally, tag and create a release; not actually done this in ages so no idea if\n<code>dune-release</code> invocations are still a thing, let alone correct!</p>\n<pre><code><span><span><span># </span>tag and create a release</span>\n</span><span><span><span>release</span></span>:\n</span><span> dune-release tag\n</span><span> dune-release -vv\n</span></code></pre>", 8 "content": "<p>In similar vein to a <a href=\"https://mort.io/blog/just-latex\">recent post</a>, I have also started using\n<a href=\"https://just.systems/\"><code>just</code></a> when I periodically need to rebuild my\n<a href=\"https://ocaml.org/\">OCaml</a> tool<a href=\"https://mort.io/blog/just-ocaml/#1\">1</a> <a href=\"https://github.com/mor1/ocal\"><code>ocal</code></a>. So\nI ended up replacing the old\n<a href=\"https://github.com/mor1/ocal/blob/6bb129627f9d1f27ab31cee810013b362ab80067/Makefile\"><code>Makefile</code></a>\nwith a shiny new\n<a href=\"https://github.com/mor1/ocal/blob/8ef8631ae5bbe0315e359d725d467e7d0403fd31/Justfile\"><code>Justfile</code></a>.</p>\n<p>As it also proved useful in another (more esoteric) tool I wrote <a href=\"https://github.com/mor1/cst-tools\">for parsing\nout exam results for my students so I can paste into email\neasily</a>, I thought I’d put it here for the\nrecord. So here it is…</p>\n<div>1\n<p>Largely due to <a href=\"https://nixos.org/\">NixOS</a> upgrades moving tools into\ndifferent locations.</p>\n</div>\n<p>Usual preamble of course:</p>\n<pre><code><span><span><span>_default</span></span>:\n</span><span> <span>@</span>just --list\n</span></code></pre>\n<p>Then set some common variables:</p>\n<pre><code><span><span>PWD</span> <span>:=</span> <span>env</span><span>(</span><span><span>&quot;</span>PWD<span>&quot;</span></span>)\n</span><span><span>DOCDIR</span> <span>:=</span> <span><span>&quot;</span>_build/default/_doc/_html<span>&quot;</span></span>\n</span><span><span>BUILDDIR</span> <span>:=</span> <span><span>&quot;</span>_build/install/default/bin<span>&quot;</span></span>\n</span></code></pre>\n<p>Then set the target — the tool name, in this case <code>ocal</code> (so named as this is\nan OCaml re-implementation of a tool approximating the trad Unix\n<a href=\"https://en.wikipedia.org/wiki/Cal_(command)\"><code>cal</code></a> tool):</p>\n<pre><code><span><span>TARGET</span> <span>:=</span> <span><span>&quot;</span>ocal<span>&quot;</span></span>\n</span></code></pre>\n<p>Now for the actually useful stuff: some targets. Mostly these just call out to\n<code>dune</code> but in a way I find more intuitive.</p>\n<pre><code><span><span><span># </span>build targets</span>\n</span><span><span><span>build</span></span>:\n</span><span> dune build @all\n</span><span>\n</span><span><span><span># </span>cleanup</span>\n</span><span><span><span>clean</span></span>:\n</span><span> dune clean\n</span><span>\n</span><span><span><span># </span>uninstall targets</span>\n</span><span><span><span>uninstall</span></span>:\n</span><span> dune uninstall\n</span><span>\n</span><span><span><span># </span>run any tests</span>\n</span><span><span><span>test</span></span>:\n</span><span> dune runtest\n</span><span>\n</span><span><span><span># </span>format sources</span>\n</span><span><span><span>format</span></span>:\n</span><span> dune fmt\n</span></code></pre>\n<p>Some compound calls next.</p>\n<p>First, before building we might need to install dependencies, so do so in the\ntime-honoured fashion:</p>\n<pre><code><span><span><span># </span>install dependencies</span>\n</span><span><span><span>depends</span></span>:\n</span><span> opam install --yes dune-release odoc\n</span><span> opam install --yes . --deps-only\n</span></code></pre>\n<p>Next, to install I first build ready to install, then symlink the resulting\nbinary into the right place in my home directory:</p>\n<pre><code><span><span><span># </span>install targets</span>\n</span><span><span><span>install</span></span>: build\n</span><span> dune build @install\n</span><span> ln -sf <span><span>{{</span><span>PWD</span><span>}}</span></span>/<span><span>{{</span><span>BUILDDIR</span><span>}}</span></span>/<span><span>{{</span><span>TARGET</span><span>}}</span></span> ~/.local/bin/\n</span></code></pre>\n<p>To lint all the things, invoke <code>dune</code> twice:</p>\n<pre><code><span><span><span># </span>lint everything</span>\n</span><span><span><span>lint</span></span>:\n</span><span> dune build @lint\n</span><span> dune-release lint\n</span></code></pre>\n<p>Similarly, to build the docs, build <em>all</em> the docs:</p>\n<pre><code><span><span><span># </span>build docs</span>\n</span><span><span><span>doc</span></span>:\n</span><span> dune build @doc\n</span><span> dune build @doc-private\n</span></code></pre>\n<p>Try to open the docs on Linux and if that fails, on MacOS:</p>\n<pre><code><span><span><span># </span>open the docs for reading</span>\n</span><span><span><span>read</span></span>: doc\n</span><span> handlr open <span><span>{{</span><span>DOCDIR</span><span>}}</span></span>/index.html || open <span><span>{{</span><span>DOCDIR</span><span>}}</span></span>\n</span></code></pre>\n<p>Finally, tag and create a release; not actually done this in ages so no idea if\n<code>dune-release</code> invocations are still a thing, let alone correct!</p>\n<pre><code><span><span><span># </span>tag and create a release</span>\n</span><span><span><span>release</span></span>:\n</span><span> dune-release tag\n</span><span> dune-release -vv\n</span></code></pre>", 9 "content_type": "html", 10 "author": { 11 "name": "Unknown", 12 "email": null, 13 "uri": null 14 }, 15 "categories": [], 16 "source": "https://mort.io/atom.xml" 17}