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

name: Tests

permissions: read-all

on:
  schedule:
    # Run daily - test sse2-avx512 targets @ -O0/-O1/-O2
    - cron:  '0 7 * * *'
  pull_request:
  workflow_dispatch:
    inputs:
      flow_type:
        description: 'Workflow flow type (full or smoke)'
        required: true
        default: 'smoke'
        type: choice
        options:
        - 'full'
        - 'smoke'

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

env:
  TARGETS_SMOKE_X86: '["avx2-i32x8", "generic-i32x4"]'
  TARGETS_SMOKE_ARM: '["neon-i32x4"]'
  OPTSETS_SMOKE: "-O2"
  TARGETS_FULL_X86:  '["generic-i1x4", "generic-i1x8", "generic-i1x16", "generic-i1x32",
                      "generic-i8x16", "generic-i8x32",
                      "generic-i16x8", "generic-i16x16",
                      "generic-i32x4", "generic-i32x8", "generic-i32x16",
                      "generic-i64x4",
                      "sse2-i32x4", "sse2-i32x8",
                      "sse4-i8x16", "sse4-i16x8", "sse4-i32x4", "sse4-i32x8",
                      "avx1-i32x4", "avx1-i32x8", "avx1-i32x16", "avx1-i64x4",
                      "avx2-i8x32", "avx2-i16x16", "avx2-i32x4", "avx2-i32x8", "avx2-i32x16", "avx2-i64x4",
                      "avx2vnni-i32x4", "avx2vnni-i32x8", "avx2vnni-i32x16",
                      "avx512skx-x4", "avx512skx-x8", "avx512skx-x16", "avx512skx-x64", "avx512skx-x32",
                      "avx512icl-x4", "avx512icl-x8", "avx512icl-x16", "avx512icl-x64", "avx512icl-x32",
                      "avx512spr-x4", "avx512spr-x8", "avx512spr-x16", "avx512spr-x64", "avx512spr-x32",
                      "avx512gnr-x4", "avx512gnr-x8", "avx512gnr-x16", "avx512gnr-x64", "avx512gnr-x32"]'
  TARGETS_FULL_ARM: '["neon-i32x4", "neon-i32x8", "neon-i8x16", "neon-i16x8", "neon-i8x32", "neon-i16x16"]'
  OPTSETS_FULL: "-O0 -O1 -O2"
  ISPC_ANDROID_NDK_PATH: "/usr/local/share/android-ndk"

