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

name: Slim Binary

permissions: read-all

on:
  pull_request:
  workflow_dispatch:

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

jobs:
  linux:
    runs-on: ubuntu-22.04

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

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

    - name: Check environment
      run: |
        which -a clang
        cat /proc/cpuinfo

    - name: Build ISPC
      run: |
        .github/workflows/scripts/build-ispc.sh -DISPC_SLIM_BINARY=ON

    - name: Sanity testing (make check-all, make test)
      run: |
        .github/workflows/scripts/check-ispc.sh

    - name: Runtime tests
      run: |
        PATH=$(pwd)/build/bin:$PATH ./scripts/run_tests.py --target=avx2-i32x8 --arch=x86-64

  macos:
    runs-on: ${{ matrix.runner }}
    strategy:
      fail-fast: false
      matrix:
        include:
          - runner: macos-15-intel
            target: avx2-i32x8
            arch: x86-64
          - runner: macos-14
            target: neon-i32x8
            arch: aarch64

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

    - name: Install dependencies
      run: |
        .github/workflows/scripts/install-build-deps.sh ${{ matrix.runner }}

    - name: Check environment
      run: |
        which -a clang
        llvm-config --system-libs
        sysctl -n machdep.cpu.brand_string

    - name: Build package
      run: |
        .github/workflows/scripts/build-ispc.sh -DISPC_SLIM_BINARY=ON

    - name: Sanity testing (make check-all, make test)
      run: |
        .github/workflows/scripts/check-ispc.sh

    - name: Runtime tests
      run: |
        PATH=$(pwd)/build/bin:$PATH ./scripts/run_tests.py --verbose --compiler=cc --target=${{ matrix.target }} --arch=${{ matrix.arch }}

  windows:
    runs-on: windows-2022
    env:
      BUILD_TYPE: "Release"

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

    - name: Add msbuild to PATH
      uses: microsoft/setup-msbuild@6fb02220983dee41ce7ae257b6f4d8f9bf5ed4ce # v2.0.0

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

    - name: Check environment
      shell: cmd
      run: |
        wmic cpu get caption, deviceid, name, numberofcores, maxclockspeed, status

    - name: Build package
      run: |
        .github/workflows/scripts/build-ispc.ps1 -DISPC_SLIM_BINARY=ON

    - name: Sanity testing (make check-all, make test)
      run: |
        .github/workflows/scripts/check-ispc.ps1

    - name: Running tests
      run: |
        $currentDir = (Get-Location).Path
        $newPath = "$currentDir\\build\\bin\\${{ env.BUILD_TYPE }}"
        $env:PATH = "$env:PATH;$newPath"
        .github/workflows/scripts/load-vs-env.ps1 x86-64
        python scripts/run_tests.py --target=avx2-i32x8 --arch=x86-64
