Commit 6a5eb8a4 authored by jan.koester's avatar jan.koester
Browse files

test

parent beb1ecc2
Loading
Loading
Loading
Loading
+47 −18
Original line number Diff line number Diff line
@@ -103,9 +103,45 @@ setup_chroot() {
# ─────────────────────────────────────────────────────────────
# Phase 2: Install LLVM toolchain + musl + libc++ + compiler-rt
# ─────────────────────────────────────────────────────────────
# Phase 2a: Ensure Linux kernel headers in musl sysroot
# ─────────────────────────────────────────────────────────────
ensure_kernel_headers() {
    if [[ -f "$CHROOT_DIR/usr/local/musl/include/asm/types.h" ]]; then
        echo "==> Kernel headers already present"
        return
    fi

    echo "==> Installing Linux kernel headers into musl sysroot..."
    systemd-nspawn -D "$CHROOT_DIR" --pipe -- bash -c '
        set -e
        apt-get install -y --no-install-recommends linux-libc-dev
        cp -a /usr/include/linux /usr/local/musl/include/
        cp -a /usr/include/asm-generic /usr/local/musl/include/
        # Debian stores arch-specific headers under multiarch path
        if [ -d /usr/include/x86_64-linux-gnu/asm ]; then
            cp -a /usr/include/x86_64-linux-gnu/asm /usr/local/musl/include/
        elif [ -d /usr/include/asm ]; then
            cp -a /usr/include/asm /usr/local/musl/include/
        else
            # Generate minimal asm headers from asm-generic
            mkdir -p /usr/local/musl/include/asm
            for f in /usr/local/musl/include/asm-generic/*.h; do
                name=$(basename $f)
                echo "#include <asm-generic/${name}>" > /usr/local/musl/include/asm/${name}
            done
        fi
        echo "==> Kernel headers installed"
    '
}

# ─────────────────────────────────────────────────────────────
# Phase 2b: Install LLVM toolchain + musl + libc++ + compiler-rt
# ─────────────────────────────────────────────────────────────
setup_toolchain() {
    if [[ -f "$CHROOT_DIR/usr/local/musl/bin/musl-clang" ]]; then
    if [[ -f "$CHROOT_DIR/usr/local/musl/lib/libc++.a" ]]; then
        echo "==> Toolchain already set up, skipping"
        # Ensure kernel headers are present (may have been missed in earlier runs)
        ensure_kernel_headers
        return
    fi

@@ -139,23 +175,16 @@ setup_toolchain() {
        make -j\$(nproc)
        make install

        # Install Linux kernel headers into musl sysroot
        apt-get install -y --no-install-recommends linux-libc-dev
        cp -a /usr/include/linux /usr/local/musl/include/
        cp -a /usr/include/asm-generic /usr/local/musl/include/
        # Debian stores arch-specific headers under multiarch path
        if [ -d /usr/include/x86_64-linux-gnu/asm ]; then
            cp -a /usr/include/x86_64-linux-gnu/asm /usr/local/musl/include/
        elif [ -d /usr/include/asm ]; then
            cp -a /usr/include/asm /usr/local/musl/include/
        else
            # Generate minimal asm headers from asm-generic
            mkdir -p /usr/local/musl/include/asm
            for f in /usr/local/musl/include/asm-generic/*.h; do
                name=\$(basename \$f)
                echo \"#include <asm-generic/\${name}>\" > /usr/local/musl/include/asm/\${name}
            done
        fi
        echo '==> musl installed'
    "

    # Install kernel headers (idempotent)
    ensure_kernel_headers

    echo "==> Building LLVM runtimes against musl..."

    systemd-nspawn -D "$CHROOT_DIR" --pipe -- bash -c "
        set -e

        # Build libc++, libc++abi and libunwind against musl from LLVM source
        # LLVM 18 requires the unified runtimes build