Files
neuron-tai/packages/node/native/scripts/generate_cpp.sh
2026-07-15 23:42:58 +03:00

44 lines
1.5 KiB
Bash

#!/usr/bin/env bash
# Reproducibly generate the C++ Shard-protocol stubs from the schema.
#
# Produces message stubs (protoc --cpp_out) always, and gRPC C++ service stubs
# (protoc --grpc_out with grpc_cpp_plugin) when the plugin is available. The
# round-trip test needs only the message stubs; gRPC service stubs are for the
# standalone C++ worker (DGR-008).
#
# Requirements: protoc (>=3.16). Optional: grpc_cpp_plugin for --grpc_out.
#
# Usage:
# packages/node/native/scripts/generate_cpp.sh
# Output: packages/node/native/build/cpp-gen/ (gitignored via build/).
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
NATIVE_ROOT="$(cd "${SCRIPT_DIR}/.." && pwd)"
PROTO_DIR="${NATIVE_ROOT}/proto"
PROTO_FILE="${PROTO_DIR}/shard_runtime.proto"
OUT_DIR="${NATIVE_ROOT}/build/cpp-gen"
if ! command -v protoc >/dev/null 2>&1; then
echo "error: protoc not found on PATH (install protobuf-compiler)." >&2
exit 3
fi
mkdir -p "${OUT_DIR}"
echo "generating C++ message stubs -> ${OUT_DIR}"
protoc --proto_path="${PROTO_DIR}" --cpp_out="${OUT_DIR}" "${PROTO_FILE}"
if command -v grpc_cpp_plugin >/dev/null 2>&1; then
echo "generating C++ gRPC service stubs -> ${OUT_DIR}"
protoc --proto_path="${PROTO_DIR}" \
--grpc_out="${OUT_DIR}" \
--plugin=protoc-gen-grpc="$(command -v grpc_cpp_plugin)" \
"${PROTO_FILE}"
else
echo "note: grpc_cpp_plugin not found; skipped --grpc_out (message stubs only)." >&2
fi
echo "done:"
ls -1 "${OUT_DIR}"