#protobuf #codegen #pure #proto #customize #input #args

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

#1931 in Development tools

Download history 23214/week @ 2024-03-14 21442/week @ 2024-03-21 20481/week @ 2024-03-28 23366/week @ 2024-04-04 23723/week @ 2024-04-11 26709/week @ 2024-04-18 24577/week @ 2024-04-25 21132/week @ 2024-05-02 27393/week @ 2024-05-09 28181/week @ 2024-05-16 25482/week @ 2024-05-23 26496/week @ 2024-05-30 23934/week @ 2024-06-06 27233/week @ 2024-06-13 26808/week @ 2024-06-20 22560/week @ 2024-06-27

105,737 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
~131K SLoC