Mooncake/mooncake-integration/ollama/scripts/gen_protos.sh

40 lines
1.5 KiB
Bash

#!/usr/bin/env bash
# Generate gRPC stubs for both protos, into the Go module and the Python proxy.
# The generated stubs are checked in, so this is only needed after editing a
# .proto. Requires protoc + the Go protoc plugins (installed by setup_go.sh).
set -euo pipefail
source "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/env.sh"
cd "$WS"
GO_MOD="github.com/mooncake-ai/ollama-mooncake-bridge"
GO_OUT="bridge"
# Wait for Go protoc plugins if a background install is still finishing.
for _ in $(seq 1 60); do
[ -x "$GOBIN/protoc-gen-go" ] && [ -x "$GOBIN/protoc-gen-go-grpc" ] && break
sleep 2
done
echo "[proto] Go stubs (storeproxy + bridge)"
protoc -I proto -I bridge/api \
--plugin=protoc-gen-go="$GOBIN/protoc-gen-go" \
--plugin=protoc-gen-go-grpc="$GOBIN/protoc-gen-go-grpc" \
--go_out="$GO_OUT" --go_opt=module="$GO_MOD" \
--go-grpc_out="$GO_OUT" --go-grpc_opt=module="$GO_MOD" \
proto/storeproxy.proto bridge/api/bridge.proto
echo "[proto] Python stubs (storeproxy) -> store-proxy/gen"
mkdir -p store-proxy/gen
python -m grpc_tools.protoc -I proto \
--python_out=store-proxy/gen \
--grpc_python_out=store-proxy/gen \
proto/storeproxy.proto
# make 'gen' a package and fix the absolute import grpc_tools emits
touch store-proxy/gen/__init__.py
sed -i 's/^import storeproxy_pb2 as/from . import storeproxy_pb2 as/' \
store-proxy/gen/storeproxy_pb2_grpc.py 2>/dev/null || true
echo "[proto] done"
find "$GO_OUT/internal" -name '*.pb.go' 2>/dev/null
ls store-proxy/gen