unic
A tool to infer dependencies which must be vendored for unikernels
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]: 0It 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-rngNext, 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:
-
-r/--recursiveallows you to include all the files in the current folder and its subfolders. -
-x/--excludeallows you to exclude folders or files from the resolution (for example, it may be useful to exclude the folder where we have packaged our dependencies, as well as the_buildfolder)www -
--forbidallows you to exclude a specific module from the dependency graph. This is particularly useful for unikernels, for example, to exclude theUnixmodule. -
-p/--preferallows you to specify a ‘preferred’ library if there are several options available. For example, you could specify--prefer digestif.cin our example so that the resolver selects this dependency rather than asking you to choose.It is also possible to specify which module's library you wish to prioritise using
--prefer Digestif:digestif.c -
-i/--ignoreallows a required module to be ignored during resolution. There may be modules that are generated on the fly and are therefore not present at the time of resolution.