forked from hyperium/tonic
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.rs
68 lines (58 loc) · 2.59 KB
/
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
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
use std::{env, path::PathBuf};
fn main() {
tonic_build::configure()
.type_attribute("routeguide.Point", "#[derive(Hash)]")
.compile_protos(&["proto/routeguide/route_guide.proto"], &["proto"])
.unwrap();
let out_dir = PathBuf::from(env::var("OUT_DIR").unwrap());
tonic_build::configure()
.file_descriptor_set_path(out_dir.join("helloworld_descriptor.bin"))
.compile_protos(&["proto/helloworld/helloworld.proto"], &["proto"])
.unwrap();
tonic_build::compile_protos("proto/echo/echo.proto").unwrap();
tonic_build::compile_protos("proto/unaryecho/echo.proto").unwrap();
tonic_build::configure()
.server_mod_attribute("attrs", "#[cfg(feature = \"server\")]")
.server_attribute("Echo", "#[derive(PartialEq)]")
.client_mod_attribute("attrs", "#[cfg(feature = \"client\")]")
.client_attribute("Echo", "#[derive(PartialEq)]")
.compile_protos(&["proto/attrs/attrs.proto"], &["proto"])
.unwrap();
tonic_build::configure()
.build_server(false)
.compile_protos(
&["proto/googleapis/google/pubsub/v1/pubsub.proto"],
&["proto/googleapis"],
)
.unwrap();
build_json_codec_service();
let smallbuff_copy = out_dir.join("smallbuf");
let _ = std::fs::create_dir(smallbuff_copy.clone()); // This will panic below if the directory failed to create
tonic_build::configure()
.out_dir(smallbuff_copy)
.codec_path("crate::common::SmallBufferCodec")
.compile_protos(&["proto/helloworld/helloworld.proto"], &["proto"])
.unwrap();
}
// Manually define the json.helloworld.Greeter service which used a custom JsonCodec to use json
// serialization instead of protobuf for sending messages on the wire.
// This will result in generated client and server code which relies on its request, response and
// codec types being defined in a module `crate::common`.
//
// See the client/server examples defined in `src/json-codec` for more information.
fn build_json_codec_service() {
let greeter_service = tonic_build::manual::Service::builder()
.name("Greeter")
.package("json.helloworld")
.method(
tonic_build::manual::Method::builder()
.name("say_hello")
.route_name("SayHello")
.input_type("crate::common::HelloRequest")
.output_type("crate::common::HelloResponse")
.codec_path("crate::common::JsonCodec")
.build(),
)
.build();
tonic_build::manual::Builder::new().compile(&[greeter_service]);
}