Unic, a way to infer dependencies from an OCaml project

unic is a project that enables the analysis of an OCaml project (without relying on any particular build system such as dune) in order to construct a dependency graph for that project within a given context (such as that provided by opam). In this way, it is possible to identify dependencies that require object files which may have been compiled using what is known as the "host toolchain".

The aim is therefore to identify these dependencies and determine which opam packages they originate from, so as to inform the user what might need to be recompiled if they wish to build the project using a different "toolchain".

In this case, it is a solution that works well whenever one wishes to compile a unikernel using the Solo5 toolchain. Let us take the example of immuable. This project provides a unikernel as well as an executable (which should not be compiled with the Solo5 toolchain). One of the artefacts required for the unikernel is Documents, which is generated by mcrunch. You can then infer the dependencies and determine what needs to be recompiled using:

$ opam pin add https://git.robur.coop/robur/unic -y
$ git clone https://github.com/dinosaure/immuable
$ cd immuable
$ unic infer --recurse . --toolchain solo5 --exclude bin/ --ignore Documents \
  --prefer digestif.c --prefer checkseum.c
angstrom
bigstringaf
bin
bstr
cachet
carton
checkseum
cstruct
decompress
digestif
encore
faraday
fluxt
gmp
...

All that remains is for the user to find a way to recompile these opam packages using the Solo5 toolchain. If these packages use dune, simply vendorise them (i.e. retrieve them using opam source and specify a directory containing their source code using (vendored_dirs ...)).

Some other tools

unic offers other tools that can help you understand a project: