A compilation target tells the compiler what kind of machine and software environment its output must run on. For an OS kernel, that environment may not exist yet: the kernel is being built to create it. A custom target is a machine-readable definition of conventions such as CPU architecture. section 11.2.1
Listing 11.2 Kernel definition for FledgeOS
{
"llvm-target": "x86_64-unknown-none",
"data-layout": "e-m:e-i64:64-f80:128-n8:16:32:64-S128",
"arch": "x86_64",
"target-endian": "little",
"target-pointer-width": "64",
"target-c-int-width": "32",
"os": "none",
"linker": "rust-lld",
"linker-flavor": "ld.lld",
"executables": true,
"features": "-mmx,-sse,+soft-float",
"disable-redzone": true,
"panic-strategy": "abort"
}
The kernel’s fledge.json is a target definition understood by the Rust compiler. It specifies an x86-64 architecture, 64-bit pointers, no operating system, a linker, and an abort panic strategy. section 11.2.3
Defining the target is only one step. Rust’s core library must be built for it, without the usual standard library. The kernel is then compiled for that target, and a bootloader loads it in a virtual environment. section 11.2.1
Listing 11.3 Extra build-time configuration for cargo
[build] target = "fledge.json" [unstable] build-std = ["core", "compiler_builtins"] build-std-features = ["compiler-builtins-mem"] [target.'cfg(target_os = "none")'] runner = "bootimage runner"
Cargo’s .cargo/config.toml selects fledge.json as the build target, requests core and compiler_builtins for that target, and sets bootimage runner for a target with no OS. section 11.2.3
To try the configured project, run cargo +nightly run. The build uses bootimage to prepare the kernel for booting, then runs it in QEMU. The first visible result is a small colored block on the screen—not a full desktop, but evidence that the target, kernel, and bootloader work together. section 11.2.1 section 11.2.3