jobs:
  define-flow:
    runs-on: ubuntu-22.04
    outputs:
      tests_matrix_targets_x86: ${{ steps.set-flow.outputs.matrix_x86 }}
      tests_matrix_targets_arm: ${{ steps.set-flow.outputs.matrix_arm }}
      tests_optsets: ${{ steps.set-flow.outputs.optsets }}
      flow_type: ${{ steps.set-flow.outputs.type }}
    env:
      # for debug purposes
      REF_NAME: ${{ github.ref }}
      EVENT_NAME: ${{ github.event_name }}

      # define rule when to run full flow
      RUN_FULL: ${{ (github.ref == 'refs/heads/main' && github.event_name == 'schedule') ||
                    (github.event_name == 'workflow_dispatch' && github.event.inputs.flow_type == 'full') }}

      # define rule when to run smoke flow
      RUN_SMOKE: ${{ github.event_name == 'pull_request' ||
                    (github.event_name == 'workflow_dispatch' && github.event.inputs.flow_type == 'smoke') }}
    steps:
    - name: Set workflow jobs flow
      id: set-flow
      run: |
        # one and only one var should be set
        if [[ "$RUN_SMOKE" == false && "$RUN_FULL" == true ]]; then
          echo "type=full" >> "$GITHUB_OUTPUT"
        elif [[ "$RUN_SMOKE" == true && "$RUN_FULL" == false ]]; then
          echo "type=smoke" >> "$GITHUB_OUTPUT"
        else
          echo "One and only one env var must be set: RUN_SMOKE or RUN_FULL"
          exit 1
        fi
        # set tests matrix depends on flow
        if [[ "$RUN_SMOKE" == "true" ]]; then
          echo "matrix_x86=${TARGETS_SMOKE_X86}" >> "$GITHUB_OUTPUT"
          echo "matrix_arm=${TARGETS_SMOKE_ARM}" >> "$GITHUB_OUTPUT"
        fi
        if [[ "$RUN_FULL" == "true" ]]; then
          echo "matrix_x86=${TARGETS_FULL_X86}" >> "$GITHUB_OUTPUT"
          echo "matrix_arm=${TARGETS_FULL_ARM}" >> "$GITHUB_OUTPUT"
        fi
        # set tests optsets
        if [[ "$RUN_SMOKE" == "true" ]]; then
          echo "optsets=${OPTSETS_SMOKE}" >> "$GITHUB_OUTPUT"
        fi
        if [[ "$RUN_FULL" == "true" ]]; then
          echo "optsets=${OPTSETS_FULL}" >> "$GITHUB_OUTPUT"
        fi

  linux-build-ispc-aarch64:
    needs: [define-flow]
    strategy:
      fail-fast: false
      matrix:
        llvm:
          - version: "21.1"
            full_version: "21.1.8"
            short_version: 21
    uses: ./.github/workflows/reusable.ispc.build.yml
    with:
      platform: linux
      artifact_name: ispc_llvm${{ matrix.llvm.short_version }}_linux.aarch64
      runner: ubuntu-22.04-arm
      llvm_version: ${{ matrix.llvm.version }}
      llvm_tar: llvm-${{ matrix.llvm.full_version }}-ubuntu22.04aarch64-Release+Asserts-x86.arm.wasm.tar.xz

  linux-build-ispc:
    needs: [define-flow]
    strategy:
      fail-fast: false
      matrix:
        llvm:
          - version: "18.1"
            full_version: "18.1.8"
            short_version: 18
          - version: "19.1"
            full_version: "19.1.7"
            short_version: 19
          - version: "20.1"
            full_version: "20.1.8"
            short_version: 20
          - version: "21.1"
            full_version: "21.1.8"
            short_version: 21
    uses: ./.github/workflows/reusable.ispc.build.yml
    with:
      platform: linux
      artifact_name: ispc_llvm${{ matrix.llvm.short_version }}_linux
      runner: ubuntu-22.04
      llvm_version: ${{ matrix.llvm.version }}
      llvm_tar: llvm-${{ matrix.llvm.full_version }}-ubuntu22.04-Release+Asserts-x86.arm.wasm.tar.xz

  linux-build-ispc-llvm21-lto:
    needs: [define-flow]
    uses: ./.github/workflows/reusable.ispc.build.yml
    with:
      platform: linux
      artifact_name: ispc_llvm21_lto_linux
      runner: ubuntu-22.04
      llvm_version: "21.1"
      llvm_tar: llvm-21.1.8-ubuntu22.04-Release+Asserts-lto-x86.arm.wasm.tar.xz
      enable_lto: true

  linux-build-ispc-llvm21-release:
      needs: [define-flow]
      uses: ./.github/workflows/reusable.ispc.build.yml
      with:
        platform: linux
        artifact_name: ispc_llvm21rel_linux
        runner: ubuntu-22.04
        llvm_version: "21.1"
        llvm_tar: llvm-21.1.8-ubuntu22.04-Release-x86.arm.wasm.tar.xz
        enable_cross: true

  linux-build-ispc-xe-llvm21-release:
    needs: [define-flow]
    uses: ./.github/workflows/reusable.ispc.build.yml
    with:
      platform: linux
      artifact_name: ispc_xe_llvm21rel_linux
      runner: ubuntu-22.04
      llvm_version: "21.1"
      llvm_tar: llvm-21.1.8-ubuntu22.04-Release-x86.arm.wasm.tar.xz
      enable_xe: true

  linux-build-ispc-wasm:
    needs: [define-flow]
    uses: ./.github/workflows/reusable.ispc.build.yml
    with:
      platform: linux
      artifact_name: ispc-wasm-linux
      runner: ubuntu-22.04
      llvm_version: "21.1"
      llvm_tar: llvm-21.1.8-ubuntu22.04-Release+Asserts-x86.arm.wasm.tar.xz
      enable_wasm: true

  linux-build-ispc-riscv:
    needs: [define-flow]
    uses: ./.github/workflows/reusable.ispc.build.yml
    with:
      platform: linux
      artifact_name: ispc-riscv-linux
      runner: ubuntu-22.04
      llvm_version: "21.1"
      llvm_tar: llvm-21.1.8-ubuntu22.04-Release+Asserts-x86.arm.wasm.tar.xz
      enable_riscv: true

  linux-test:
    needs: [define-flow, linux-build-ispc]
    strategy:
      fail-fast: false
      matrix:
        llvm: [18, 19, 20, 21]
        arch: [x86, x86-64]
    uses: ./.github/workflows/reusable.ispc.test.yml
    with:
      platform: linux
      architecture: ${{ matrix.arch }}
      artifact_name: ispc_llvm${{ matrix.llvm }}_linux
      targets: ${{ needs.define-flow.outputs.tests_matrix_targets_x86 }}
      optsets: ${{ needs.define-flow.outputs.tests_optsets }}

  linux-test-flags:
    needs: [define-flow, linux-build-ispc]
    strategy:
      fail-fast: false
      matrix:
        # --math-lib=fast and --opt=fast-math are not tested because of #3442
        include:
          - llvm: 21
            arch: x86-64
            extra_flags: "--opt=disable-zmm"
            targets: '["avx512skx-x16"]'
          - llvm: 21
            arch: x86-64
            extra_flags: "--addressing=64"
            targets: '["avx2-i32x8"]'
          - llvm: 21
            arch: x86
            extra_flags: "--addressing=64"
            targets: '["avx2-i32x8"]'
          - llvm: 21
            arch: x86-64
            extra_flags: "-g"
            targets: '["avx2-i32x8"]'
          - llvm: 21
            arch: x86
            extra_flags: "-g"
            targets: '["avx2-i32x8"]'
          - llvm: 21
            arch: x86
            extra_flags: "--math-lib=system"
            targets: '["avx2-i32x8"]'
          - llvm: 21
            arch: x86-64
            extra_flags: "--math-lib=system"
            targets: '["avx2-i32x8"]'
          - llvm: 21
            arch: x86
            extra_flags: "--pic"
            targets: '["avx2-i32x8"]'
          - llvm: 21
            arch: x86-64
            extra_flags: "--pic"
            targets: '["avx2-i32x8"]'
          - llvm: 21
            arch: x86-64
            extra_flags: "--mcmodel=large"
            targets: '["avx2-i32x8"]'
          - llvm: 21
            arch: x86
            extra_flags: "--no-wrap-signed-int"
            targets: '["avx2-i32x8"]'
          - llvm: 21
            arch: x86-64
            extra_flags: "--no-wrap-signed-int"
            targets: '["avx2-i32x8"]'
          - llvm: 21
            arch: x86
            extra_flags: "--opt=disable-fma"
            targets: '["avx2-i32x8"]'
          - llvm: 21
            arch: x86-64
            extra_flags: "--opt=disable-fma"
            targets: '["avx2-i32x8"]'
    uses: ./.github/workflows/reusable.ispc.test.yml
    with:
      platform: linux
      architecture: ${{ matrix.arch }}
      artifact_name: ispc_llvm${{ matrix.llvm }}_linux
      targets: ${{ matrix.targets }}
      optsets: ${{ needs.define-flow.outputs.tests_optsets }}
      ispc_extra_flags: ${{ matrix.extra_flags }}

  linux-test-llvm21-lto:
    needs: [define-flow, linux-build-ispc-llvm21-lto]
    strategy:
      fail-fast: false
      matrix:
        arch: [x86, x86-64]
    uses: ./.github/workflows/reusable.ispc.test.yml
    with:
      platform: linux
      architecture: ${{ matrix.arch }}
      artifact_name: ispc_llvm21_lto_linux
      targets: ${{ needs.define-flow.outputs.tests_matrix_targets_x86 }}
      optsets: ${{ needs.define-flow.outputs.tests_optsets }}
      enable_lto: true

  linux-test-llvm21-aarch64:
    needs: [define-flow, linux-build-ispc-aarch64]
    uses: ./.github/workflows/reusable.ispc.test.yml
    with:
      platform: linux
      architecture: aarch64
      artifact_name: ispc_llvm21_linux.aarch64
      targets: ${{ needs.define-flow.outputs.tests_matrix_targets_arm }}
      optsets: ${{ needs.define-flow.outputs.tests_optsets }}

  linux-test-riscv:
    needs: [define-flow, linux-build-ispc-riscv]
    uses: ./.github/workflows/riscv.yml
    with:
      artifact_name: ispc-riscv-linux

  # Test release version
  linux-test-llvm21-release:
    needs: [define-flow, linux-build-ispc-llvm21-release]
    strategy:
      fail-fast: false
      matrix:
        arch: [x86, x86-64]
    uses: ./.github/workflows/reusable.ispc.test.yml
    with:
      platform: linux
      architecture: ${{ matrix.arch }}
      artifact_name: ispc_llvm21rel_linux
      targets: '["avx2-i32x8"]'
      optsets: -O0 -O2

  # Debug run is experimental with the purpose to see if it's capable to catch anything.
  # So it's running in "full" mode only for now.
  # Single target, as it should be representative enough.
  linux-test-debug-llvm21:
    needs: [define-flow, linux-build-ispc]
    if: ${{ needs.define-flow.outputs.flow_type == 'full' }}
    strategy:
      fail-fast: false
      matrix:
        arch: [x86, x86-64]
    uses: ./.github/workflows/reusable.ispc.test.yml
    with:
      platform: linux
      architecture: ${{ matrix.arch }}
      artifact_name: ispc_llvm21_linux
      targets: '["avx2-i32x8"]'
      optsets: -O0 -O2
      enable_debug: true

  # Test xe release version
  linux-test-xe-llvm21-release:
    needs: [define-flow, linux-build-ispc-xe-llvm21-release]
    if: ${{ needs.define-flow.outputs.flow_type == 'smoke' }}
    strategy:
      fail-fast: false
      matrix:
        arch: [x86, x86-64]
    uses: ./.github/workflows/reusable.ispc.test.yml
    with:
      platform: linux
      architecture: ${{ matrix.arch }}
      artifact_name: ispc_xe_llvm21rel_linux
      targets: '["avx2-i32x8"]'
      optsets: -O0 -O2
      enable_xe: true

  linux-test-ispc-wasm:
    needs: [define-flow, linux-build-ispc-wasm]
    strategy:
      fail-fast: false
      matrix:
        # wasm64 is failing with nodejs 20.18.0 that is installed by default
        # with emsdk in script/install_emscripten.[sh|bat]
        # Disable it for now, nodejs 23.9.0 works but it requires us to install
        # it manually alongside emsdk.
        arch: [wasm32]
    uses: ./.github/workflows/reusable.ispc.test.yml
    with:
      platform: linux
      architecture: ${{ matrix.arch }}
      artifact_name: ispc-wasm-linux
      targets: '["wasm-i32x4"]'
      optsets: -O0 -O2

  macos-build-ispc:
    needs: [define-flow]
    strategy:
      fail-fast: false
      matrix:
        runner: [macos-15-intel, macos-14]
        llvm:
          - version: "18.1"
            full_version: "18.1.8"
            short_version: 18
          - version: "19.1"
            full_version: "19.1.7"
            short_version: 19
          - version: "20.1"
            full_version: "20.1.8"
            short_version: 20
          - version: "21.1"
            full_version: "21.1.8"
            short_version: 21
    uses: ./.github/workflows/reusable.ispc.build.yml
    with:
      platform: macos
      artifact_name: ispc_llvm${{ matrix.llvm.short_version }}_${{ matrix.runner }}
      runner: ${{ matrix.runner }}
      llvm_version: ${{ matrix.llvm.version }}
      llvm_tar: llvm-${{ matrix.llvm.full_version }}-macos-Release+Asserts-universal-x86.arm.wasm.tar.xz

  macos-build-ispc-llvm21-lto:
    needs: [define-flow]
    uses: ./.github/workflows/reusable.ispc.build.yml
    with:
      platform: macos
      artifact_name: ispc_llvm21_lto_macos
      runner: macos-15-intel
      llvm_version: 21.1
      llvm_tar: llvm-21.1.8-macos-Release-lto-universal-x86.arm.wasm.tar.xz
      enable_lto: true

  macos-test-ispc:
    needs: [define-flow, macos-build-ispc]
    strategy:
      fail-fast: false
      matrix:
        llvm: [18, 19, 20, 21]
    uses: ./.github/workflows/reusable.ispc.test.yml
    with:
      platform: macos
      architecture: x86-64
      artifact_name: ispc_llvm${{matrix.llvm}}_macos-15-intel
      targets: '["sse2-i32x4", "sse4-i32x4"]'
      optsets: -O0 -O2

  macos-test-ispc-llvm21-lto:
    needs: [define-flow, macos-build-ispc-llvm21-lto]
    uses: ./.github/workflows/reusable.ispc.test.yml
    with:
      platform: macos
      architecture: x86-64
      artifact_name: ispc_llvm21_lto_macos
      targets: '["sse4-i32x4"]'
      optsets: -O0 -O2
      enable_lto: true

  macos-test-ispc-llvm21-arm64:
    needs: [define-flow, macos-build-ispc]
    uses: ./.github/workflows/reusable.ispc.test.yml
    with:
      platform: macos
      architecture: aarch64
      artifact_name: ispc_llvm21_macos-14
      targets: ${{ needs.define-flow.outputs.tests_matrix_targets_arm }}
      optsets: ${{ needs.define-flow.outputs.tests_optsets }}

  macos-test-flags:
    needs: [define-flow, macos-build-ispc]
    strategy:
      fail-fast: false
      matrix:
        llvm: [21]
        # --math-lib=fast and --opt=fast-math are not tested because of #3442
        # --opt=disable-zmm is not applicable for ARM targets
        extra_flags: ["--addressing=64", "-g",
                      "--math-lib=system", "--mcmodel=large", "--pic",
                      "--no-wrap-signed-int",  "--opt=disable-fma"]
    uses: ./.github/workflows/reusable.ispc.test.yml
    with:
      platform: macos
      architecture: aarch64
      artifact_name: ispc_llvm${{ matrix.llvm }}_macos-14
      targets: '["neon-i32x4"]'
      optsets: -O0 -O2
      ispc_extra_flags: ${{ matrix.extra_flags }}

  win-build-ispc:
    needs: [define-flow]
    strategy:
      fail-fast: false
      matrix:
        llvm:
          - version: "18.1"
            full_version: "18.1.8"
            short_version: 18
            vs_version: "vs2022"
          - version: "19.1"
            full_version: "19.1.7"
            short_version: 19
            vs_version: "vs2022"
          - version: "20.1"
            full_version: "20.1.8"
            short_version: 20
            vs_version: "vs2022"
          - version: "21.1"
            full_version: "21.1.8"
            short_version: 21
            vs_version: "vs2022"
    uses: ./.github/workflows/reusable.ispc.build.yml
    with:
      platform: windows
      artifact_name: ispc_llvm${{ matrix.llvm.short_version }}_win
      runner: windows-2022
      llvm_version: ${{ matrix.llvm.version }}
      llvm_tar: llvm-${{ matrix.llvm.full_version }}-win.${{ matrix.llvm.vs_version }}-Release+Asserts-x86.arm.wasm.tar.7z

  win-build-ispc-llvm21-lto:
    needs: [define-flow]
    uses: ./.github/workflows/reusable.ispc.build.yml
    with:
      platform: windows
      artifact_name: ispc_llvm21_lto_win
      runner: windows-2022
      llvm_version: 21.1
      llvm_tar: llvm-21.1.8-win.vs2022-Release+Asserts-lto-x86.arm.wasm.tar.7z
      enable_lto: true

  win-build-ispc-xe-llvm21-release:
    needs: [define-flow]
    uses: ./.github/workflows/reusable.ispc.build.yml
    with:
      platform: windows
      artifact_name: ispc_xe_llvm21rel_win
      runner: windows-2022
      llvm_version: 21.1
      llvm_tar: llvm-21.1.8-win.vs2022-Release-x86.arm.wasm.tar.7z
      enable_xe: true

  win-build-ispc-wasm:
    needs: [define-flow]
    uses: ./.github/workflows/reusable.ispc.build.yml
    with:
      platform: windows
      artifact_name: ispc-wasm-windows
      runner: windows-2022
      llvm_version: 21.1
      llvm_tar: llvm-21.1.8-win.vs2022-Release+Asserts-x86.arm.wasm.tar.7z
      enable_wasm: true

  win-test:
    needs: [define-flow, win-build-ispc]
    strategy:
      fail-fast: false
      matrix:
        llvm: [18, 19, 20, 21]
        arch: [x86, x86-64]
    uses: ./.github/workflows/reusable.ispc.test.yml
    with:
      platform: windows
      architecture: ${{ matrix.arch }}
      artifact_name: ispc_llvm${{matrix.llvm}}_win
      targets: ${{ needs.define-flow.outputs.tests_matrix_targets_x86 }}
      optsets: ${{ needs.define-flow.outputs.tests_optsets }}

  win-test-flags:
    needs: [define-flow, win-build-ispc]
    strategy:
      fail-fast: false
      matrix:
        # --math-lib=fast and --opt=fast-math are not tested because of #3442
        include:
          - llvm: 21
            arch: x86-64
            extra_flags: "--opt=disable-zmm"
            targets: '["avx512skx-x16"]'
          - llvm: 21
            arch: x86-64
            extra_flags: "--addressing=64"
            targets: '["avx2-i32x8"]'
          - llvm: 21
            arch: x86
            extra_flags: "--addressing=64"
            targets: '["avx2-i32x8"]'
          - llvm: 21
            arch: x86-64
            extra_flags: "-g"
            targets: '["avx2-i32x8"]'
          - llvm: 21
            arch: x86
            extra_flags: "-g"
            targets: '["avx2-i32x8"]'
          - llvm: 21
            arch: x86-64
            extra_flags: "--math-lib=system"
            targets: '["avx2-i32x8"]'
          - llvm: 21
            arch: x86
            extra_flags: "--pic"
            targets: '["avx2-i32x8"]'
          - llvm: 21
            arch: x86-64
            extra_flags: "--pic"
            targets: '["avx2-i32x8"]'
          - llvm: 21
            arch: x86-64
            extra_flags: "--mcmodel=large"
            targets: '["avx2-i32x8"]'
          - llvm: 21
            arch: x86
            extra_flags: "--no-wrap-signed-int"
            targets: '["avx2-i32x8"]'
          - llvm: 21
            arch: x86-64
            extra_flags: "--no-wrap-signed-int"
            targets: '["avx2-i32x8"]'
          - llvm: 21
            arch: x86
            extra_flags: "--opt=disable-fma"
            targets: '["avx2-i32x8"]'
          - llvm: 21
            arch: x86-64
            extra_flags: "--opt=disable-fma"
            targets: '["avx2-i32x8"]'
    uses: ./.github/workflows/reusable.ispc.test.yml
    with:
      platform: windows
      architecture: ${{ matrix.arch }}
      artifact_name: ispc_llvm${{matrix.llvm}}_win
      targets: ${{ matrix.targets }}
      optsets: ${{ needs.define-flow.outputs.tests_optsets }}
      ispc_extra_flags: ${{ matrix.extra_flags }}

  win-test-llvm21-lto:
    needs: [define-flow, win-build-ispc-llvm21-lto]
    strategy:
      fail-fast: false
      matrix:
        arch: [x86, x86-64]
    uses: ./.github/workflows/reusable.ispc.test.yml
    with:
      platform: windows
      architecture: ${{ matrix.arch }}
      artifact_name: ispc_llvm21_lto_win
      targets: ${{ needs.define-flow.outputs.tests_matrix_targets_x86 }}
      optsets: ${{ needs.define-flow.outputs.tests_optsets }}
      enable_lto: true

  # Test xe release version
  win-test-xe-llvm21-release:
    needs: [define-flow, win-build-ispc-xe-llvm21-release]
    if: ${{ needs.define-flow.outputs.flow_type == 'smoke' }}
    strategy:
      fail-fast: false
      matrix:
        arch: [x86, x86-64]
    uses: ./.github/workflows/reusable.ispc.test.yml
    with:
      platform: windows
      architecture: ${{ matrix.arch }}
      artifact_name: ispc_xe_llvm21rel_win
      targets: '["avx2-i32x8"]'
      optsets: ${{ needs.define-flow.outputs.tests_optsets }}
      enable_xe: true

  win-test-llvm21-aarch64:
    needs: [define-flow, win-build-ispc]
    uses: ./.github/workflows/reusable.ispc.test.yml
    with:
      platform: windows
      architecture: aarch64
      artifact_name: ispc_llvm21_win
      targets: ${{ needs.define-flow.outputs.tests_matrix_targets_arm }}
      optsets: ${{ needs.define-flow.outputs.tests_optsets }}

  win-test-llvm21-vectorcall:
    needs: [define-flow, win-build-ispc-xe-llvm21-release]
    uses: ./.github/workflows/reusable.ispc.test.yml
    with:
      platform: windows
      architecture: x86-64
      artifact_name: ispc_xe_llvm21rel_win
      targets: '["avx2-i32x8"]'
      optsets: O2
      calling_conv: vectorcall

  win-package-examples:
    needs: [define-flow]
    runs-on: windows-2022

    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: Build examples package
      run: |
        cmake -B build ./ -DISPC_PREPARE_PACKAGE=ON
        cmake --build build --target package-examples

    - name: Upload examples package
      uses: actions/upload-artifact@b7c566a772e6b6bfb58ed0dc250532a479d7789f # v6.0.0
      with:
        name: examples_zip
        path: build/ispc-examples-*.zip

  linux-package-examples:
    needs: [define-flow]
    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: Build examples package
      run: |
        cmake -B build ./ -DISPC_PREPARE_PACKAGE=ON
        cmake --build build --target package-examples

    - name: Upload package
      uses: actions/upload-artifact@b7c566a772e6b6bfb58ed0dc250532a479d7789f # v6.0.0
      with:
        name: examples_tgz
        path: build/ispc-examples-*.tar.gz

  win-examples:
    needs: [win-package-examples, win-build-ispc]
    runs-on: windows-2022
    steps:
    - uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0
      with:
        submodules: true
    - name: Download ispc package
      uses: actions/download-artifact@37930b1c2abaa49bbe596cd826c3c89aef350131 # v7.0.0
      with:
        name: ispc_llvm21_win

    - name: Download examples package
      uses: actions/download-artifact@37930b1c2abaa49bbe596cd826c3c89aef350131 # v7.0.0
      with:
        name: examples_zip
        path: examples-package

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

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

    - name: Unpack examples
      run: |
        for %%f in (ispc-examples-*.zip) do unzip "%%f"
      working-directory: examples-package
      shell: cmd

    - name: Run performance tests
      shell: cmd
      run: |
        set VSVARS="C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Auxiliary\Build\vcvars64.bat"
        call %VSVARS%
        for /d %%d in (%GITHUB_WORKSPACE%\ispc-*-windows) do set PATH=%%d\bin;%PATH%
        python scripts\perf.py -n 1 -g "Visual Studio 17 2022"

    - name: Build examples
      run: |
        cmake -DCMAKE_C_FLAGS="/WX" -DCMAKE_CXX_FLAGS="/WX" examples-package\examples\cpu -B examples-build -Thost=x64 -G "Visual Studio 17 2022"
        cmake --build examples-build --target ALL_BUILD --config Release
      shell: cmd

    - name: Run examples
      shell: cmd
      run: |
        ctest --test-dir examples-build -C Release --output-on-failure

  linux-examples:
    needs: [linux-package-examples, linux-build-ispc]
    runs-on: ubuntu-22.04
    steps:
    - uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0
      with:
        submodules: true
    - name: Download ispc package
      uses: actions/download-artifact@37930b1c2abaa49bbe596cd826c3c89aef350131 # v7.0.0
      with:
        name: ispc_llvm21_linux

    - name: Download examples package
      uses: actions/download-artifact@37930b1c2abaa49bbe596cd826c3c89aef350131 # v7.0.0
      with:
        name: examples_tgz
        path: examples-package

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

    - name: Unpack examples
      run: |
        tar xf ispc-examples-*.tar.gz
      working-directory: examples-package

    - name: Run performance tests
      run: python scripts/perf.py

    - name: Build examples
      run: |
        cmake \
            -B examples-build \
            -DCMAKE_C_COMPILER=clang \
            -DCMAKE_CXX_COMPILER=clang++ \
            examples-package/examples/cpu
        cmake --build examples-build

    - name: Run examples
      run: |
        ctest --test-dir examples-build -C Release --output-on-failure

  macos-examples:
    needs: [linux-package-examples, macos-build-ispc]
    runs-on: macos-14
    steps:
    - uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0
      with:
        submodules: true
    - name: Download ispc package
      uses: actions/download-artifact@37930b1c2abaa49bbe596cd826c3c89aef350131 # v7.0.0
      with:
        name: ispc_llvm21_macos-14

    - name: Download examples package
      uses: actions/download-artifact@37930b1c2abaa49bbe596cd826c3c89aef350131 # v7.0.0
      with:
        name: examples_tgz
        path: examples-package

    - name: Install dependencies and unpack artifacts
      run: |
        ISPC_TAR=$(ls ispc-*-macos.tar.gz)
        tar xf "$ISPC_TAR"
        ISPC_DIR=$(basename "$ISPC_TAR" .tar.gz)
        echo "$GITHUB_WORKSPACE/$ISPC_DIR/bin" >> "$GITHUB_PATH"
        echo "ISPC_HOME=$GITHUB_WORKSPACE" >> "$GITHUB_ENV"
        pip install nanobind

    - name: Unpack examples
      run: |
        tar xf ispc-examples-*.tar.gz
      working-directory: examples-package

    - name: Build examples
      run: |
        cmake -DCMAKE_C_FLAGS="-Wall -Werror" -DCMAKE_CXX_FLAGS="-Wall -Werror" examples-package/examples/cpu -B examples-build
        cmake --build examples-build

    - name: Run examples
      run: |
        ctest --test-dir examples-build -C Release --output-on-failure
