1 use std::{env, path::PathBuf}; 2 3 fn main() { 4 tonic_build::configure() 5 .type_attribute("routeguide.Point", "#[derive(Hash)]") 6 .compile(&["proto/routeguide/route_guide.proto"], &["proto"]) 7 .unwrap(); 8 9 let out_dir = PathBuf::from(env::var("OUT_DIR").unwrap()); 10 tonic_build::configure() 11 .file_descriptor_set_path(out_dir.join("helloworld_descriptor.bin")) 12 .compile(&["proto/helloworld/helloworld.proto"], &["proto"]) 13 .unwrap(); 14 15 tonic_build::compile_protos("proto/echo/echo.proto").unwrap(); 16 17 tonic_build::compile_protos("proto/unaryecho/echo.proto").unwrap(); 18 19 tonic_build::configure() 20 .server_mod_attribute("attrs", "#[cfg(feature = \"server\")]") 21 .server_attribute("Echo", "#[derive(PartialEq)]") 22 .client_mod_attribute("attrs", "#[cfg(feature = \"client\")]") 23 .client_attribute("Echo", "#[derive(PartialEq)]") 24 .compile(&["proto/attrs/attrs.proto"], &["proto"]) 25 .unwrap(); 26 27 tonic_build::configure() 28 .build_server(false) 29 .compile( 30 &["proto/googleapis/google/pubsub/v1/pubsub.proto"], 31 &["proto/googleapis"], 32 ) 33 .unwrap(); 34 35 build_json_codec_service(); 36 } 37 38 // Manually define the json.helloworld.Greeter service which used a custom JsonCodec to use json 39 // serialization instead of protobuf for sending messages on the wire. 40 // This will result in generated client and server code which relies on its request, response and 41 // codec types being defined in a module `crate::common`. 42 // 43 // See the client/server examples defined in `src/json-codec` for more information. 44 fn build_json_codec_service() { 45 let greeter_service = tonic_build::manual::Service::builder() 46 .name("Greeter") 47 .package("json.helloworld") 48 .method( 49 tonic_build::manual::Method::builder() 50 .name("say_hello") 51 .route_name("SayHello") 52 .input_type("crate::common::HelloRequest") 53 .output_type("crate::common::HelloResponse") 54 .codec_path("crate::common::JsonCodec") 55 .build(), 56 ) 57 .build(); 58 59 tonic_build::manual::Builder::new().compile(&[greeter_service]); 60 } 61