tonic-health: commit generated code (#1065)

* tonic-health: commit generated code rather than generating at build time

This saves users from needing protoc available on their path if they're not
generating other tonic code at build time, either.

The generated modules can be regenerated by enabling the `gen-proto`
feature, which will trigger the relevant part of the build script.

* Check generated code for tonic-health matches in CI

* Use bootstrap test to generate/check validity of generated code

As suggested by @LucioFranco in https://github.com/hyperium/tonic/pull/1065\#discussion_r951580189.
This avoids the need for a feature which would show
up in docs.rs, and achieves the same goals via CI.
This commit is contained in:
Ben Sully
2022-08-23 10:31:37 -04:00
committed by GitHub
parent 2d66a0aa30
commit 0a2a2f3ac5
6 changed files with 413 additions and 20 deletions
+30
View File
@@ -0,0 +1,30 @@
use std::{path::PathBuf, process::Command};
#[test]
fn bootstrap() {
let iface_files = &["proto/health.proto"];
let dirs = &["proto"];
let out_dir = PathBuf::from(std::env!("CARGO_MANIFEST_DIR"))
.join("src")
.join("generated");
tonic_build::configure()
.build_client(true)
.build_server(true)
.out_dir(format!("{}", out_dir.display()))
.compile(iface_files, dirs)
.unwrap();
let status = Command::new("git")
.arg("diff")
.arg("--exit-code")
.arg("--")
.arg(format!("{}", out_dir.display()))
.status()
.unwrap();
if !status.success() {
panic!("You should commit the protobuf files");
}
}