#protoc-gen-rust #protobuf #generator #binary #path #protobuf-codegen-pure #rust-protobuf

bin+lib nrc-protobuf-codegen

rust-protobuf 的代码生成器。包括库和 protoc-gen-rust 二进制文件。参见 protoc-rustprotobuf-codegen-pure crate。是 https://github.com/stepancheg/rust-protobuf/ 的一个小的分支。

1 个稳定版本

使用旧的 Rust 2015

2.8.0 2019年11月29日

#1980开发工具

MIT 许可证

1MB
28K SLoC

protobuf-codegen

这个 crate 包含 protobuf 代码生成器和 protoc-gen-rust protoc 插件。

protoc-gen-rust

protoc-gen-rust 实现了标准的 protobuf protoc 插件约定。

你可能不想在 Rust 环境中直接使用它,有一些更易用的替代方案

  • protoc-rust crate,它可以从项目的 build.rs 中以程序方式调用,只需要 protoc,而不需要 protoc-gen-rust
  • protobuf-codegen-pure crate,它表现得像 protoc-rust,但不依赖于 protoc 二进制文件

但如果你真的想使用这个插件,以下是使用说明

(注意 protoc 可以通过 protoc crate 以程序方式调用)

  1. 安装 protoc 的 protobuf 二进制文件。

在 OS X 上,可以使用 Homebrew

brew install protobuf

在 Ubuntu 上,可以安装 protobuf-compiler 软件包

apt-get install protobuf-compiler

protobuf 只需要用于代码生成,rust-protobuf 运行时不需要 protobuf 库。

  1. 安装 protoc-gen-rust 程序(即 protoc 插件)

可以从源安装,也可以使用 cargo install protobuf 命令安装。

  1. protoc-gen-rust 添加到 $PATH

如果你是用 cargo 安装的,那么应该是

PATH="$HOME/.cargo/bin:$PATH"
  1. 生成 .rs 文件
protoc --rust_out . foo.proto

这将在当前目录中生成 .rs 文件。

依赖项

~605KB