Skip to content
Xen / docs

Search documentation

English · v0.1.0-demo.2

Type to search the documentation.

    한국어
    Xen / reference v0.1.0-demo.2

    Building the Xen compiler

    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 environmentOCaml needed
    Linux x86_64, building an x86_64 compilerNative x86_64 OCaml
    Linux AArch64, building an AArch64 compilerNative AArch64 OCaml
    Linux x86_64, building an AArch64 compilerNative 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.

    • Native OCaml with ocamlc and ocamlopt on PATH; 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-dev for .deb creation.

    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.

    With an initialized opam installation, create a native switch and install Dune:

    Terminal window
    opam switch create xen-native 5.5.0
    eval "$(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:

    Terminal window
    sudo apt install build-essential pkg-config libzstd-dev curl

    Use a fresh source directory and a persistent, user-owned installation prefix:

    Terminal window
    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=1
    cd "$XEN_OCAML_SOURCE_ROOT/native"
    ./configure --prefix="$XEN_OCAML_NATIVE_PREFIX"
    make -j2
    make install
    export PATH="$XEN_OCAML_NATIVE_PREFIX/bin:$PATH"

    Install Dune separately using its official installation instructions. Check the tools selected by PATH before building Xen:

    Terminal window
    ocamlc -version
    ocamlopt -version
    dune --version

    The native OCaml source procedure follows OCaml’s installation guide. Use matching sources when selecting a different OCaml version.

    Run from the Xen repository root:

    Terminal window
    make build
    compiler/dist/xen version
    compiler/dist/xen check examples/demo.xen
    compiler/dist/xen run examples/demo.xen

    make 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.

    VERSION declares the default compiler version. Make embeds a supplied override:

    Terminal window
    make build VERSION=0.1.0-demo.2
    compiler/dist/xen version

    Direct Dune builds use VERSION or XEN_BUILD_VERSION. Binary and source package version handling is described in 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:

    Terminal window
    make package-deb PACKAGE_ARCHS=x86_64
    make release-package PACKAGE_ARCHS=x86_64

    Use 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.