#!/usr/bin/env bash
set -e

(
  cd third_party/tools
  ./build.sh
)

third_party/tools/bin/buf generate

# cargo install serde-generate
if command -v serdegen &> /dev/null
then
  serdegen ./pkg/gossip/schema.yaml \
    --language=Go \
    --with-runtimes=Bincode \
    --module-name=gossip \
    --serde-package-name=gossip \
    > ./pkg/gossip/schema.go
  sed -i'.bak' '1s/^/\/\/ Code generated by "serde-generate"; DO NOT EDIT.\n\n/' ./pkg/gossip/schema.go
  rm -f ./pkg/gossip/schema.go.bak
  go fmt ./pkg/gossip/schema.go
fi
