crabc 0.4.2

A Rust musl-compatible libc with a dynamic linker
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: cargo test --workspace

      - 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

  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