#!/usr/bin/env bash # K1 check (kernel 0.21.0+): the kernel's own build can take our image as # its disk 0. With RUSTBELT_DISK0=out/foundry.img, the kernel's build.rs # copies our image to $CARGO_TARGET_DIR/disk.img instead of making its own, # and skips the programs that moved to Foundry OS. This builds the pinned # kernel that way, in its OWN target dir (out/kernel-k1-target, so the # normal out/kernel-target with the kernel's reference disk.img is left # alone), and checks: # 1. the disk.img it ends up with is byte-identical to our image; # 2. none of the moved programs (sh, ls, cat, ...) was built. # After that, the kernel's own tooling (`cargo run`, `cargo test`, its # scripts/run-headless.sh) boots Foundry OS: run it in out/kernel-src with # the same two variables, e.g. # cd out/kernel-src && RUSTBELT_DISK0=../foundry.img \ # CARGO_TARGET_DIR=../kernel-k1-target cargo run # # Usage: scripts/k1-check.sh IMAGE KERNEL_SRC TARGET_DIR "MOVED PROGRAMS" set -euo pipefail IMAGE=$(realpath "$1") SRC=$(realpath "$2") T=$(realpath -m "$3") MOVED=$4 rm -rf "$T" && mkdir -p "$T" # fresh, so whatever is in it was built just now ( cd "$SRC" && RUSTBELT_DISK0="$IMAGE" CARGO_TARGET_DIR="$T" cargo build --features headless ) ok=1 if cmp -s "$IMAGE" "$T/disk.img"; then echo "[k1-check] $T/disk.img is byte-identical to $IMAGE" else echo "[k1-check] FAIL: $T/disk.img differs from $IMAGE"; ok=0 fi # build.rs puts the user programs it builds in its OUT_DIR # ($T/x86_64-rust_kernel/debug/build/rustbelt/HASH/out/). # Only the files directly in out/ (out/rootfs-tree/bin/sh is the kernel's # boot-v2 test init, not a moved program). built=$(find "$T" -path '*/build/rustbelt/*/out/*' -type f | grep -E '/build/rustbelt/[^/]+/out/[^/]+$' | xargs -n1 basename | sort -u) [ -n "$built" ] || { echo "[k1-check] FAIL: found no build.rs output at all"; ok=0; } echo "[k1-check] build.rs built $(wc -l <<<"$built") files, e.g. $(grep -x -m1 forktest <<<"$built" || echo '(no forktest!)')" for p in $MOVED; do if printf '%s\n' "$built" | grep -qx "$p"; then echo "[k1-check] FAIL: moved program $p was still built"; ok=0; fi done [ $ok = 1 ] && echo "[k1-check] OK: the kernel build uses Foundry OS's image as disk 0 and skips the $(wc -w <<<"$MOVED") moved programs" [ $ok = 1 ]