#!/bin/bash
# Build script for ARM64/Raspberry Pi
# Run this directly on your Raspberry Pi

echo "🦾 Building msger for ARM64..."

# Check for Rust
if ! command -v cargo &> /dev/null; then
    echo "📦 Installing Rust..."
    curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
    source "$HOME/.cargo/env"
fi

# Check for build dependencies
echo "🔍 Checking for build dependencies..."
if ! pkg-config --exists gtk+-3.0 webkit2gtk-4.1; then
    echo "📦 Installing build dependencies..."
    sudo apt-get update
    sudo apt-get install -y pkg-config libgtk-3-dev libwebkit2gtk-4.1-dev libsoup-3.0-dev
fi

# Build
echo "📦 Building binary..."
cargo build --release

# Copy binary
echo "📋 Copying binary..."
mkdir -p bin
cp target/release/msgernative bin/msgernative-arm64
chmod +x bin/msgernative-arm64

echo "✅ Build complete! Binary is at: bin/msgernative-arm64"
echo ""
echo "To use it in the npm package, copy it to:"
echo "  msger-native/bin/msgernative-arm64"
