Skip to content

Commit

Permalink
build(example): made protoc useless to build grpc client & server
Browse files Browse the repository at this point in the history
- store the generated content
  • Loading branch information
davidB committed Sep 22, 2024
1 parent d7bc961 commit bfed50e
Show file tree
Hide file tree
Showing 5 changed files with 390 additions and 13 deletions.
14 changes: 12 additions & 2 deletions examples/grpc/build.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,20 @@
use std::{env, path::PathBuf};
use std::path::PathBuf;

fn main() {
let out_dir = PathBuf::from(env::var("OUT_DIR").unwrap());
// trigger rebuild if "proto" folder change
print!("cargo:rerun-if-changed=./proto");

//let out_dir = PathBuf::from(env::var("OUT_DIR").unwrap());
let out_dir = PathBuf::from(std::env!("CARGO_MANIFEST_DIR"))
.join("src")
.join("generated");
std::fs::create_dir_all(&out_dir).unwrap();

tonic_build::configure()
.build_client(true)
.build_server(true)
.file_descriptor_set_path(out_dir.join("helloworld_descriptor.bin"))
.out_dir(out_dir)
.compile(&["helloworld.proto"], &["proto"])
.unwrap();
}
9 changes: 5 additions & 4 deletions examples/grpc/src/client.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
use hello_world::greeter_client::GreeterClient;
use hello_world::{HelloRequest, StatusRequest};
use generated::greeter_client::GreeterClient;
use generated::{HelloRequest, StatusRequest};
use tonic::transport::Channel;
use tonic::Code;
use tonic_tracing_opentelemetry::middleware::client::OtelGrpcLayer;
use tower::ServiceBuilder;

pub mod hello_world {
tonic::include_proto!("helloworld");
pub mod generated {
//tonic::include_proto!("helloworld");
include!("generated/helloworld.rs");
}

#[tokio::main]
Expand Down
Loading

0 comments on commit bfed50e

Please sign in to comment.