hyperium / tonic

A native gRPC client & server implementation with async/await support.
https://docs.rs/tonic
MIT License
9.76k stars 997 forks source link

Automatically emitting rerun-if-changed instructions for cargo #1020

Closed mickvangelderen closed 2 years ago

mickvangelderen commented 2 years ago

Discussed in https://github.com/hyperium/tonic/discussions/1019

Originally posted by **mickvangelderen** June 17, 2022 I find myself writing a build script similar to the following for every project: ```rust fn main() { let protos = ["proto/rocsys/canonical.proto"]; let includes = ["proto"]; tonic_build::configure() .server_mod_attribute("rocsys.canonical", "#[cfg(feature = \"server\")]") .client_mod_attribute("rocsys.canonical", "#[cfg(feature = \"client\")]") .compile(&protos, &includes) .unwrap(); for path in protos.iter().copied().chain(includes.iter().copied()) { println!("cargo:rerun-if-changed={}", path) } } ``` I was wondering if we could let tonic emit those rerun-if-changed statements for us. It would be even better if we could narrow down the rerun-if-changed instructions only to the included files rather than asking cargo to monitor the entire include directories. It is possible that this feature already exists but I couldn't find any signs of tonic_build writing to `stdout` nor does my build script print anything to `stdout` when removing my own `println` statements.

Is this indeed a missing feature? If so, should it maybe be added to tonic_build (perhaps under a configuration flag since not everyone using tonic_build may be using cargo).

LucioFranco commented 2 years ago

Oh we should for sure add this! I would totally accept a PR for this.