[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [MirageOS-devel] Using Ocaml math libraries in MirageOS?

Hi Seamus,

Firs, thank you to your interest about MirageOS :) !

The current status of MirageOS (Mirage 3.6) has a way to integrate C code into an unikernel. Currently, we have some examples about that:
https://github.com/mirage/checkseum.git (checksum implementation in C and in OCaml)
https://github.com/mirage/digestif.git (hash implementation in C and in OCaml)

The way is to compile a C library (*.a) with some specific flags. These flags are available with `pkg-config`. So about compilation, when we call `ocamlopt` (with `dune`) to compile C code, we give some flags by this way:

(library (name myclib_xen) (public_name myclib.xen) (c_names myclib) (c_flags (:include cflags.sexp)))

In this example, `dune` needs two files. First, the `myclib.c` which will contains C code. Then, `cflags.sexp` which can be generated by a shell-script:

flags=$(pkg-config --static mirage-xen-posix --cflags)
echo "($flags)"

Then, your can wrap this C library with a fancy OCaml library. At the final step, your OCaml library must provide a specific META file like:

archive(native) = "myocamllib.cmxa"
xen_linkopts = "-l:myocamllib/myclib_xen.a"

At the end, on your config.ml, you should just ask to depend on `myclib`. `ocamlbuild`/`ocamlfind` will take care to take `myclib.xen` if you want to compiler an unikernel for Xen. For other target like HVT/KVM/Solo5, it's pretty the same process but with `ocaml-freestanding` instead `mirage-xen-posix`.
However, the C library should be constrained by some details. The biggest one is about the C standard library which does not properly exist as we expect into an unikernel. So many symbols don't exist and at the link-time of your unikernel (only if the target is Xen or HVT/KVM), you should have some troubles.
The way to fix them is to copy/paste implementations if symbols are really needed (like what we did for checkseum about size_t and ptrdiff_t) or remove them.

This is a reason of why we want to remake all the wheel in OCaml ;) !

So I mostly showed how to link with a C library but about FORTRAN, I don't really know to do that ... So it's may be interesting to start with Owl which is a project born in OCamllabs and whose creator (to my knowledge) kept in his mind MirageOS and its constraints.
`checkseum` is a good project and small project to have a good skeleton about C stubs and MirageOS.

Le ven. 13 sept. 2019 à 22:25, Seamus Brady <seamus@xxxxxxxxxxxx> a écrit :
Hi folks

Excuse the basic question, I am looking into the feasibility of using a MirageOS unikernel for some development work.
However this will require the use of some of the Ocaml maths libraries such as Lacaml or Owl.
I can see there is a list of Ocaml packages that seem to work out of the box with MirageOS.
However I cannot find any documentation about whether arbitrary Ocaml libraries can be compiled into a unikernel or how one would manage any dependencies these libraries might have (such as BLAS or LAPACK in the case of Lacaml).

Could anyone speculate as to whether this is possible or even worthwhile?
I think an MirageOS unikernel with some some Linear Algebra support would be most interesting.

Thanks in advance


MirageOS-devel mailing list

Romain Calascibetta - http://din.osau.re/
MirageOS-devel mailing list



Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.