distributable:
  url: https://github.com/ggerganov/whisper.cpp/archive/refs/tags/v{{version}}.tar.gz
  strip-components: 1

versions:
  github: ggerganov/whisper.cpp

platforms:
  - darwin/aarch64
  - linux

provides:
  - bin/whisper.cpp

dependencies:
  libsdl.org: '*'

build:
  dependencies:
    freedesktop.org/pkg-config: ~0.29
    gnu.org/patch: '*'
    gnu.org/coreutils: '*'
  script:
    - run: patch -p1 < props/illegal_instruction.patch
      if: <1.4.3

    - make --jobs {{ hw.concurrency }}
    - make stream --jobs {{ hw.concurrency }}
    - make command --jobs {{ hw.concurrency }}

    # ggml-metal.metal must be installed alongside whisper.cpp sadly
    - install -Dt {{prefix}}/bin
        ggml-metal.metal
        stream command
        models/download-ggml-model.sh

    - install -D main {{prefix}}/bin/whisper.cpp

    - install -D examples/command/commands.txt {{prefix}}/share/whisper.cpp/commands.txt

test:
  env:
    cache: $HOME/.cache/huggingface
  script: |
    huggingface-cli download ggerganov/whisper.cpp ggml-base.en.bin
    model="$(find "$cache" -name "ggml-base.en.bin")"
    curl https://github.com/ggerganov/whisper.cpp/raw/master/samples/jfk.wav | whisper.cpp --model "$model" -
  cache:
    $HOME/.cache/huggingface
