* 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.
31 lines
733 B
Rust
31 lines
733 B
Rust
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");
|
|
}
|
|
}
|