1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104
|
[](https://crates.io/crates/protox/)
[](https://docs.rs/protox/)
[](https://deps.rs/crate/protox)

[](https://github.com/andrewhickman/protox/actions/workflows/ci.yml)
[](https://codecov.io/gh/andrewhickman/protox)

# protox
An implementation of the protobuf compiler in rust, intended for use as a library with crates such as [`prost-build`](https://crates.io/crates/prost-build) to avoid needing to build `protoc`.
## Examples
Compiling a single source file:
```rust
assert_eq!(protox::compile(["root.proto"], ["."]).unwrap(), FileDescriptorSet {
file: vec![
FileDescriptorProto {
name: Some("root.proto".to_owned()),
/* ... */
}
],
});
```
Usage with [`prost-build`](https://crates.io/crates/prost-build):
```rust
let file_descriptors = protox::compile(["root.proto"], ["."]).unwrap();
prost_build::compile_fds(file_descriptors).unwrap();
```
Usage with [`tonic-build`](https://crates.io/crates/tonic-build):
```rust
let file_descriptors = protox::compile(["root.proto"], ["."]).unwrap();
tonic_build::configure()
.build_server(true)
.compile_fds(file_descriptors)
.unwrap();
```
### Error messages
This crate uses [`miette`](https://crates.io/crates/miette) to add additional details to errors. For nice error messages, add `miette` as a dependency with the `fancy` feature enabled and return a [`miette::Result`](https://docs.rs/miette/latest/miette/type.Result.html) from your build script.
```rust
fn main() -> miette::Result<()> {
let _ = protox::compile(["root.proto"], ["."])?;
Ok(())
}
```
Example error message:
```
Error:
× name 'Bar' is not defined
╭─[root.proto:3:1]
3 │ message Foo {
4 │ Bar bar = 1;
· ─┬─
· ╰── found here
5 │ }
╰────
```
## Minimum Supported Rust Version
Rust **1.74** or higher.
The minimum supported Rust version may be changed in the future, but it will be
done with a minor version bump.
## License
Licensed under either of
* Apache License, Version 2.0
([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0)
* MIT license
([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT)
at your option.
This project includes code imported from the Protocol Buffers project, which is
included under its original ([BSD][2]) license.
[2]: https://github.com/protocolbuffers/protobuf/blob/master/LICENSE
## Contribution
Unless you explicitly state otherwise, any contribution intentionally submitted
for inclusion in the work by you, as defined in the Apache-2.0 license, shall be
dual licensed as above, without any additional terms or conditions.
## Related projects
* [prost](https://crates.io/crates/prost) - a protocol buffers implementation for the Rust Language
* [protoxy](https://github.com/tardyp/protoxy) - python bindings for protox
|