Conversation
|
Nice! :O What's the list of path for in the configure target ? Could we make the definition easier in case where they are no path (which seems common given the diff). |
That's the list of files generated when running |
|
Maybe we could only annotate the external commands and infer as much as we can ? |
|
We will also need to check that the list of generated files is static (e.g. doesn't depend on the result/stdout of external commands) which might be a pain. I'll have a look. |
|
I've reverted back to inferring files in configure actions -- most of the time it will just use work so let's make this the default. If for any reason this doesn't work, users can provide their own list of files with |
|
Sounds good! |
|
I've added a bit of documentation in the mlis (and in the initial body of that PR). I think this is now ready to review! Right now I managed to build mirage-skeleton's |
|
I tried your instructions on a mirage-skeleton hello example. My initial observations:
and I've no idea how to continue from here -- maybe the way out is |
|
ok, after a manual wipe of the repository - and running mirage configure ; duniverse again, I got to a point where "dune build hello.hvt" does some work, and then fails with "spt/spt_core.c:37:10: fatal error: 'seccomp.h' file not found" (and still no hello.hvt :/) |
88465cd to
b029c88
Compare
As unirkernels do not depend on mirage-types inconditionnaly anymore, every device needs to be more precise about the signatures they require.
|
@TheLortex do you have an open PR which subsumes this one? |
|
As far as I can know, the status of MirageOS is available here: TheLortex#1 |
|
Hey, I'll make a proper PR tomorrow, the most up to date branch is https://github.com/TheLortex/mirage/tree/mirage-4-upstream based on @dinosaure 's PR on my repo. |
|
No hurry -- I'll wait for your PR before closing this one then :-) |
|
Closing in favor of #1226 |
MirageOS 4
What is MirageOS?
MirageOS is a library operating system that can build standalone unikernels on various platforms. More precisely, the architecture can be divided into:
operating system libraries that implement kernel and protocol functionality, ranging from low-level network card drivers to a full reimplementation of the TLS protocol, through to a reimplementation of the Git protocol to store versioned data.
A set of typed signatures to make sure these libraries are consistent and can interoperate. As all the library are almost all pure OCaml code, we have defined a set of OCaml module types that encode these conventions in a statically enforcable way. We make no compatibility guarantees at the C level, but compile those on a best-effort basis.
Finally, MirageOS is also a metaprogramming compiler that generates OCaml code. It takes as input: the OCaml source code of a program and all of its dependencies, the full description of
the deployment target, including configuration values (like the HTTP port to listen too, or the private key or the service being deployed). The
mirageCLI tool uses all of these to generate a executable unikernel: a specialised binary artefact containing only the code what is needed to run on the given deployment platform and no more.It is possible to write high-level MirageOS applications, such as HTTPS, email or CalDAV servers which can be deployed on very heterogenous and embedded platforms by changing only a few compilation parameters. The supported platforms range from ESP32 micro-controllers, minimal virtual machines running on a cloud providers, or processes running inside a Docker container configured with a tight security profile. In general, these platform do not have a full POSIX environment; MirageOS does not try to emulate POSIX and focuses on providing a small, well-defined, typed interface with the system components. The nearest equivalent to the MirageOS approach is the WASI (wasi.dev) set of interfaces for WebAssembly.
Is everything really written in OCaml
While most of the code is written in OCaml, a typed, high-level language with many good safety properties, there are pieces of MirageOS which are still written in unsafe C. These bits can be
separated in three categories:
The OCaml runtime is written in C. It needs to be ported to the platform that MirageOS is trying to target, which do not support POSIX. Hence, the first component to port to a new platform is the OCaml runtime.
The low-level device drivers (network, console, clock, etc) also need some C bits.
The base usual C bindings; some libraries are widely used and (unfortunately) very hard (but not impossible) to replace them completely without taking a big performance hit or having to trust code without much real-world usages. This is the case for low-level bit handling for crypto code (even if we try to make sure allocation is alway handled by the OCaml runtime) as well as arbitrary precision numeric computation (e.g. gmp). Ideally we could image rewriting all of these libraries in OCaml if we had an infinite amount of time in our hands.
MirageOS as a cross-compilator
The MirageOS compiler is basically a cross-compiler, where the host and target toolchain are identical, but with different flags for the C bindings: for instance, it is necessary to pass
-freestandingto all C bindings to not use POSIX headers. The MirageOS compiler also uses a custom linker: eg. not only it needs a custom OCaml's runtimelibasmrun.a, but it also needs to run a different linker to generate specialised executable images.Historically, the OCaml ecosystem always had partial support for cross-compilation: for instance, the ocaml-cross way of doing it is to duplicate all existing opam pacakges by adding a
-windowssuffix to their names and dependencies; this allows normal packages and windows packages can be co-installed in the same opam switch.MirageOS 3 resolved that by duplicating only the packages defining C bindings and (ab)using ocamlfind predicates to resolve link time depencencies for C archives and on relying on the now deprecated
--output-objoption of the OCaml compiler.The proposal for MirageOS 4 is to solve this issue via the built-in support for cross-compilation of
dune. This is done by gathering all the sourceslocally, creating adune-workspacefile describing the C flags to use in each cross-compilation "context" and then callduneonce.An example: solo5
The current prototype is using
duniverseto gather all sources and can be tested as follows:Current limitations:
enabled_iftoinstallstanzas and enforce variable restrictions ocaml/dune#3408 to makedune buildjust workPossible improvements:
mirage execto replace the last line?note: this PR builds on the amazing work done by @TheLortex @dinosaure who worked on various iterations of this patch over the last 2 years.