export RUSTFLAGS := "-C target-cpu=native"
export WEBKIT_DISABLE_COMPOSITING_MODE := "1"

build:
  cargo tauri build --no-bundle -- --profile dev

run:
  cargo tauri dev

fmt:
  cargo +nightly fmt

_fix:
  cargo fix
  cargo clippy --fix

fix: _fix fmt

clippy:
  cargo clippy

test:
  cargo test --workspace

clean:
  cargo clean

peer-cli-build:
  cargo build -p lanspread-peer-cli

peer-cli-image:
  docker build -f crates/lanspread-peer-cli/Dockerfile -t lanspread-peer-cli:dev .

# macvlan: each peer container gets its own MAC/IP on the real LAN.
# Override on the command line if your LAN differs, e.g.
#   just LANSPREAD_PARENT_IFACE=enp4s0 LANSPREAD_SUBNET=10.0.0.0/24 LANSPREAD_GATEWAY=10.0.0.1 peer-cli-net
LANSPREAD_NET := "lanspread"
LANSPREAD_PARENT_IFACE := "eth0"
LANSPREAD_SUBNET := "192.168.1.0/24"
LANSPREAD_GATEWAY := "192.168.1.1"

peer-cli-net:
  docker network inspect {{LANSPREAD_NET}} >/dev/null 2>&1 || \
    docker network create -d macvlan \
      --subnet={{LANSPREAD_SUBNET}} \
      --gateway={{LANSPREAD_GATEWAY}} \
      -o parent={{LANSPREAD_PARENT_IFACE}} \
      {{LANSPREAD_NET}}

peer-cli-run NAME: peer-cli-net
  mkdir -p ".lanspread-peer-cli/{{NAME}}/state" ".lanspread-peer-cli/{{NAME}}/games"
  docker run --rm --init --network {{LANSPREAD_NET}} --name "lanspread-peer-cli-{{NAME}}" -i \
    -v "$PWD/.lanspread-peer-cli/{{NAME}}/state:/state" \
    -v "$PWD/.lanspread-peer-cli/{{NAME}}/games:/games" \
    lanspread-peer-cli:dev \
    --name "{{NAME}}" \
    --games-dir /games \
    --state-dir /state \
    --catalog-db /app/game.db

peer-cli-alpha: peer-cli-net
  mkdir -p ".lanspread-peer-cli/alpha/state"
  docker run --rm --init --network lanspread --name "lanspread-peer-cli-alpha" -i \
    -v "$PWD/.lanspread-peer-cli/alpha/state:/state" \
    -v "$PWD/crates/lanspread-peer-cli/fixtures/fixture-alpha:/games:ro" \
    lanspread-peer-cli:dev \
    --name "alpha" \
    --games-dir /games \
    --state-dir /state \
    --catalog-db /app/game.db

peer-cli-bravo: peer-cli-net
  mkdir -p ".lanspread-peer-cli/bravo/state"
  docker run --rm --init --network lanspread --name "lanspread-peer-cli-bravo" -i \
    -v "$PWD/.lanspread-peer-cli/bravo/state:/state" \
    -v "$PWD/crates/lanspread-peer-cli/fixtures/fixture-bravo:/games:ro" \
    lanspread-peer-cli:dev \
    --name "bravo" \
    --games-dir /games \
    --state-dir /state \
    --catalog-db /app/game.db

peer-cli-charlie: peer-cli-net
  mkdir -p ".lanspread-peer-cli/charlie/state"
  docker run --rm --init --network lanspread --name "lanspread-peer-cli-charlie" -i \
    -v "$PWD/.lanspread-peer-cli/charlie/state:/state" \
    -v "$PWD/crates/lanspread-peer-cli/fixtures/fixture-charlie:/games:ro" \
    lanspread-peer-cli:dev \
    --name "charlie" \
    --games-dir /games \
    --state-dir /state \
    --catalog-db /app/game.db
