name: Check for compilation failures

on: [push, pull_request]

jobs:
  build:
    name: Check for compilation failures
    runs-on: codeberg-small
    container: archlinux:latest

    steps:
      - name: Create resolv.conf
        run: |
          set -ex
          echo 'nameserver 8.8.8.8' >/etc/resolv.conf
          echo 'nameserver 8.8.4.4' >>/etc/resolv.conf

      - name: Install dependencies
        run: pacman --noconfirm -Syu && pacman --needed --noconfirm -S nodejs base-devel git autoconf automake nasm curl mtools llvm clang lld

      - name: Checkout code
        uses: https://code.forgejo.org/actions/checkout@v6

      - name: Build the bootloader (LLVM, default)
        run: ./bootstrap && ./configure --enable-werror --enable-all && make all && make distclean

      - name: Set cross GCC version
        run: echo "GCC_VERSION=15.2.0" >> $FORGEJO_ENV

      - name: Download GCC cross toolchains
        run: |
          set -e
          for i in aarch64 loongarch64 riscv64 x86_64; do
            ( curl -Lo x86_64-gcc-${{ env.GCC_VERSION }}-nolibc-$i-linux.tar.gz https://mirrors.edge.kernel.org/pub/tools/crosstool/files/bin/x86_64/${{ env.GCC_VERSION }}/x86_64-gcc-${{ env.GCC_VERSION }}-nolibc-$i-linux.tar.gz && tar -xf x86_64-gcc-${{ env.GCC_VERSION }}-nolibc-$i-linux.tar.gz ) &
            WAITING_ON_PIDS="$WAITING_ON_PIDS $!"
          done
          for pid in $WAITING_ON_PIDS; do
            wait $pid
          done

      - name: Build the bootloader (GNU, x86)
        run: export PATH="$(pwd -P)"/gcc-${{ env.GCC_VERSION }}-nolibc/x86_64-linux/bin:"$PATH" && ./configure TOOLCHAIN_FOR_TARGET=x86_64-linux- --enable-werror --enable-bios --enable-uefi-ia32 --enable-uefi-x86-64 && make all -j$(nproc) && make distclean

      - name: Build the bootloader (GNU, aarch64)
        run: export PATH="$(pwd -P)"/gcc-${{ env.GCC_VERSION }}-nolibc/aarch64-linux/bin:"$PATH" && ./configure TOOLCHAIN_FOR_TARGET=aarch64-linux- --enable-werror --enable-uefi-aarch64 && make all -j$(nproc) && make distclean

      - name: Build the bootloader (GNU, riscv64)
        run: export PATH="$(pwd -P)"/gcc-${{ env.GCC_VERSION }}-nolibc/riscv64-linux/bin:"$PATH" && ./configure TOOLCHAIN_FOR_TARGET=riscv64-linux- --enable-werror --enable-uefi-riscv64 && make all -j$(nproc) && make distclean

      - name: Build the bootloader (GNU, loongarch64)
        run: export PATH="$(pwd -P)"/gcc-${{ env.GCC_VERSION }}-nolibc/loongarch64-linux/bin:"$PATH" && ./configure TOOLCHAIN_FOR_TARGET=loongarch64-linux- --enable-werror --enable-uefi-loongarch64 && make all -j$(nproc) && make distclean
