Development
This page is for people who build cairn from source, run its tests, or package it. It covers the build, every Makefile target, what each test level needs from the host, the lint policy, packaging and release signing. The Makefile is the source of truth; run make -n <target> to see what a target does. How the code is organised is in architecture.
Building
make buildmake build is the default target. It does two things in order:
- builds
cairn-init, the guest's PID 1, as a static musl binary (target/x86_64-unknown-linux-musl/release/cairn-init;rustup target addis run for you); - runs
cargo build --release --workspace.
cairn embeds the init with include_bytes!. Its build script reads the path from CAIRN_INIT_PATH, which the Makefile exports to every cargo invocation. Keep using make for builds and tests: a different value of that variable rebuilds cairn each time, and a bare cargo build outside make embeds a placeholder that cairn deploy refuses. The init is rebuilt when anything in cairn-init, cairn-proto, cairn-guest-proto, cairn-sync or cairn-durable changes, because the guest links all of them.
The helper's installed location is a compile-time constant, /usr/libexec/cairn (CAIRN_LIBEXECDIR, set by the Makefile). The CLI looks for its helper programs there and nowhere else, so a make build binary is a package payload.
The toolchain is pinned in rust-toolchain.toml: Rust 1.97.1, minimal profile, plus rustfmt and clippy. Edition 2024.
Nothing that builds needs root, and nothing that needs root builds. Do not run packaging targets with sudo; they refuse.
If rustc crashes
A large crate can overflow rustc's stack (SIGSEGV or an internal compiler error). Retry with:
ulimit -s unlimited
export RUST_MIN_STACK=67108864
make buildA SIGSEGV can leave a corrupt library behind ("output file too large"). Remove it and rebuild:
cargo clean -p cairnMakefile targets
| Target | What it does |
|---|---|
build | The musl init, then the release workspace. The default. |
gen | Regenerates the systemd units and cron file from their .in templates (cairn-gen). |
fmt, fmt-check | cargo fmt --all, or check only. |
clippy | Clippy with -D warnings, twice: default features, then the namespace and VM features so feature-gated tests are linted. |
deny | cargo deny check (licences, advisories). Needs cargo install --locked cargo-deny. |
doc-check | Builds rustdoc with -D warnings and --document-private-items: no broken links. |
check-refs | Fails if any .rs file cites a design plan (a section sign, plans/, "plan N"). Comments must stand on their own. |
audit-jail | Verifies cairn-jail has exactly one program-spawn site, reads no environment, uses no shell and no PATH lookup. Prints its line count. |
check | fmt-check, check-refs, clippy, test. |
ci | check, doc-check, audit-jail, deny. |
clean | cargo clean. |
install-kernel | Downloads the pinned guest kernel into $CAIRN_HOME/kernels, checks its sha256 and sets mode 0444. Run as yourself. |
fetch-firecracker | Fetches the pinned Firecracker into target/firecracker for packaging. |
package, install | Host-format package from this tree, and its install step. See Packaging. |
rpm, deb, dist | Release packages built from static musl binaries. |
test-gen, build-musl, test-musl, test-ns-musl | The musl equivalents of the build and test levels. |
Test levels
Each level adds a host requirement. A test that cannot run on this host prints why and passes, so read the output.
| Level | Command | Needs |
|---|---|---|
| Unit | make test | Nothing. |
| Namespace | make test-ns | Unprivileged user namespaces. |
| VM | make test-vm | The namespace needs, plus /dev/kvm, an installed package, test assets, tools (below). |
| VM, complete | make test-vm-complete | Same as test-vm; also fails on any self-skip. |
| Focused VM | make test-vm-volumes etc. | Same as test-vm. |
| Package | make test-package | Rootless podman. |
| Installed | make test-installed | The package installed; sudo for the removal step. |
| Host | make test-host | The built programs installed; sudo. |
| Benchmark | make bench | As test-host, plus iperf3. |
make test
Checks the generated unit files are current, then runs cargo test --workspace --all-targets and cargo test --workspace --doc. It also enforces that every file under crates/cairn-ns/tests starts with #![forbid(unsafe_code)].
make test-ns
Runs the suite with the ns-tests features, which build the programs the tests run (the helper with fault points, a stub jailer, the network agent's probe) and start whole rootless "hosts" in user and mount namespaces. Each test is heavy, so threads are capped: NS_TEST_THREADS defaults to 4. Choose how the harness runs the helper with make test-ns CAIRN_TEST_HELPER=direct|broker|auto; CI runs it with each forced so the fallback does not rot.
make test-vm and make test-vm-complete
Boots real Firecracker guests. The host needs:
/dev/kvmyou can open;- unprivileged user namespaces;
- membership of the
cairngroup, and the installed package (the realcairn-jailandcairn-helper); jailed VM tests need nosudoonce it is installed; mkfs.ext4,tar,fallocateandinstallin/usr/sbin:/usr/bin:/sbin:/bin;- a directory
../example/assetsnext to the repository (override withCAIRN_VM_ASSETS) containingfirecracker,vmlinux(the guest kernel) andimage.tar(a small Alpine image).
crates/cairn/tests/support/vm.rs checks these and prints what is missing. make test-vm uses VM_TEST_THREADS (default 2); each VM is 128 MiB of guest memory plus a 64 MiB disk.
test-vm exits 0 on a host that cannot run a test, because each such test prints why, returns and counts as passed. That suits a laptop and is wrong evidence for a release. make test-vm-complete runs the same suite into target/test-vm-complete.log (change it with LOG=) and then runs make check-no-skips, which fails on any line starting skipped or skipping, except the opt-in experiments (CAIRN_P6_*, CAIRN_TEST_CUSTOM_KERNEL*). make check-no-skips LOG=<file> audits any log made with --show-output.
Focused VM targets
Each builds a special guest or runs one suite, so a change to one area does not rerun everything.
| Target | What it runs |
|---|---|
test-vm-volumes | The complete volume matrix on real VMs (machine_volumes, one thread). |
test-vm-backpressure | One test with a guest built with the backpressure-test feature; the supervisor is stopped with SIGSTOP while the vsock buffers fill (BACKPRESSURE_SECONDS, default 240). |
test-vm-health | The machine_health seam tests, with a guest built with health-test. FILTER= narrows it. |
test-vm-exec | The exec agent's failure paths, with a guest built with exec-test-seams. Needs rootless podman for a per-test image layer. |
test-vm-cost | The CPU benchmark of the health checks, against the production guest. |
build-run-seams | Builds cairn and a guest with run-test-seams into target/run-seams, for the cairn run fault-injection acceptance script. |
The special guests are built in their own target directories, so the normal build never contains them.
Test parallelism
The namespace and VM suites start whole hosts and VMs; at full parallelism they have exhausted a workstation's memory and I/O. Check the load first, and run one heavy suite at a time. Two suites are known to be flaky when many threads run at once, with processes seen late or a network briefly reported degraded; rerun before calling it a regression. For make test on a busy machine use:
RUST_TEST_THREADS=6 make testmake test-package
Builds two packages of each format (v1, and v2 for the upgrade) and installs, upgrades, repairs and removes them inside fresh rootless-podman containers: Fedora 43, Ubuntu 24.04 and Ubuntu 26.04. No network, no systemd. Run only one format with sh dist/pkg/tests/run.sh rpm.
make test-installed
Acceptance of the package installed on this host, used as a user would, ending with a real removal and reinstall. It uses only installed programs, creates its own uniquely named apps, networks and run folders, and removes them. It asks before changing anything (CONFIRM=1 skips the question) and will not stop anything it did not create. The removal needs a quiet host: the maintenance barrier refuses otherwise, so stop your own machines first. sh dist/pkg/tests/installed.sh --checks-only runs only the prechecks, with no root and no changes. Environment: RUN_AGENT, PORT (first of four free ports, default 18601), SUDO, CONFIRM.
make test-host and make bench
test-host checks that the installed programs are byte-identical to target/release, runs cairn doctor, runs the real-host scripts as you, and re-runs two host regression scripts as root with sudo. bench runs iperf3 against the installed programs. Both need make build, then make install and installing the package it names, first. These use scripts in ../example, which is outside this repository.
Lint policy
Set once in the workspace Cargo.toml under [workspace.lints]:
unsafe_code = "forbid".forbid, notdeny, because no attribute can undo it, so a test file cannot quietly allowunsafe.cairn-nsandcairn-initdo not inherit the table and state their own set.- Clippy
pedanticis a warning, andunwrap_usedandexpect_usedare denied: a panic in library code is a compile error.-D warningsinmake clippymakes the warnings fail the build. Tests opt back in locally. result_large_erris allowed: error types carry structured refusals and are built once per refusal.- rustdoc
private_intra_doc_linksis allowed; every other rustdoc lint failsmake doc-check.
make check-refs also keeps source comments self-contained: no section signs and no references to design plans.
Packaging
Packages are RPM and deb, built from this tree. The host programs install to /usr/bin and /usr/libexec/cairn; cairn-jail is root-owned setuid (4755), and cairn-helper is setuid to the cairn-helper account with CAP_NET_ADMIN and CAP_NET_BIND_SERVICE file capabilities. The package creates the cairn group and the cairn-helper user, ships the pinned Firecracker and jailer, the sysctl and AppArmor files and the gc timers. Everything lives under dist/: dist/pkg/stage.sh stages the payload, cairn.spec and dist/pkg/debian/ describe the packages, version.sh chooses the version.
Install from source
make installAs yourself, this builds and validates a package in the host's own format (using the glibc target/release binaries, with no container) and prints the one command to run as root, for example sudo dnf install <archive> or sudo apt-get install <archive>. It never runs sudo for you. As root, it installs the archive this tree already built and refuses if sources changed since; a root caller never builds, so target/ stays yours. make package stops after building the package and writes its path to target/pkg/LAST.
Then install the kernel as yourself with make install-kernel (never with sudo: the file must be yours), add yourself to the cairn group and run cairn doctor.
Release packages
make dist # development version, into the source folder
make dist RELEASE=1 # the workspace version, as a release
make dist RELEASE=1 DIST_DIR=/path/to/outmake dist runs rpm and deb, which build static musl binaries (build-musl; it fails if the init was not embedded), stage the payload and build each archive. Distribution versions do not depend on what this build host has installed. BUILD_JOBS (default 2), NICE and IONICE set the build's resource use. Run as an ordinary user.
Signing releases
make dist builds unsigned packages. Sign the RPM itself and provide signed checksums for both formats. For direct deb downloads, verify those checksums before installing. APT repositories use a signed package index instead.
Create a key once
Install GnuPG and rpmsign on the signing machine. These commands use RPM 6 (as shipped by Fedora 43). Replace the email and choose a passphrase:
gpg --quick-generate-key 'Cairn releases <you@example.com>' rsa3072 sign 1y
gpg --fingerprint 'Cairn releases'Copy the full fingerprint for the next step. Back up the private key and revocation certificate offline. Renew the key before its one-year expiry.
Build, sign and upload
Run from the source folder as an ordinary user. Use a fresh output folder for each release. Sign the RPM before calculating checksums, because signing changes the RPM file.
set -e
export SIGNING_KEY='YOUR_FULL_KEY_FINGERPRINT'
release_dir="$PWD/target/dist-$(date -u +%Y%m%dT%H%M%SZ)"
make dist RELEASE=1 DIST_DIR="$release_dir"
cd "$release_dir"
rpmsign --define '_openpgp_sign gpg' --addsign --key-id "$SIGNING_KEY" cairn-*.rpm
sha256sum cairn-*.rpm cairn_*.deb > SHA256SUMS
gpg --local-user "$SIGNING_KEY" --armor --detach-sign SHA256SUMS
gpg --armor --export "$SIGNING_KEY" > cairn-release-key.ascUpload the RPM, deb, SHA256SUMS, SHA256SUMS.asc and cairn-release-key.asc. Publish the fingerprint on the project page too. In CI, keep the private key and passphrase in protected secrets available only to the release job. Keep them out of Git and builder images.
Verify a download
Compare the public key's fingerprint with the one on the project page. Then verify the signature and checksums. Both checks must succeed, and the signature must identify the expected key.
set -e
gpg --show-keys --fingerprint cairn-release-key.asc
gpg --import cairn-release-key.asc
gpg --verify SHA256SUMS.asc SHA256SUMS
sha256sum --check SHA256SUMSFor RPM's own signature check, an administrator imports the public key once:
sudo rpmkeys --import cairn-release-key.asc
rpmkeys --checksig cairn-*.rpmAPT does not automatically check the checksum signature beside a downloaded deb. If cairn later has an APT repository, sign its Release metadata and configure clients to trust the public key through Signed-By.
References: RPM signing, GnuPG keys, APT authentication.