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

Conversation

sd2k
Copy link
Contributor

@sd2k sd2k commented Aug 21, 2022

This PR resolves #1052 by making the build.rs code and tonic-build dependency optional, as suggested by @nashley in the comments of that issue.

Motivation

See #1052. In brief, this avoids consumers having to have a protoc binary available in order to use tonic-health, which is helpful if they have also committed their generated code.

Solution

  • Make the tonic-build dependency optional
  • Commit generated code to src/generated
  • Validate that the generated code matches in CI

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.
Copy link
Member

@LucioFranco LucioFranco left a comment

Choose a reason for hiding this comment

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

Thank you for getting this started. I left a comment about doing the gen in a test. I think we should make that change then we can merge.

@@ -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.

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.
@sd2k sd2k requested a review from LucioFranco August 22, 2022 21:58
Copy link
Member

@LucioFranco LucioFranco left a comment

Choose a reason for hiding this comment

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

Thanks!

@LucioFranco LucioFranco merged commit 0a2a2f3 into hyperium:master Aug 23, 2022
flemosr added a commit to flemosr/tonic that referenced this pull request Aug 28, 2022
As suggested by @LucioFranco in hyperium#1068 (comment).

This avoids the need for consumers to have `protoc` in their path.
Implemented following changes in hyperium#1065.
LucioFranco pushed a commit that referenced this pull request Sep 21, 2022
* types: add tonic as dependency, add error_details.proto

* types: add BadRequest support from flemosr/tonic-richer-error

* types: adjust code following suggestions

Adjustments following suggestions by @LucioFranco in #1068.

Adjust style, remove unecessary prints, avoid glob imports, apply
`non_exhaustive` to `ErrorDetails` and `ErrorDetail`, avoid pub
fields in `ErrorDetails`, adjust
`WithErrorDetails::with_error_details_vec` args, add
`gen_details_bytes`.

* types: add generated protobuf code

As suggested by @LucioFranco in #1068 (comment).

This avoids the need for consumers to have `protoc` in their path.
Implemented following changes in #1065.

* types: add custom metadata support

This allows consumers to provide custom metadata when creating a
`Status` with error details.

* types: adjust code following suggestions

Adjustments following suggestions by @LucioFranco in #1068.

Move `error_details_vec` mod into `error_details` mod, adjust doc
comments, rename `WithErrorDetails` trait to `StatusExt`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

tonic-health: check in generated code instead of requiring tonic-build
2 participants