#protobuf #codegen #pure #proto #customize #proto-file #input

build protobuf-codegen-pure

Pure-rust codegen for protobuf using protobuf-parser crate WIP

66 stable releases

3.0.0-alpha.2 Nov 1, 2021
2.28.0 Sep 26, 2022
2.27.1 Feb 5, 2022
2.25.2 Oct 24, 2021
1.6.0 May 11, 2018

#2224 in Development tools

Download history 24771/week @ 2024-07-23 23324/week @ 2024-07-30 25668/week @ 2024-08-06 23970/week @ 2024-08-13 25431/week @ 2024-08-20 23044/week @ 2024-08-27 26901/week @ 2024-09-03 25390/week @ 2024-09-10 24235/week @ 2024-09-17 26961/week @ 2024-09-24 24325/week @ 2024-10-01 29211/week @ 2024-10-08 29152/week @ 2024-10-15 28984/week @ 2024-10-22 24610/week @ 2024-10-29 21228/week @ 2024-11-05

108,412 downloads per month
Used in fewer than 32 crates

MIT license

2MB
41K SLoC

API to generate .rs files

API to generate .rs files to be used e. g. from build.rs.

Example code:

With stable rust-protobuf:

extern crate protobuf_codegen_pure;

protobuf_codegen_pure::run(protobuf_codegen_pure::Args {
    out_dir: "src/protos",
    input: &["protos/a.proto", "protos/b.proto"],
    includes: &["protos"],
    customize: protobuf_codegen_pure::Customize {
      ..Default::default()
    },
}).expect("protoc");

With rust-protobuf from master:

extern crate protobuf_codegen_pure;

protobuf_codegen_pure::Args::new()
    .out_dir("src/protos")
    .inputs(&["protos/a.proto", "protos/b.proto"])
    .include("protos")
    .run()
    .expect("protoc");

And in Cargo.toml:

[build-dependencies]
protobuf-codegen-pure = "2.3"

The alternative is to use protoc-rust crate, which relies on protoc command to parse descriptors. Both crates should produce the same result, otherwise please file a bug report.

Dependencies

~2–11MB
~133K SLoC