Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tonic-health: commit generated code #1065

Merged
merged 3 commits into from
Aug 23, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ jobs:
run: cargo hack check --all --ignore-private --each-feature --no-dev-deps
- name: Check all targets
run: cargo check --all --all-targets --all-features
- name: Ensure generated code matches
run: >
echo 'If this fails, run `cargo build --features gen-proto` and commit the changes';
git diff --exit-code --name-only -- tonic-health/src/generated/

# deny-check:
# name: cargo-deny check
Expand Down
6 changes: 4 additions & 2 deletions tonic-health/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ version = "0.7.0"

[features]
default = ["transport"]
transport = ["tonic/transport", "tonic-build/transport"]
transport = ["tonic/transport"]
# generate gRPC code from `.proto`(s)
gen-proto = ["dep:tonic-build"]

[dependencies]
async-stream = "0.3"
Expand All @@ -30,4 +32,4 @@ tonic = {version = "0.8", path = "../tonic", features = ["codegen", "prost"]}
tokio = {version = "1.0", features = ["rt-multi-thread", "macros"]}

[build-dependencies]
tonic-build = {version = "0.8", path = "../tonic-build", features = ["prost"]}
tonic-build = {version = "0.8", path = "../tonic-build", features = ["prost"], optional = true}
14 changes: 9 additions & 5 deletions tonic-health/build.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
use std::env;
use std::path::PathBuf;
// This build file is used to generate the code as a one-off,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For prost-types we generate the code via a bootstrap test. This test runs on CI and verifies that the generated code checked in matches locally generated code on the ci box. This removes the need for an awkward feature and gives you the CI check automatically. You can see that approach here https://github.com/tokio-rs/console/blob/606cf721bdd831ee4fa8622081a654fa5b1926b8/console-api/tests/bootstrap.rs

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, that makes sense, I see now. I've pushed a commit to do it the same way here, thanks for the pointer.

// but is only rerun with the `gen-proto` feature enabled.
// This simplifies the build process for this crate by not requiring
// users to have protoc available.

fn main() -> Result<(), Box<dyn std::error::Error>> {
let grpc_health_v1_descriptor_set_path: PathBuf =
PathBuf::from(env::var("OUT_DIR").unwrap()).join("grpc_health_v1.bin");
#[cfg(feature = "gen-proto")]
tonic_build::configure()
.file_descriptor_set_path(grpc_health_v1_descriptor_set_path)
.file_descriptor_set_path(
std::path::PathBuf::from("src/generated").join("grpc_health_v1.bin"),
)
.out_dir("src/generated")
.build_server(true)
.build_client(true)
.compile(&["proto/health.proto"], &["proto/"])?;
Expand Down
Loading