#google #protocol-buffers #path #api #protocol #buffers #not #generate #implementation

build protoc-rust

protoc –rust_out=… available as API. protoc needs to be in $PATH, protoc-gen-run does not.

63 stable releases

Uses old Rust 2015

new 2.18.1 Nov 22, 2020
2.17.0 Aug 12, 2020
2.16.2 Jul 6, 2020
2.12.0 Mar 26, 2020
1.4.1 Jun 24, 2017

#346 in Network programming

Download history 8275/week @ 2020-08-02 9766/week @ 2020-08-09 9025/week @ 2020-08-16 8829/week @ 2020-08-23 9158/week @ 2020-08-30 8413/week @ 2020-09-06 9139/week @ 2020-09-13 7761/week @ 2020-09-20 8350/week @ 2020-09-27 8510/week @ 2020-10-04 9199/week @ 2020-10-11 8756/week @ 2020-10-18 7871/week @ 2020-10-25 6878/week @ 2020-11-01 7132/week @ 2020-11-08 7275/week @ 2020-11-15

35,156 downloads per month
Used in 96 crates (40 directly)

MIT license

1.5MB
29K SLoC

API to generate .rs files

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

Example code:

extern crate protoc_rust;

protoc_rust::run(protoc_rust::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]
protoc-rust = "1.5"

Note this API requires protoc command present in $PATH. Although protoc-gen-rust command is not needed.

The alternative is to use pure-rust .proto parser and code generator.


lib.rs:

API to generate .rs files.

This API requires protoc command present in $PATH or passed explicitly to Codegen object.

extern crate protoc_rust;

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

It is advisable that protoc-rust build-dependecy version be the same as protobuf dependency.

The alternative is to use protobuf-codegen-pure.

Dependencies

~0.8–1.4MB
~31K SLoC