# Copyright 2024-2026, Intel Corporation
# SPDX-License-Identifier: BSD-3-Clause

name: ISPCRT

permissions: read-all

on:
  pull_request:
  workflow_dispatch:

concurrency:
  group: ${{ github.workflow }}-${{ github.ref }}
  cancel-in-progress: true

jobs:
  # Build ISPC Runtime separately from ISPC with support of different task systems
  build-linux-ispcrt:
    runs-on: ubuntu-22.04
    strategy:
      fail-fast: false
      matrix:
        task_system: ['OpenMP', 'TBB', 'Threads', 'notasking']

    steps:
      - uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0

      - name: Install dependencies
        run: |
          .github/workflows/scripts/install-build-deps.sh

      - name: Build L0 loader
        run: |
          cmake superbuild \
              -B build-l0 \
              --preset os \
              -DPREBUILT_STAGE2_PATH="${GITHUB_WORKSPACE}/bin-${LLVM_VERSION}" \
              -DBUILD_L0_LOADER_ONLY=ON \
              -DCMAKE_INSTALL_PREFIX=install
          cmake --build build-l0 -j "$(nproc)"

      - name: Build ISPCRT
        run: |
          TASKING_FLAG="-DISPCRT_BUILD_TASK_MODEL=${{ matrix.task_system }}"
          if [ "${{ matrix.task_system }}" == "notasking" ]; then
            TASKING_FLAG="-DISPCRT_BUILD_TASKING=OFF"
          fi
          cmake ispcrt \
              -B build-ispcrt \
              -DXE_ENABLED=ON \
              -DLEVEL_ZERO_ROOT=install \
              -DLEVEL_ZERO_INCLUDE_DIR=install/include/ \
              ${TASKING_FLAG} \
              -DCMAKE_INSTALL_PREFIX=install
          cmake --build build-ispcrt -j "$(nproc)"
          cmake --install build-ispcrt
          cmake --install build-ispcrt --component ispcrt-tests

      - name: Upload artifacts
        uses: actions/upload-artifact@b7c566a772e6b6bfb58ed0dc250532a479d7789f # v6.0.0
        with:
          name: linux-ispcrt-${{ matrix.task_system }}
          path: |
            install
