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

feat(build): Decouple codgen from prost #170

Merged
merged 10 commits into from
Mar 1, 2020

Conversation

Perlmint
Copy link
Contributor

Motivation

Prepare using tonic with other protocol buffer implement or flatbuffers.

Solution

Add trait to provide needed info to the code generator.
And, introduce new features to make using prost optional.


quote! {
pub async fn #ident(
&mut self,
request: impl tonic::IntoRequest<#request>,
) -> Result<tonic::Response<#response>, tonic::Status> {
self.ready().await?;
let codec = tonic::codec::ProstCodec::default();
let codec = tonic::codec::#codec_name::default();
Copy link
Member

Choose a reason for hiding this comment

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

I was thinking we should actually make this

let codec = #codec_path::default();

so that you can use any codec from any path include crates that are not tonic.

let mut stream = TokenStream::new();

for comment in comments {
stream.extend(generate_doc_comment(comment.as_ref()));
for ref comment in comments {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
for ref comment in comments {
for comment in &comments {

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually comments is an iterator. So, your suggestion is not appliable straightforward. I changed the type of comments to IntoIterator.

}

impl schema::Context for ProstContext {
const CODEC_NAME: &'static str = "ProstCodec";
Copy link
Member

Choose a reason for hiding this comment

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

so we probably want to make this non-const so that users can set it via a builder fn possibly. This path to this codec may not always be static.

}

pub(crate) trait Method<'a>: Commentable<'a> {
type Context: Context + Sized + 'a;
Copy link
Member

Choose a reason for hiding this comment

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

You don't need to add sized here iirc since its always included in a trait bound.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I didn't specify Sized constraint. But, it is useless, unused constraint. So I removed it.

@Perlmint
Copy link
Contributor Author

Perlmint commented Jan 5, 2020

@LucioFranco Can you check some added commits?

Which way is preferred here to fix this check failure? Adding _ prefix or disabling the function by feature gate?

@LucioFranco
Copy link
Member

@Perlmint looks like there are a couple conflicts, I know some of the build code change, would you be able to update this? Then I can take another look. Thanks!

@Perlmint Perlmint force-pushed the feature/decouple_prost branch from 1ed85ab to 9881a64 Compare January 8, 2020 02:01
@Perlmint
Copy link
Contributor Author

Perlmint commented Jan 8, 2020

I rebased my commits. But, It looks like I should add more commits - make types that needed to describe schema public. After pushing the commits, I'll notify.

@Perlmint
Copy link
Contributor Author

Perlmint commented Jan 8, 2020

@LucioFranco Fix all checks and make possible implementing the service generator out of tonic-build.

@LucioFranco
Copy link
Member

Sorry for the delay on this, I am gonna take a longer look at this once tonic 0.1 is out because I would like to push this to 0.2 since there are still somethings to work out. Thanks for your patience.

@Perlmint
Copy link
Contributor Author

I got it. When you have time to review this, please notify me. I'll update soon :)

@magnet
Copy link
Contributor

magnet commented Jan 29, 2020

@Perlmint Any plan to rebase this on master? :) If not I can give it a shot, but I won't be able to add commits to this MR

@Perlmint
Copy link
Contributor Author

@magnet Oh, I'm just waiting for that @LucioFranco is ready to review this. If you need, I'll do it soon. :)

@magnet
Copy link
Contributor

magnet commented Jan 30, 2020

Thanks @Perlmint! I'm basing #250 off your branch, and trying to keep up with master, so it would be great if can update it 🙂

@LucioFranco
Copy link
Member

@Perlmint yes, sorry for the delay! We should get the ball rolling on this, looks like fbs support is almost ready :) Thanks for the patience, if we can rebase this against master then I think we can move forward.

@Perlmint Perlmint force-pushed the feature/decouple_prost branch 3 times, most recently from c12cc97 to 1fee30e Compare January 30, 2020 13:10
@Perlmint
Copy link
Contributor Author

@magnet rebased!

@LucioFranco
Copy link
Member

Great thank you! @magnet let me know if you have any issues, I plan on taking a longer look at all of this soon.

@Perlmint Perlmint force-pushed the feature/decouple_prost branch from 1fee30e to f16badb Compare February 25, 2020 04:11
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.

Sorry for the huge delay on this! Thank you for keeping up with this! Everything, looks fantastic!

@LucioFranco LucioFranco changed the title Decouple prost from tonic. feat(build): Decouple codgen from prost Mar 1, 2020
@LucioFranco LucioFranco merged commit f65cda1 into hyperium:master Mar 1, 2020
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.

3 participants