# ClaudeOS build environment
#
# Provides everything needed to build and test a bare-metal i386 kernel:
#   - Clang + LLD for cross-compilation to i386-elf
#   - GRUB 2 tools for generating bootable ISO and floppy images
#   - QEMU (i386) for running integration tests
#   - CMake + Ninja for the build system
#   - xorriso and mtools used internally by grub-mkrescue / grub-mkimage

FROM --platform=linux/amd64 alpine:3.23

RUN apk add --no-cache \
    # Core build tools
    clang \
    lld \
    cmake \
    ninja \
    make \
    git \
    # GRUB image generation
    grub \
    grub-bios \
    xorriso \
    mtools \
    # QEMU for running the OS
    qemu-system-i386 \
    # Handy utilities
    file \
    ca-certificates

# Verify the cross-compilation toolchain can produce an i386-elf binary.
# Compile and link separately so ld.lld is invoked directly, avoiding the
# host gcc linker driver (which rejects -m32 on non-x86 hosts such as aarch64).
RUN echo 'void _start(void){for(;;)__asm__("hlt");}' > /tmp/test.c \
    && clang -v -target i386-elf -march=i386 -ffreestanding -fno-stack-protector \
             -c /tmp/test.c -o /tmp/test.o \
    && ld.lld -m elf_i386 -e _start --nostdlib /tmp/test.o -o /tmp/test.elf \
    && file /tmp/test.elf | grep -q "ELF 32-bit.*386" \
    && echo "Toolchain OK" \
    && rm /tmp/test.c /tmp/test.o /tmp/test.elf

WORKDIR /workspaces/claude-os
