name: CI (macOS)

on:
  workflow_dispatch: # allows manual triggering
  push:
    branches:
      - master
    paths: ['.github/workflows/build-macos.yml',
            '**/CMakeLists.txt',
            '**/Makefile',
            '**/*.mk',
            '**/*.cmake',
            '**/*.in',
            '**/*.h',
            '**/*.hpp',
            '**/*.c',
            '**/*.cpp',
            '**/*.cu',
            '**/*.cuh',
            '**/*.swift',
            '**/*.m',
            '**/*.mm',
            '**/*.metal']

  pull_request:
    types: [opened, synchronize, reopened]
    paths-ignore:
      - 'bindings/ruby/**'        # handled by bindings-ruby.yml
      - 'bindings/go/**'          # handled by bindings-go.yml
      - 'examples/addon.node/**'  # handled by examples.yml

concurrency:
  group: ${{ github.workflow }}-${{ github.head_ref && github.ref || github.run_id }}
  cancel-in-progress: true

jobs:
  macOS-latest:
    runs-on: macOS-latest

    strategy:
      matrix:
        destination: ['generic/platform=macOS', 'generic/platform=iOS', 'generic/platform=tvOS']

    steps:
      - name: Clone
        id: checkout
        uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6

      - name: ccache
        uses: ggml-org/ccache-action@v1.2.21
        with:
          key: macos-${{ matrix.destination }}
          evict-old-files: 1d
          save: ${{ github.event_name == 'push' && github.ref == 'refs/heads/master' }}

      - name: Dependencies
        run: |
          brew update
          cmake --version
          brew install sdl2

      - name: Build
        run: |
          sysctl -a
          cmake -B build -G Xcode \
            -DGGML_NATIVE=OFF \
            -DGGML_METAL_USE_BF16=ON \
            -DGGML_METAL_EMBED_LIBRARY=ON \
            -DWHISPER_BUILD_EXAMPLES=OFF \
            -DWHISPER_BUILD_TESTS=OFF \
            -DWHISPER_BUILD_SERVER=OFF \
            -DCMAKE_OSX_ARCHITECTURES="arm64;x86_64"
          cmake --build build --config Release -j $(sysctl -n hw.logicalcpu)
