我不知道如何使用 prost_build
生成代码。
我已经阅读了文档,但它们没有详细说明如何生成代码。cargo build
命令也无法生成代码。
这是我的 build.rs
文件。
extern crate prost_build;
fn main() {
prost_build::compile_protos(&["src/items.proto"],
&["src/"]).unwrap();
}
我的 Cargo.toml
[package]
name = "snazzy"
version = "0.1.0"
authors = ["xxx <xxx@xxx.com>"]
edition = "2018"
build = "build.rs"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
bytes = "0.4"
prost = "0.5"
[build-dependencies]
prost-build = { version = "0.4" }
我的 items.proto
syntax = "proto3";
package snazzy.items;
message Shirt {
enum Size {
SMALL = 0;
MEDIUM = 1;
LARGE = 2;
}
string color = 1;
Size size = 2;
}
我的文件树:
.
├── build.rs
├── Cargo.lock
├── Cargo.toml
└── src
├── items.proto
└── main.rs
没有构建错误,但我看不到生成的代码在哪里。任何帮助都将不胜感激!
src
。我猜这份文档认为你已经知道了,但我是新手。 - sudosrc
文件夹中同时拥有build.rc
和lib.rc
,这样程序可以完美运行。如果无法正常运行,我们可以开始另一个问题并一起找出错误。 - taras