crabc 0.7.8

A Rust musl-compatible libc with a dynamic linker
# Copyright (c) 2026 Meng Zhuo
# SPDX-License-Identifier: BSD-3-Clause

name: CI

on:
  push:
    branches: [main]
  pull_request:
    branches: [main]

env:
  CARGO_TERM_COLOR: always
  RUST_TEST_THREADS: "1"

jobs:
  build-and-test:
    strategy:
      fail-fast: false
      matrix:
        include:
          - arch: x86_64
            os: ubuntu-latest
          # Native arm64 runners.
          - arch: aarch64
            os: ubuntu-24.04-arm
          # Native riscv64 hardware from the RISE RISC-V Runners service.
          # Requires the RISE GitHub App: https://github.com/apps/rise-risc-v-runners
          # Disabled for now: the runner does not come up. Re-enable together
          # with the riscv64-only steps below.
          # - arch: riscv64
          #   os: ubuntu-24.04-riscv
    runs-on: ${{ matrix.os }}
    # RISC-V hardware is scarce and slower; keep it non-blocking and capped.
    continue-on-error: ${{ matrix.arch == 'riscv64' }}
    timeout-minutes: ${{ matrix.arch == 'riscv64' && 10 || 360 }}
    steps:
      - uses: actions/checkout@v7

      - name: Install Rust nightly
        uses: dtolnay/rust-toolchain@nightly

      - name: Install musl-tools
        run: sudo apt-get update && sudo apt-get install -y musl-tools

      - name: Cache cargo registry
        uses: actions/cache@v6
        with:
          path: ~/.cargo/registry
          key: ${{ runner.os }}-${{ matrix.arch }}-cargo-registry-${{ hashFiles('**/Cargo.lock') }}

      - name: Fetch libc-test sources
        run: git clone --depth 1 https://github.com/kraj/libc-test /tmp/libc-test

      - name: Build all artifacts
        run: cargo build --workspace

      - name: Run integration tests
        run: |
          set -o pipefail
          cargo test --workspace --no-fail-fast 2>&1 | tee /tmp/integration-tests.log

      - name: Report failed tests
        if: failure()
        run: |
          grep -E '^test .* FAILED|FAILED|panicked at|error: test failed' /tmp/integration-tests.log | tail -80 | while IFS= read -r line; do
            echo "::error::$line"
          done

      - name: Install riscv64 musl target
        if: matrix.arch == 'riscv64'
        run: rustup target add riscv64gc-unknown-linux-musl

      - name: Run riscv64 smoke suite natively
        if: matrix.arch == 'riscv64'
        env:
          CARGO_TARGET_RISCV64GC_UNKNOWN_LINUX_MUSL_LINKER: musl-gcc
        run: ./scripts/riscv-smoke.sh

      - name: Run libc-test harness (informational)
        continue-on-error: true
        env:
          LIBC_TEST_DIR: /tmp/libc-test
        run: |
          cd libc-test-harness
          ./run.sh functional

  macro-parity:
    runs-on: ubuntu-latest
    timeout-minutes: 15
    steps:
      - uses: actions/checkout@v7

      - name: Install cross compilers
        run: |
          sudo apt-get update
          sudo apt-get install -y gcc-aarch64-linux-gnu gcc-riscv64-linux-gnu g++-aarch64-linux-gnu g++-riscv64-linux-gnu make curl

      - name: Cache musl 1.2.6 headers
        uses: actions/cache@v6
        with:
          path: ~/.cache/crabc
          key: musl-1.2.6-headers-v1

      - name: Check macro expansion parity
        run: ./scripts/macro-parity.sh

      - name: Check headers against Rust constants
        run: python3 tests/header_rust_consistency.py --include include

  riscv64-cross:
    runs-on: ubuntu-latest
    continue-on-error: true
    timeout-minutes: 10
    steps:
      - uses: actions/checkout@v7

      - name: Install Rust nightly + riscv64 target
        uses: dtolnay/rust-toolchain@nightly
        with:
          targets: riscv64gc-unknown-linux-musl

      - name: Install riscv64 cross compiler and qemu
        run: sudo apt-get update && sudo apt-get install -y gcc-riscv64-linux-gnu qemu-user

      - name: Cross-build all artifacts
        env:
          CARGO_TARGET_RISCV64GC_UNKNOWN_LINUX_MUSL_LINKER: riscv64-linux-gnu-gcc
        run: cargo build --workspace --target riscv64gc-unknown-linux-musl

      - name: Smoke-test riscv64 under qemu
        run: ./scripts/riscv-smoke.sh