#protobuf #protoc #protoc-rust

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

#869 in Build Utils

Download history 2747/week @ 2024-12-21 2705/week @ 2024-12-28 4708/week @ 2025-01-04 5114/week @ 2025-01-11 5241/week @ 2025-01-18 3660/week @ 2025-01-25 5003/week @ 2025-02-01 7264/week @ 2025-02-08 6782/week @ 2025-02-15 6456/week @ 2025-02-22 8921/week @ 2025-03-01 8822/week @ 2025-03-08 7848/week @ 2025-03-15 6853/week @ 2025-03-22 6123/week @ 2025-03-29 4010/week @ 2025-04-05

26,277 downloads per month
Used in fewer than 55 crates

MIT license

1.5MB
38K 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 Shell 9 SLoC // 0.2% comments

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.


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.

Dependencies

~2–11MB
~151K SLoC