protox
A pure-Rust implementation of the protobuf compiler, usable as a library without protoc.
Repository Health
Technical Analysis
protox is an implementation of the Protocol Buffers compiler written entirely in Rust. It is designed to be used as a library so that build tooling such as prost-build and tonic-build can compile .proto files without shelling out to the C++ protoc binary, removing a native build dependency from Rust projects.
Given a set of source files and include paths, protox parses and compiles them into a standard protobuf FileDescriptorSet, complete with rich, miette-powered diagnostics for syntax and semantic errors. Its parser lives in the separate protox-parse crate, while protox itself handles full compilation and descriptor generation.
What You Get
- A pure-Rust protobuf compiler with no dependency on the native protoc binary
- A simple
compile(files, includes)entry point returning a FileDescriptorSet - Drop-in integration with prost-build and tonic-build for code generation
- Rich, source-annotated error diagnostics powered by miette
- A standalone parser via the companion protox-parse crate for lower-level use
Common Use Cases
- Generating prost or tonic code in build.rs without installing protoc
- Producing a FileDescriptorSet for reflection or dynamic message handling
- Making Rust protobuf builds fully self-contained and reproducible in CI
- Parsing and validating .proto files programmatically with detailed errors
Under The Hood
Architecture — protox is a two-crate Cargo workspace. protox-parse handles lexing and parsing of .proto source into an AST (src/lex, src/parse, src/ast) and emits descriptor fragments (src/generate). The main protox crate (protox/src/compile, protox/src/file, protox/src/lib.rs) drives the full compilation: it resolves imports across include paths, links types across files, checks semantics, and assembles a prost_types::FileDescriptorSet. The public compile function ties this together, while an optional bin feature exposes a small CLI (protox/src/main.rs).
Tech Stack — Written in Rust (2021 edition, MSRV 1.74). It builds on the prost ecosystem — prost, prost-types, and prost-reflect — for descriptor types and reflection, bytes for buffer handling, thiserror for error definitions, and miette for fancy diagnostic reporting. The optional CLI adds clap. Testing uses insta snapshot tests and proptest regressions.
Code Quality — The codebase is well organized around parse and compile stages, with snapshot-based tests, property-test regressions, and codecov integration. Errors are modeled explicitly with thiserror and surfaced through miette for readable diagnostics. Recent activity has slowed, but the project is mature and its behavior is pinned by an extensive snapshot suite.
API Design — The primary API is a single compile function that mirrors how developers already think about invoking protoc, which keeps adoption nearly frictionless for prost-build and tonic-build users. Documentation on docs.rs includes worked examples for both build tools, and error messages are unusually clear thanks to miette source spans, lowering the debugging burden when proto definitions are malformed.