An implementation of the protobuf compiler in rust, intended for use as a library with crates such as prost-build
to avoid needing to build protoc
.
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
:
```rust let filedescriptors = compile(&["root.proto"], &["."]).unwrap(); let filedescriptorpath = PathBuf::from(env::varos("OUTDIR").expect("OUTDIR not set")) .join("filedescriptorset.bin"); fs::write(&filedescriptorpath, filedescriptors.encodeto_vec()).unwrap();
prostbuild::Config::new() .filedescriptorsetpath(&filedescriptorpath) .skipprotocrun() .compile_protos(&["root.proto"], &["."]) .unwrap(); ```
Rust 1.61 or higher.
The minimum supported Rust version may be changed in the future, but it will be done with a minor version bump.
Licensed under either of
at your option.
This project includes code imported from the Protocol Buffers project, which is included under its original (BSD) license.
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.