name: github-OSX

on:
  workflow_call:

concurrency:
  group: ${ {github.event_name }}-${{ github.workflow }}-${{ github.ref }}-osx-x64
  cancel-in-progress: ${{github.event_name == 'pull_request'}}

permissions: read-all

jobs:
  osxci:
    name: osx-ci

    continue-on-error: true
    strategy:
      matrix:
        include:
          - backend: "SERIAL"
            cmake_build_type: "RelWithDebInfo"
            cxx_standard: "20"
            compiler: "c++"
            runner: "macos-14"
            cmake_extra_opts: '-DCMAKE_CXX_CLANG_TIDY="$(brew --prefix llvm)/bin/clang-tidy;-warnings-as-errors=*"'
          - backend: "THREADS"
            cmake_build_type: "RelWithDebInfo"
            cxx_standard: "20"
            compiler: "c++"
            runner: "macos-14"
          - backend: "SERIAL"
            cmake_build_type: "Debug"
            cxx_standard: "20"
            compiler: "c++"
            runner: "macos-14"
            cmake_extra_opts: '-DCMAKE_CXX_CLANG_TIDY="$(brew --prefix llvm)/bin/clang-tidy;-warnings-as-errors=*"'
          - backend: "SERIAL"
            cmake_build_type: "Release"
            cxx_standard: "20"
            compiler: "c++"
            runner: "macos-14"
            cmake_extra_opts: '-DCMAKE_CXX_CLANG_TIDY="$(brew --prefix llvm)/bin/clang-tidy;-warnings-as-errors=*"'
          # Testing a compiler with mdspan implementation (clang 18.1.8+libc++)
          - backend: "SERIAL"
            cmake_build_type: "RelWithDebInfo"
            cxx_standard: "23"
            compiler: "$(brew --prefix llvm@18)/bin/clang++"
            runner: "macos-15"
            cmake_extra_opts: '-DCMAKE_CXX_CLANG_TIDY="$(brew --prefix llvm@18)/bin/clang-tidy;-warnings-as-errors=*"'

    runs-on: ${{ matrix.runner }}

    steps:
      - uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
      - name: Install ccache llvm
        run: |
          brew update
          brew install ccache llvm
      - uses: actions/cache@9255dc7a253b0ccc959486e2bca901246202afeb # v5.0.1
        with:
          path: ~/.cache/ccache
          key: kokkos-osx-${{ matrix.cmake_build_type }}-${{ matrix.backend }}-${{ matrix.cxx_standard }}-${{ github.ref }}-${{ github.sha }}
          restore-keys: kokkos-osx-${{ matrix.cmake_build_type }}-${{ matrix.backend }}-${{ matrix.cxx_standard }}-${{ github.ref }}
      - name: configure
        run:
          cmake -B build .
            -DKokkos_ENABLE_${{ matrix.backend }}=ON
            -DCMAKE_CXX_COMPILER=${{ matrix.compiler }}
            -DCMAKE_CXX_STANDARD=${{ matrix.cxx_standard }}
            -DKokkos_ARCH_NATIVE=ON
            -DKokkos_ENABLE_COMPILER_WARNINGS=ON
            ${{ matrix.cmake_extra_opts }}
            -DKokkos_ENABLE_DEPRECATED_CODE_4=OFF
            -DKokkos_ENABLE_TESTS=ON
            -DKokkos_ENABLE_DEBUG_BOUNDS_CHECK=ON
            -DCMAKE_BUILD_TYPE=${{ matrix.cmake_build_type }}
            -DCMAKE_CXX_COMPILER_LAUNCHER=ccache
      - name: build
        run: cmake --build build --parallel $(sysctl -n hw.ncpu)
      - name: test
        run: ctest --test-dir build -j$(sysctl -n hw.ncpu) --output-on-failure
