#serialization #protoc #protobuf #proto #buffer #api #protocols

build protoc-rust

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

81 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.4.1 Jun 24, 2017

#2245 in Encoding

Download history 25011/week @ 2024-01-03 18279/week @ 2024-01-10 22955/week @ 2024-01-17 30948/week @ 2024-01-24 28452/week @ 2024-01-31 31518/week @ 2024-02-07 29385/week @ 2024-02-14 26329/week @ 2024-02-21 38820/week @ 2024-02-28 33051/week @ 2024-03-06 34095/week @ 2024-03-13 31288/week @ 2024-03-20 41754/week @ 2024-03-27 31442/week @ 2024-04-03 26728/week @ 2024-04-10 20964/week @ 2024-04-17

127,426 downloads per month
Used in fewer than 55 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:

extern crate protoc_rust;

use protoc_rust::Customize;

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

And in Cargo.toml:

[build-dependencies]
protoc-rust = "2.0"

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

Note 2: Is advisable that protoc-rust build-dependecy version be the same as protobuf dependency.

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

~2–12MB
~135K SLoC