#protobuf #protobuf-codegen #protobuf-codegen-pure

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

#1432 in Development tools

Download history 27877/week @ 2024-12-14 12163/week @ 2024-12-21 11722/week @ 2024-12-28 25663/week @ 2025-01-04 32886/week @ 2025-01-11 28350/week @ 2025-01-18 29611/week @ 2025-01-25 37702/week @ 2025-02-01 45789/week @ 2025-02-08 46111/week @ 2025-02-15 36755/week @ 2025-02-22 39273/week @ 2025-03-01 32945/week @ 2025-03-08 33499/week @ 2025-03-15 27651/week @ 2025-03-22 21323/week @ 2025-03-29

121,742 downloads per month
Used in fewer than 28 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–11MB
~151K SLoC