-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.rs
24 lines (19 loc) · 851 Bytes
/
build.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
use std::path::Path;
fn main() -> Result<(), Box<dyn std::error::Error>> {
let (proto_path, proto_dir) = compile_args("user-service-proto/service.proto");
tonic_build::configure()
.build_server(false)
.type_attribute(".", "#[cfg_attr(feature = \"serde\", derive(serde::Serialize, serde::Deserialize))]")
.extern_path(".google.protobuf.Struct", "::prost_wkt_types::Struct")
.compile_protos(&proto_path, &proto_dir)?;
Ok(())
}
/// tonic-build/src/prost.rs — compile_protos()
fn compile_args(proto: &str) -> ([impl AsRef<Path> + '_; 1], [impl AsRef<Path> + '_; 1]) {
let proto_path: &Path = proto.as_ref();
// directory the main .proto file resides in
let proto_dir = proto_path
.parent()
.expect("proto file should reside in a directory");
([proto_path], [proto_dir])
}