1 个稳定版本
使用旧的 Rust 2015
| 2.8.0 | 2019年11月29日 |
|---|
#1980 在 开发工具
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 以程序方式调用)
- 安装
protoc的 protobuf 二进制文件。
在 OS X 上,可以使用 Homebrew
brew install protobuf
在 Ubuntu 上,可以安装 protobuf-compiler 软件包
apt-get install protobuf-compiler
protobuf 只需要用于代码生成,rust-protobuf 运行时不需要 protobuf 库。
- 安装
protoc-gen-rust程序(即protoc插件)
可以从源安装,也可以使用 cargo install protobuf 命令安装。
- 将
protoc-gen-rust添加到 $PATH
如果你是用 cargo 安装的,那么应该是
PATH="$HOME/.cargo/bin:$PATH"
- 生成 .rs 文件
protoc --rust_out . foo.proto
这将在当前目录中生成 .rs 文件。
依赖项
~605KB