version: '3'

vars:
  PHP_CONFIG: /opt/homebrew/opt/php@8.4-zts/bin/php-config
  CGO_CFLAGS:
    sh: "{{.PHP_CONFIG}} --includes"
  CGO_LDFLAGS:
    sh: "echo -L/opt/homebrew/opt/php@8.4-zts/lib $({{.PHP_CONFIG}} --ldflags) $({{.PHP_CONFIG}} --libs)"

tasks:
  setup:
    desc: "Install PHP-ZTS build dependency"
    cmds:
      - brew tap shivammathur/php 2>/dev/null || true
      - brew install shivammathur/php/php@8.4-zts

  build:
    desc: "Build core-app binary"
    env:
      CGO_ENABLED: "1"
      CGO_CFLAGS: "{{.CGO_CFLAGS}}"
      CGO_LDFLAGS: "{{.CGO_LDFLAGS}}"
    cmds:
      - go build -tags nowatcher -o ../../bin/core-app .

  dev:
    desc: "Build and run core-app"
    deps: [build]
    env:
      DYLD_LIBRARY_PATH: "/opt/homebrew/opt/php@8.4-zts/lib"
    cmds:
      - ../../bin/core-app

  clean:
    desc: "Remove build artifacts"
    cmds:
      - rm -f ../../bin/core-app
