#!/bin/bash # MARKUS MAIWALD (ARCHITECT) | VOXIS FORGE (AI) # Rumpk Build Script - Multi-Architecture # Supports: aarch64, x86_64, riscv64 set -e RUMPK_DIR="$(cd "$(dirname "$0")" && pwd)" BUILD_DIR="$RUMPK_DIR/build" # Default architecture ARCH="${1:-aarch64}" # Validate architecture case "$ARCH" in aarch64|arm64) ARCH="aarch64" ZIG_TARGET="aarch64-freestanding-none" NIM_CPU="arm64" NIM_DEFINE="arm64" QEMU_CMD="qemu-system-aarch64 -M virt -cpu cortex-a57" UART_ADDR="0x09000000" ;; x86_64|amd64) ARCH="x86_64" ZIG_TARGET="x86_64-freestanding-none" NIM_CPU="amd64" NIM_DEFINE="amd64" QEMU_CMD="qemu-system-x86_64 -M q35" UART_ADDR="0x3F8" # COM1 ;; riscv64) ARCH="riscv64" ZIG_TARGET="riscv64-freestanding-none" NIM_CPU="riscv64" NIM_DEFINE="riscv64" QEMU_CMD="qemu-system-riscv64 -M virt" UART_ADDR="0x10000000" ;; *) echo "Usage: $0 [aarch64|x86_64|riscv64]" echo "Default: aarch64" exit 1 ;; esac echo "╔═══════════════════════════════════════╗" echo "║ RUMPK MULTI-ARCH BUILD v0.3 ║" echo "║ Architecture: $ARCH " echo "╚═══════════════════════════════════════╝" echo "" # Create build directory mkdir -p "$BUILD_DIR" mkdir -p "$BUILD_DIR/nimcache" # ========================================================= # Step 1: Compile Zig L0 (HAL + Stubs) # ========================================================= echo "[1/5] Compiling Zig L0 (HAL + libc stubs)..." # Compile main.zig zig build-obj \ "$RUMPK_DIR/hal/main.zig" \ -target $ZIG_TARGET \ -O ReleaseSmall \ -femit-bin="$BUILD_DIR/hal.o" # Compile stubs.zig zig build-obj \ "$RUMPK_DIR/hal/stubs.zig" \ -target $ZIG_TARGET \ -O ReleaseSmall \ -femit-bin="$BUILD_DIR/stubs.o" echo " → $BUILD_DIR/hal.o" echo " → $BUILD_DIR/stubs.o" # ========================================================= # Step 2: Compile Context Switch Assembly # ========================================================= echo "[2/5] Compiling context switch ($ARCH)..." zig cc \ -target $ZIG_TARGET \ -c "$RUMPK_DIR/hal/arch/$ARCH/switch.S" \ -o "$BUILD_DIR/switch.o" echo " → $BUILD_DIR/switch.o" # ========================================================= # Step 3: Compile Nim L1 (Kernel + Fibers) # ========================================================= echo "[3/5] Compiling Nim L1 (Kernel + Fibers)..." nim c \ --cpu:$NIM_CPU \ --os:any \ --mm:arc \ --noMain:on \ --cc:clang \ --passC:"-target ${ZIG_TARGET/-freestanding-none/-unknown-none} -ffreestanding -fno-stack-protector -fno-builtin" \ --passL:"-target ${ZIG_TARGET/-freestanding-none/-unknown-none} -nostdlib -ffreestanding" \ --define:useMalloc \ --define:StandaloneHeapSize=65536 \ --define:$NIM_DEFINE \ -d:release \ -d:danger \ --checks:off \ --assertions:off \ --boundChecks:off \ --overflowChecks:off \ --nimcache:"$BUILD_DIR/nimcache" \ --path:"$RUMPK_DIR/core" \ -c \ "$RUMPK_DIR/core/kernel.nim" echo " → $BUILD_DIR/nimcache/*.c" # ========================================================= # Step 4: Compile Nim C files to objects # ========================================================= echo "[4/5] Compiling Nim C files..." for cfile in "$BUILD_DIR/nimcache"/*.c; do ofile="${cfile%.c}.o" zig cc \ -target $ZIG_TARGET \ -ffreestanding \ -fno-stack-protector \ -fno-builtin \ -fno-sanitize=all \ -I"$RUMPK_DIR/core/include" \ -I/usr/lib/nim \ -I"$RUMPK_DIR/core" \ -c "$cfile" \ -o "$ofile" 2>&1 || true done echo " → $BUILD_DIR/nimcache/*.o" # ========================================================= # Step 5: Link Everything # ========================================================= echo "[5/5] Linking (freestanding, no libc)..." NIM_OBJS=$(find "$BUILD_DIR/nimcache" -name "*.o" 2>/dev/null | tr '\n' ' ') if [ -z "$NIM_OBJS" ]; then echo "ERROR: No Nim object files found!" exit 1 fi # Select linker script based on architecture LINKER_SCRIPT="$RUMPK_DIR/boot/linker.ld" if [ -f "$RUMPK_DIR/boot/linker-$ARCH.ld" ]; then LINKER_SCRIPT="$RUMPK_DIR/boot/linker-$ARCH.ld" fi zig cc \ -target $ZIG_TARGET \ -nostdlib \ -T "$LINKER_SCRIPT" \ "$BUILD_DIR/hal.o" \ "$BUILD_DIR/stubs.o" \ "$BUILD_DIR/switch.o" \ $NIM_OBJS \ -o "$BUILD_DIR/rumpk-$ARCH.elf" echo " → $BUILD_DIR/rumpk-$ARCH.elf" # ========================================================= # Done # ========================================================= echo "" echo "✅ Build complete for $ARCH!" echo "" echo "Run with:" echo " $QEMU_CMD -nographic -kernel $BUILD_DIR/rumpk-$ARCH.elf"