|
| 1 | +--- |
| 2 | +id: "unikernel-target" |
| 3 | +short_title: "Unikernels" |
| 4 | +title: "Compilation Targets: Unikernels" |
| 5 | +description: "Compile OCaml to specialised unikernel targets using MirageOS. Create minimal, fast-booting applications for hvt, virtio, Xen, and more with reduced attack surfaces." |
| 6 | +category: "Compilation Targets" |
| 7 | +--- |
| 8 | + |
| 9 | +OCaml can compile to specialised unikernel targets through [MirageOS](https://mirage.io), a library operating system that creates secure, single-purpose applications. |
| 10 | + |
| 11 | +## What are Unikernels? |
| 12 | + |
| 13 | +Unikernels are specialised, single-purpose virtual machine images that bundle your application with only the minimal OS functionality it needs. Unlike traditional applications that run on general-purpose operating systems, unikernels: |
| 14 | + |
| 15 | +- Include only the necessary OS components, resulting in tiny footprints (often just a few megabytes) |
| 16 | +- Boot in milliseconds |
| 17 | +- Have reduced attack surfaces due to minimal code |
| 18 | +- Run directly on hypervisors or specialised monitor layers |
| 19 | + |
| 20 | +MirageOS lets you write OCaml applications once and deploy them as unikernels to different virtualisation platforms. |
| 21 | + |
| 22 | +## Available Targets |
| 23 | + |
| 24 | +MirageOS supports compilation to several unikernel backends: |
| 25 | + |
| 26 | +### Solo5 Targets |
| 27 | + |
| 28 | +[Solo5](https://github.com/Solo5/solo5) is a sandboxed execution environment that provides multiple deployment options: |
| 29 | + |
| 30 | +- **hvt** (Hardware Virtualized Tender) - Runs on KVM/Linux, bhyve/FreeBSD, and vmm/OpenBSD with minimal overhead |
| 31 | +- **spt** (Sandboxed Process Tender) - Runs as a regular Unix process with seccomp sandboxing on Linux |
| 32 | +- **virtio** - Runs on standard virtio-based hypervisors including QEMU/KVM, Google Compute Engine, and OpenStack |
| 33 | +- **muen** - Runs on the Muen Separation Kernel |
| 34 | +- **xen** - Runs on the Xen hypervisor as a paravirtualised guest (PVHv2 mode) |
| 35 | + |
| 36 | +### Unikraft Targets |
| 37 | + |
| 38 | +[Unikraft](https://unikraft.org) is a general Unikernel Development Kit that can be used as a MirageOS backend: |
| 39 | + |
| 40 | +- **unikraft-qemu** - Runs on the [QEMU](https://www.qemu.org/) virtual machine monitor |
| 41 | +- **unikraft-firecracker** - Runs on the [Firecracker](https://firecracker-microvm.github.io/) virtual machine monitor |
| 42 | + |
| 43 | +### Unix |
| 44 | + |
| 45 | +- **unix** - Runs as a standard Unix process (useful for development and testing) |
| 46 | + |
| 47 | +## Choosing a Target |
| 48 | + |
| 49 | +**Use Unix** when you're developing and testing your unikernel locally. |
| 50 | + |
| 51 | +**Use hvt** when you want lightweight virtualisation on Linux, FreeBSD, or OpenBSD with KVM, bhyve, or vmm. |
| 52 | + |
| 53 | +**Use virtio** when deploying to cloud providers like Google Compute Engine, or standard KVM/QEMU setups. |
| 54 | + |
| 55 | +**Use spt** when you want process-level isolation on Linux without full virtualisation. |
| 56 | + |
| 57 | +**Use Xen** when deploying to Xen-based infrastructure or cloud providers that support Xen. |
| 58 | + |
| 59 | +**Use Unikraft targets** when you want to use the Unikraft unikernel framework with QEMU or Firecracker. |
| 60 | + |
| 61 | +## Getting Started |
| 62 | + |
| 63 | +To start building unikernels with OCaml, visit the [MirageOS Getting Started Guide](https://mirage.io/docs/). The guide walks you through: |
| 64 | + |
| 65 | +- Installing the MirageOS tooling |
| 66 | +- Creating your first unikernel application |
| 67 | +- Configuring and building for different targets |
| 68 | +- Deploying your unikernel |
| 69 | + |
| 70 | +## Learn More |
| 71 | + |
| 72 | +- [Dune Manual: Executable Linking Modes](https://dune.readthedocs.io/en/stable/reference/dune/executable.html#linking-modes) - How to specify native, bytecode, or other compilation modes in Dune |
| 73 | +- [MirageOS Documentation](https://mirage.io/docs/) - Comprehensive guides and tutorials |
| 74 | +- [MirageOS Blog](https://mirage.io/blog/) - Updates and advanced topics |
| 75 | +- [Solo5 Documentation](https://github.com/Solo5/solo5) - Details on Solo5 targets and deployment |
| 76 | +- [MirageOS Examples](https://github.com/mirage/mirage-skeleton) - Sample unikernel applications to explore |
| 77 | + |
| 78 | +## Community |
| 79 | + |
| 80 | +- [Discuss OCaml Forums](https://discuss.ocaml.org/) - Ask questions in the Ecosystem category |
| 81 | +- [MirageOS Mailing List](https://lists.xenproject.org/cgi-bin/mailman/listinfo/mirageos-devel) - Development discussions |
| 82 | +- IRC: `#mirage` on Libera.Chat |
0 commit comments