name: Build macOS Binaries

on:
  workflow_dispatch:

jobs:
  build:
    name: Build macOS binaries
    runs-on: macos-latest

    steps:
      - uses: actions/checkout@v4.2.2

      - name: Install Rust
        uses: dtolnay/rust-toolchain@stable
        with:
          targets: aarch64-apple-darwin,x86_64-apple-darwin

      - name: Install dependencies
        run: |
          brew update
          brew install openssl@3 protobuf pkg-config node

      - name: Build x86_64 binary
        run: |
          RUSTFLAGS="-C link-arg=-s -C target-cpu=x86-64-v3" \
          cargo build --release --target x86_64-apple-darwin
          mv target/x86_64-apple-darwin/release/cursor-api cursor-api-x86_64-apple-darwin

      - name: Build arm64 binary
        run: |
          RUSTFLAGS="-C link-arg=-s -C target-cpu=apple-m1" \
          cargo build --release --target aarch64-apple-darwin
          mv target/aarch64-apple-darwin/release/cursor-api cursor-api-aarch64-apple-darwin

      - name: Create universal binary
        run: |
          lipo -create \
            cursor-api-x86_64-apple-darwin \
            cursor-api-aarch64-apple-darwin \
            -output cursor-api-universal-apple-darwin

      - name: Upload artifacts
        uses: actions/upload-artifact@v4.6.0
        with:
          name: cursor-api-darwin
          path: |
            cursor-api-x86_64-apple-darwin
            cursor-api-aarch64-apple-darwin
            cursor-api-universal-apple-darwin
