Unikernels in OCaml

unic

A tool to infer dependencies which must be vendored for unikernels

Version
0.1.0
Kind
tool
Source
https://git.robur.coop/robur/unic
Homepage
https://git.robur.coop/robur/unic
Authors
Romain Calascibetta
Tags
workflowdependencies

unic is a tool that analyses an OCaml project in order to infer the dependencies required by that project, which must be vendored to enable the static linking of an executable/unikernel and the compilation of C source files using the correct OCaml toolchain. Its aims is to resolve the issue of how to produce a statically linked executable whose artefacts are compiled consistently. This is a particular challenge when it comes to unikernels, as the C source files must be compiled using our Solo5 toolchain (which, amongst other things, excludes the host system's standard C library).

It is a tool that does not depend on a build system (such as dune) and uses codept to infer dependencies. Let’s take this simple example:

$ cat >main.ml<<EOF
let () =
  Mirage_crypto_rng_unix.use_default ();
  let buf = Bytes.create 0x7ff in
  Mirage_crypto_rng.generate_into buf (Bytes.length buf);
  Fmt.pr "@[<hov>%a@]\n%!" (Hxd_string.pp Hxd.default)
    (Bytes.unsafe_to_string buf)
EOF
$ unic infer .

Here, unic asks you which implementation of digestif you would like. We choose digestif.c.

Module Digestif is provided by several ocamlfind packages:
  [0] digestif.c
  [1] digestif.ocaml
Pick one [0-1]: 0

It should be noted that fmt and hxd are not included amongst the dependencies to be bundled. This is simply because these libraries are implemented in pure OCaml and do not transitively depend on libraries containing C files.

digestif
mirage-crypto
mirage-crypto-rng

Next, you can save the result to a _mfetch file and use the mfetch tool to download the source code for these projects.

There are also several options available to fine-tune the resolution produced by unic: