#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

#2568 in Development tools

Download history 28833/week @ 2024-11-18 31377/week @ 2024-11-25 30514/week @ 2024-12-02 30283/week @ 2024-12-09 27340/week @ 2024-12-16 11737/week @ 2024-12-23 12513/week @ 2024-12-30 26209/week @ 2025-01-06 32611/week @ 2025-01-13 28945/week @ 2025-01-20 29049/week @ 2025-01-27 41466/week @ 2025-02-03 43186/week @ 2025-02-10 46316/week @ 2025-02-17 36878/week @ 2025-02-24 37494/week @ 2025-03-03

166,341 downloads per month
Used in fewer than 29 crates

MIT license

1.5MB
37K SLoC

C 26K SLoC // 0.1% comments Rust 11K SLoC // 0.1% comments Bitbake 795 SLoC // 0.2% comments Bazel 58 SLoC // 0.1% comments

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–12MB
~151K SLoC