#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

#2379 in Development tools

Download history 26429/week @ 2024-09-25 24422/week @ 2024-10-02 29594/week @ 2024-10-09 30859/week @ 2024-10-16 28117/week @ 2024-10-23 23821/week @ 2024-10-30 25707/week @ 2024-11-06 28583/week @ 2024-11-13 31848/week @ 2024-11-20 30217/week @ 2024-11-27 29453/week @ 2024-12-04 30170/week @ 2024-12-11 22189/week @ 2024-12-18 9587/week @ 2024-12-25 18300/week @ 2025-01-01 23082/week @ 2025-01-08

77,993 downloads per month
Used in fewer than 29 crates

MIT license

210KB
5K 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

~4–12MB
~172K SLoC