Something went wrong. Try again.
An experimental port of NetBSD, FreeBSD, OpenBSD, and XNU to unkernel unkernel.dev
Something went wrong. Try again.
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182#!/usr/bin/env bash# SPDX-License-Identifier: GPL-2.0-or-later# Copyright (C) 2026 Tsiry Sandratraina# Run kernel/build.sh in the Linux build container: what build.sh does by# itself on macOS (kernel/tools/env.sh use_docker_host; KW_DOCKER=1 forces# it on Linux). .agents/toolchain.md, macOS host.## kernel/tools/docker-build.sh STEP [ARGS] kernel/build.sh STEP ARGS in the container# kernel/tools/docker-build.sh shell an interactive shell there (/work: this checkout)## The image is unkernel-build:<hash of kernel/tools/Dockerfile>, built when# missing (a changed Dockerfile is a new image; `docker image prune` drops# the old ones). The checkout is mounted at /work; the trees that need a# case-sensitive file system and the large outputs are Docker volumes# mounted over their places in it:# kw-linux vendor/src/linux-wasm-kernel kw-kout vendor/build/kernel# kw-llvm vendor/src/llvm22 kw-kout-smp vendor/build/kernel-smp# kw-lld vendor/build/lld22 kw-toolchain vendor/toolchain# kw-distro vendor/build/distro kw-cache /kw (Zig's caches)# (the distro staging trees are unpacked by root with their owners and# modes, which the macOS bind mount refuses), so the host sees the bundle# and the base initramfs as usual, and build.sh copies vmlinux,# vmlinux32.wasm and .config of each kernel to the host's# vendor/build/kernel{,-smp}, and the distro images with distros.json to its# vendor/build/distro (publish_outputs), when a step ends. Everything else# of those trees is reached with `shell`.# KW_ZFS, KW_SMP, JOBS, KWEMU_JIT, KWEMU_STATS, KSRC, KOUT, KOUT_SMP, ZSRC,# LINUX_REPO, ZFS_REPO and the KBUILD_BUILD_* stamps pass through; paths# among them name container paths. KW_BUILD is not passed (the volumes sit# at the default places).set -euo pipefail
. "$(dirname "$0")/env.sh" # root, vendor, sha256_ofcd "$root"
if ! command -v docker >/dev/null; then echo "docker not found: the kernel build needs a Linux host; on macOS install Docker Desktop or OrbStack (KW_DOCKER=0 builds natively)" >&2 exit 1fiif ! docker info >/dev/null 2>&1; then echo "docker is not running (docker info failed); start it, then retry" >&2 exit 1fiif [ -n "${KW_BUILD:-}" ]; then echo "warning: KW_BUILD is not passed to the build container; its outputs go to vendor/build" >&2fi
what="${1:-all}"image="unkernel-build:$(sha256_of "$root/kernel/tools/Dockerfile" | cut -c1-12)"if ! docker image inspect "$image" >/dev/null 2>&1; then echo "building the image $image from kernel/tools/Dockerfile (once per Dockerfile)" docker build -t "$image" -f "$root/kernel/tools/Dockerfile" "$root/kernel/tools"fi
# The mount points of the volumes must exist on the host side of /work.mkdir -p "$vendor/src/linux-wasm-kernel" "$vendor/src/llvm22" "$vendor/toolchain" \ "$vendor/build/lld22" "$vendor/build/kernel" "$vendor/build/kernel-smp" "$vendor/build/distro"args=(--rm -w /work -e KW_IN_DOCKER=1 -e KW_HOST_BUILD=/host/build -v "$root:/work" -v "$vendor/build:/host/build" -v kw-cache:/kw -v kw-linux:/work/vendor/src/linux-wasm-kernel -v kw-llvm:/work/vendor/src/llvm22 -v kw-lld:/work/vendor/build/lld22 -v kw-toolchain:/work/vendor/toolchain -v kw-kout:/work/vendor/build/kernel -v kw-kout-smp:/work/vendor/build/kernel-smp -v kw-distro:/work/vendor/build/distro)for v in KW_ZFS KW_SMP JOBS KWEMU_JIT KWEMU_STATS KSRC KOUT KOUT_SMP ZSRC LINUX_REPO ZFS_REPO \ KBUILD_BUILD_USER KBUILD_BUILD_HOST KBUILD_BUILD_VERSION KBUILD_BUILD_TIMESTAMP; do [ -z "${!v:-}" ] || args+=(-e "$v")doneif [ -t 0 ] && [ -t 1 ]; then args+=(-it)elif [ "$what" = shell ]; then echo "shell needs a terminal" >&2 exit 2fiif [ "$what" = shell ]; then exec docker run "${args[@]}" "$image" bashfiexec docker run "${args[@]}" "$image" kernel/build.sh "$@"