Skip to content

A pure-rust protobuf compiler, designed for use with prost-build

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT
Notifications You must be signed in to change notification settings

andrewhickman/protox

Repository files navigation

crates.io docs.rs deps.rs MSRV Continuous integration codecov Apache 2.0 OR MIT licensed

protox

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.

Examples

Compiling a single source file:

assert_eq!(protox::compile(["root.proto"], ["."]).unwrap(), FileDescriptorSet {
    file: vec![
        FileDescriptorProto {
            name: Some("root.proto".to_owned()),
            /* ... */
        }
    ],
});

Usage with prost-build:

let file_descriptors = protox::compile(["root.proto"], ["."]).unwrap();
prost_build::compile_fds(file_descriptors).unwrap();

Usage with tonic-build:

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 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 from your build script.

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.70 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

at your option.

This project includes code imported from the Protocol Buffers project, which is included under its original (BSD) 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 - a protocol buffers implementation for the Rust Language
  • protoxy - python bindings for protox

About

A pure-rust protobuf compiler, designed for use with prost-build

Topics

Resources

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT

Stars

Watchers

Forks

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •  

Languages