#protobuf #codegen #protocol-buffers #google #api #protocol #buffers #pure

build protobuf-codegen-pure

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

57 stable releases

Uses old Rust 2015

2.24.1 Jun 11, 2021
2.22.1 Mar 18, 2021
2.18.1 Nov 22, 2020
2.16.2 Jul 6, 2020
1.6.0 May 11, 2018
Download history 6795/week @ 2021-04-03 6755/week @ 2021-04-10 5625/week @ 2021-04-17 7504/week @ 2021-04-24 8413/week @ 2021-05-01 10937/week @ 2021-05-08 8038/week @ 2021-05-15 6858/week @ 2021-05-22 7703/week @ 2021-05-29 6887/week @ 2021-06-05 6745/week @ 2021-06-12 6502/week @ 2021-06-19 6499/week @ 2021-06-26 9790/week @ 2021-07-03 12376/week @ 2021-07-10 6818/week @ 2021-07-17

31,401 downloads per month
Used in 58 crates (33 directly)

MIT license

1.5MB
35K SLoC

API to generate .rs files

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

Example code:

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: Customize {
      ..Default::default()
    },
}).expect("protoc");

And in Cargo.toml:

[build-dependencies]
protobuf_codegen_pure = "1.5"

The alternative is to use protoc-rust crate, which relies on protoc command to parse descriptors (thus it's more reliable), but it requires protoc command in $PATH.


lib.rs:

API to generate .rs files.

This API does not require protoc command present in $PATH.

extern crate protoc_rust;

fn main() {
    protobuf_codegen_pure::Codegen::new()
        .out_dir("src/protos")
        .inputs(&["protos/a.proto", "protos/b.proto"])
        .include("protos")
        .run()
        .expect("Codegen failed.");
}

It is advisable that protobuf-codegen-pure build-dependecy version be the same as protobuf dependency.

The alternative is to use protoc-rust crate.

Dependencies