-
Notifications
You must be signed in to change notification settings - Fork 8
Use syn/quote for codegen #185
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
Conversation
👋🏻 @blinsay, thanks for the patch!
Can you say a little more about what you'd like to change? I do appreciate that moving away from the very utilitarian printf code gen is probably a good idea long term. I'm a bit hesitant to spend time on that though without some other benefit, mostly based on my own limited time and other higher priority things demanding attention. I'd also like to carefully vet each of the 4 new dependencies (even if this is a build time crate) as that can have a pretty big impact on our usage of this library. Adding those means we take on the treadmill of updates, security patches, license compliance, etc (in perpetuity) and that also adds up. Let's talk larger motivations to see if all this effort is worth it! |
I had two semi-related ideas I wanted to mess with:
Totally get it!
|
also wanted to mention: I see the |
Oh yeah, this doesn't work at all. Big 👍🏻 to fixing that.
Agree. We some extra internal code for this as well to register various internal layers and even non-twirp endpoints. These both sound like excellent motivations. I also had a closer look at the diff and I really like how much this Thanks for the contribution! |
@tclem I'm passing clippy locally, seems like you need to kick something to get CI to run here. Let me know if you like that |
@blinsay for some reason I'm unable to get CI to run again (we've hit some bug and I've asked another internal team to take a look). In an attempt to work around: do you mind pushing an empty commit ( |
@tclem I tried amending and force-pushing and it looks like we're back where we started :( |
OK, the new codegen fails in our usage of I just changed our dependency to:
|
Oh, it's just that you can't define multiple rpcs... Here's a branch demonstrating the failure. We should probably improve our example and tests to include this. |
Ope, nice find. The fix was pretty silly. I'm not sure how it compiled in the first place to be honest. Also added a new commit with a second rpc method defined on the Haberdasher API. |
OK. Here's the next issue I run into. Do you mind adding a bit more debugging info to the error message (I believe this is coming from
|
I pushed a hacky branch that hopefully helps. I didn't add it to this branch because I feel like we can do better, but hopefully that gets us enough info keep making progress and I'll think about a better way to do error reporting. |
That helped! One problem was actually in the I didn't read your "hacky branch" in detail, but you actually fixed whatever the codegen issue is here. I can still reproduce the error on 8b3c6e1 (even after fixing the |
Awesome. I switched from parsing input/output types as |
Ok, I'm happier enough with that for you to review it. I ran with the pre-parsing stuff, which still calls |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@blinsay code looks great, thank you for improving the error messages! I was able to validate by forcing some errors (rpcs that reference messages that aren't defined).
I'm also able to fully upgrade to this branch on our primary projects that depend on twirp-rs with no issues now 🎉
This PR was included in v0.8.0, released today. |
First of all, thanks for maintaining this crate. It's been really easy to get started with and to use .
I had some ideas for changing how code was generated for services, but wanted to make it easier to change things before I started messing around. I borrowed the
syn
/quote
/prettyplease
approach fromtonic
because I find the quasi-quoted codegen a lot easier to read than template strings towrite!
- here's an example of some heavy quote usage in tonic-build.For this PR I tried to keep the structure of
lib.rs
mostly the same. I'm happy to break it up a bit or get a little more disciplined about idents and types if y'all are interested but I didn't want to presume too much.