3个版本
0.1.2 | 2021年6月9日 |
---|---|
0.1.1 | 2020年7月9日 |
0.1.0 | 2020年7月8日 |
#95 in #server-client
7KB
包含所有生成的proto服务器和客户端项目。
tonic_include_protos::include_protos!();
动机
我在一个项目中工作,这个项目基于较大的grpc基础,我们使用了tonic和Google API。tonic使用基于prost的良好的构建系统,但它生成了很多文件。每个文件都必须在单独的mod
中手动包含才能正确工作。如果你把它们都放在一个模块中,编译很可能会失败。
工作原理
此宏将根据grpc包名称构建mod树。例如,如果你在OUT_DIR
中创建了两个由tonic_build生成的文件
package.api.example.rs
package.api.another_example.rs
结果将与以下内容相当
pub mod package{
pub mod api {
pub mod example {
include!(concat!(env!("OUT_DIR"), "/google.api.example.rs"));
}
pub mod another_example {
include!(concat!(env!("OUT_DIR"), "/google.api.another_example.rs"));
}
}
}
如果你无法使用OUT_DIR
(当你将tonic_build设置为将文件保存在其他目录或出于其他原因)时,你可以设置TIP_OUT_DIR
环境变量来指向所需的目录。
我知道这个解决方案并不完美,但它能完成任务。如果您有更好的实现想法,请随时提出问题或发送PR。
许可证
本项目采用MIT许可证。