## Copyright 2009 Intel Corporation
## SPDX-License-Identifier: Apache-2.0

name: CI MacOS

on:
  push:
  workflow_dispatch:

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

permissions: read-all

jobs:

### BUILD JOBS ###

  build-osx-clang:
    uses: intel-innersource/libraries.devops.renderkit.workflows/.github/workflows/macos.yml@main
    secrets: inherit
    with:
      runs-on: '["x86_64", "build"]'
      cmd: |
        scripts/build/macosx.sh -DBUILD_OSPRAY_MODULE_MULTIDEVICE=ON
      artifact-out: build-osx-clang
      artifact-path: build/install/ospray build/CMakeCache.txt build/*/build/CMakeCache.txt

  build-osx-arm:
    uses: intel-innersource/libraries.devops.renderkit.workflows/.github/workflows/macos.yml@main
    secrets: inherit
    with:
      runs-on: '["arm", "build"]'
      cmd: |
        scripts/build/macosx.sh -DBUILD_TBB_FROM_SOURCE=ON -DBUILD_OPENVKL_FROM_SOURCE=ON
      artifact-out: build-osx-arm
      artifact-path: build/install/ospray build/CMakeCache.txt build/*/build/CMakeCache.txt

  build-osx-x64-on-arm:
    uses: intel-innersource/libraries.devops.renderkit.workflows/.github/workflows/macos.yml@main
    secrets: inherit
    with:
      runs-on: '["arm", "build"]'
      cmd: |
        scripts/build/macosx.sh -DCMAKE_TOOLCHAIN_FILE=../scripts/superbuild/toolchains/macos-rosetta.cmake -DBUILD_TBB_FROM_SOURCE=ON -DBUILD_EMBREE_FROM_SOURCE=ON -DBUILD_OPENVKL_FROM_SOURCE=ON -DBUILD_OIDN_FROM_SOURCE=ON -DBUILD_ISA_AVX=OFF -DBUILD_ISA_AVX2=OFF -DBUILD_ISA_AVX512=OFF
      artifact-out: build-osx-x64
      artifact-path: build/install/ospray build/CMakeCache.txt build/*/build/CMakeCache.txt

### TEST JOBS ###

  test-osx-clang:
    needs: build-osx-clang
    uses: intel-innersource/libraries.devops.renderkit.workflows/.github/workflows/macos.yml@main
    with:
      runs-on: '["x86_64", "avx2", "build"]'
      cmd: |
        export PATH="$GITHUB_WORKSPACE/build/install/ospray/bin:$PATH"
        scripts/tests/run_tests.sh "$GITHUB_WORKSPACE" AVX2 TEST_MULTIDEVICE
      artifact-in: build-osx-clang
      artifact-out: test-osx-clang
      artifact-path: build_regression_tests/tests*.xml build_regression_tests/failed*
      artifact-on-failure: true

  test-osx-arm:
    needs: build-osx-arm
    uses: intel-innersource/libraries.devops.renderkit.workflows/.github/workflows/macos.yml@main
    with:
      runs-on: '["arm", "build"]'
      cmd: |
        export PATH="$GITHUB_WORKSPACE/build/install/ospray/bin:$PATH"
        scripts/tests/run_tests.sh "$GITHUB_WORKSPACE" AVX512SKX
      artifact-in: build-osx-arm
      artifact-out: test-osx-arm
      artifact-path: build_regression_tests/tests*.xml build_regression_tests/failed*
      artifact-on-failure: true

  test-osx-x64-on-arm:
    needs: build-osx-x64-on-arm
    uses: intel-innersource/libraries.devops.renderkit.workflows/.github/workflows/macos.yml@main
    with:
      runs-on: '["arm", "build"]'
      cmd: |
        export PATH="$GITHUB_WORKSPACE/build/install/ospray/bin:$PATH"
        scripts/tests/run_tests.sh "$GITHUB_WORKSPACE" AVX512SKX
      artifact-in: build-osx-x64
      artifact-out: test-osx-x64
      artifact-path: build_regression_tests/tests*.xml build_regression_tests/failed*
      artifact-on-failure: true
