Building the Xen compiler
This topic is not available in the selected language or version. Showing the start of this section.
Xen’s compiler is an OCaml executable. Its host architecture is independent of the architecture of programs generated by Xen.
To use a released compiler, follow installation for .deb
and tar.gz packages. This guide covers building the compiler from source.
| Build environment | OCaml needed |
|---|---|
| Linux x86_64, building an x86_64 compiler | Native x86_64 OCaml |
| Linux AArch64, building an AArch64 compiler | Native AArch64 OCaml |
| Linux x86_64, building an AArch64 compiler | Native x86_64 OCaml and an AArch64 cross OCaml toolchain |
Cross OCaml runs on the build host and emits code for another CPU. Installing an AArch64-native OCaml executable on x86_64 does not provide that cross toolchain. See AArch64 cross compilation.
Prerequisites
Section titled “Prerequisites”- Native OCaml with
ocamlcandocamloptonPATH; OCaml 5.5.0 is the reference toolchain. - Dune 3.18 or later; Dune 3.24.2 is the reference build version.
- GNU Make for the repository’s build commands.
- Python 3.10 or later for packaging and test scripts;
dpkg-devfor.debcreation.
The cross toolchain must match the native OCaml version exactly. Compiler tests also require Python 3.10 or later and binutils; see the test guide. Generated Xen programs use a static runtime and do not require a C compiler, assembler, linker or libc. Building OCaml itself requires a native C toolchain.
Installing native OCaml
Section titled “Installing native OCaml”With an initialized opam installation, create a native switch and install Dune:
opam switch create xen-native 5.5.0eval "$(opam env --switch=xen-native)"opam install 'dune>=3.18'Alternatively, build native OCaml from the official sources. On Ubuntu/Debian, the following packages provide the native build tools:
sudo apt install build-essential pkg-config libzstd-dev curlUse a fresh source directory and a persistent, user-owned installation prefix:
XEN_OCAML_SOURCE_ROOT="$HOME/.local/src/xen-ocaml-5.5.0"XEN_OCAML_NATIVE_PREFIX="$HOME/.local/opt/ocaml-native-5.5.0"mkdir -p "$XEN_OCAML_SOURCE_ROOT/native"curl --fail --location https://github.com/ocaml/ocaml/archive/refs/tags/5.5.0.tar.gz \ --output "$XEN_OCAML_SOURCE_ROOT/ocaml-5.5.0.tar.gz"tar -xzf "$XEN_OCAML_SOURCE_ROOT/ocaml-5.5.0.tar.gz" \ -C "$XEN_OCAML_SOURCE_ROOT/native" --strip-components=1cd "$XEN_OCAML_SOURCE_ROOT/native"./configure --prefix="$XEN_OCAML_NATIVE_PREFIX"make -j2make installexport PATH="$XEN_OCAML_NATIVE_PREFIX/bin:$PATH"Install Dune separately using its official installation instructions.
Check the tools selected by PATH before building Xen:
ocamlc -versionocamlopt -versiondune --versionThe native OCaml source procedure follows OCaml’s installation guide. Use matching sources when selecting a different OCaml version.
Building Xen
Section titled “Building Xen”Run from the Xen repository root:
make buildcompiler/dist/xen versioncompiler/dist/xen check examples/demo.xencompiler/dist/xen run examples/demo.xenmake build runs dune build @release. Dune builds
_build/default/compiler/main.exe and promotes the release executable to
compiler/dist/xen. Native Linux AArch64 uses the same commands without a cross
workspace. The CLI default target follows the compiler’s OCaml build architecture;
both Linux targets use scoped AOT optimization.
Compiler version
Section titled “Compiler version”VERSION declares the default compiler version. Make embeds a supplied override:
make build VERSION=0.1.0-demo.2compiler/dist/xen versionDirect Dune builds use VERSION or XEN_BUILD_VERSION. Binary and source package
version handling is described in packaging.
Testing and packaging
Section titled “Testing and packaging”Use the test guide for make test and focused host
suites. Native AArch64 host validation uses python3 scripts/test.py --suite host
and --suite arm64; the full suite also includes x86_64 execution/scoped AOT checks.
Select the current host CPU when packaging a native build:
make package-deb PACKAGE_ARCHS=x86_64make release-package PACKAGE_ARCHS=x86_64Use PACKAGE_ARCHS=aarch64 on a native AArch64 host. The first command creates
only .deb; the second creates .deb and tar.gz. Without a CPU selection,
make package, make package-deb and make release-package request both CPUs
and need the other CPU’s cross toolchain. Debian cross packaging also needs target
library metadata. See packaging for the directory layout, version
mapping, glibc baseline and GitHub release procedure.