#!/usr/bin/env bash # Build a protobuf C++ toolchain for the native Shard protocol. # # The Python side needs nothing beyond `pip install grpcio-tools` — it bundles # protoc. The C++ side needs libprotobuf headers and a protoc binary, and a # machine that has neither (no protobuf-devel, no cmake, no system protoc) can # still get a working one from source with this script. It is the exact recipe # DGR-002 used to build and run the C++ conformance test. # # gRPC C++ is deliberately NOT built here. The conformance test only needs # message types, so verifying the schema does not require the whole gRPC stack. # The worker (DGR-008) will need gRPC C++ and should extend this script then. # # Usage: # scripts/bootstrap_native_toolchain.sh [install-prefix] # # Then: # cmake -S packages/node/native -B build/native -DCMAKE_PREFIX_PATH= # cmake --build build/native -j # ctest --test-dir build/native --output-on-failure set -euo pipefail PREFIX="${1:-${PWD}/build/native-toolchain}" WORK="$(mktemp -d)" trap 'rm -rf "${WORK}"' EXIT # Pinned: the C++ runtime a generated stub is compiled against must be a version # that stub is allowed to use, so these are exact, not floating. PROTOBUF_VERSION="33.1" ABSEIL_VERSION="20250814.1" command -v cmake >/dev/null || { echo "cmake is required (pip install cmake==4.4.0)" >&2 exit 1 } echo "--- fetching protobuf ${PROTOBUF_VERSION} and abseil ${ABSEIL_VERSION}" cd "${WORK}" curl -sfL -o protobuf.tar.gz \ "https://github.com/protocolbuffers/protobuf/releases/download/v${PROTOBUF_VERSION}/protobuf-${PROTOBUF_VERSION}.tar.gz" tar xzf protobuf.tar.gz # The protobuf release tarball ships utf8_range but not abseil, and its default # CMake provider expects abseil as a submodule, so vendor it into place. curl -sfL -o abseil.tar.gz \ "https://github.com/abseil/abseil-cpp/releases/download/${ABSEIL_VERSION}/abseil-cpp-${ABSEIL_VERSION}.tar.gz" tar xzf abseil.tar.gz rm -rf "protobuf-${PROTOBUF_VERSION}/third_party/abseil-cpp" mv "abseil-cpp-${ABSEIL_VERSION}" "protobuf-${PROTOBUF_VERSION}/third_party/abseil-cpp" echo "--- building protobuf into ${PREFIX}" cmake -S "protobuf-${PROTOBUF_VERSION}" -B build \ -DCMAKE_BUILD_TYPE=Release \ -DCMAKE_INSTALL_PREFIX="${PREFIX}" \ -DCMAKE_POSITION_INDEPENDENT_CODE=ON \ -Dprotobuf_ABSL_PROVIDER=module \ -Dprotobuf_BUILD_TESTS=OFF \ -Dprotobuf_BUILD_SHARED_LIBS=OFF \ -DABSL_PROPAGATE_CXX_STD=ON cmake --build build -j"$(nproc)" cmake --install build echo "--- done" "${PREFIX}/bin/protoc" --version echo "configure the protocol build with: -DCMAKE_PREFIX_PATH=${PREFIX}"