-
Notifications
You must be signed in to change notification settings - Fork 435
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/Prost Rules - Take 2 #595
Conversation
This is still very WIP in terms of its integration with rules_rust, however, I wanted to put this up as a reference for those who may be interested in pushing it forward more. Ideally, rules_rust would be updated to expose an interface similar to rules_go: https://github.com/bazelbuild/rules_go#protobuf-and-grpc That allows plugins appropriate access into build internals so that the generate code can be shifted by the user. This quite necessary for rust, as there is no canonical rust api for protobuf/grpc; Prost/Tonic is just one of them. The current rust_proto_library and rust_grpc_library are tied to grpc_rust and rust_protobuf crates currently, and this cannot be shifted with the rust_protobuf_toolchain. This PR contains a couple parts: 1. Bazel rules and macros that define an external prost_library and tonic_library that can generate code from a proto_library target 2. A prostgen executable that does the heavy lifting of running the code generation, and making sure that different prost_library targets can be used in different targets 3. The cargo file with the requisite crates for prostgen 4. A set of test cases that we had run into when using prost_library and tonic_library. The //proto/prostgen/raze folder doesn't quite interoperate with the //proto/raze folder, and I haven't had a chance to nail that down yet. There are also some targets missing from WORKSPACE needed for the tests. For googlers, the high-level approach is described in go/rust-protobuf.
I'm going to pick this up again soon but the biggest blocker that I can't really figure out is how to make the prost/tonic dependencies controllable by the user of the rules. @dfreese @illicitonion @UebelAndre Do you have any ides of a good approach regarding that? |
Toolchains can probably be used to solve for this. I recently did #678 to address a similar usability concern with the existing proto rules. Maybe that helps? But I'd love to see this get in so thanks for pinging this! 😄 |
@UebelAndre The problem with toolchains is that currently there is also an macro that is being used here rules_rust/proto/prostgen/prostgen.bzl Line 253 in cc60173
This macro is dependent on prost/tonic. I could of course change it so that the user has to supply prost/tonic themselves as deps to the macro. The usability suffers a bit though. Another issue is that the generator rule depends on this binary which depends on prost/tonic as well: rules_rust/proto/prostgen/BUILD Line 10 in cc60173
I guess since the binary is only used for generating the |
This doesn't seem link to a file. Could you maybe link something directly from your branch so I know for sure what you're referring to? I think there's a bad patter where the rules are designed to use a set of dependencies gathered outside the set of dependencies users actually want to build with. This is generally fine for tools (binaries that are run but otherwise don't share dependencies with your targets) but in cases where a rule produces dependencies, we need to probably have the initial expectation be that users provide their own dependencies. I'm not sure who would have the best insight on something like this. I think you pinged an appropriate group though. I'll take some time this week to do a deeper dive into the rules and see what suggestions I can come up with. |
Also unrelated to the dependencies issue, how do we feel about using |
@UebelAndre Sorry, I updated the links. |
Ah yeah, I feel like this is a bad pattern and isn't very maintainable (not specific to anything in these rules, a general pattern of handling dependencies). Maybe instead of using a macro we should be using a rule? @dfreese might have more context here (being the original author) on how this came to be. |
The context as to why it was a macro, rather than a rule was I was building outside of rules_rust, so I was trying to avoid depending on internals, such as //rust/private. A rule would make a lot more sense here, and would probably allow the extern attribute/macro parameter to be removed and consolidated into deps, but that could be a fair bit of work, at least initially. |
I'm building an app that has a frontend written in Rust and compiled to wasm, and it has a tonic/prost gRPC client in the wasm frontend. This poses a challenge, because To solve this I did the following:
These changes mean that all Hopefully this is helpful while you continue work on this PR, let me know if I can provide more detail that would be helpful. |
I unfortunately won't have time to finish this in the foreseeable future, if anybody wants to pick this up they feel free to do so. |
@purkhusid can you give a summary of what things are missing to get this up to speed and working? |
@rdelfin The main blocker is that the prost/tonic dependencies can not be overriden by the user of the rules. This can lead to hard to debug behaviour in your application if you might for example have an existing dependency that depends on a different version of prost/tonic than these rules use by default. The rules would have to be migrated to use toolchains in the places where the dependencies can easily be replaced and then the macros would probably have to be replaced with a proper custom rule so that we can use the dependencies that are provided by the toolchains. |
Talked to a coworker that knows a lot more about Bazel than myself and basically there's a couple options for where this can go:
With all these options we would still make the generated |
Does it need to be a separate repo/library? I feel like a toolchain would be the right choice here and would basically accomplish this. Plus, this is a pattern already in use for other rules ( I think this leads me to favor option 2
Finally, I would definitely not even consider option 1, updating the version of these crates shouldn't require a PR to the repo. It's unnecessary churn for users and maintainers. But that's just my personal opinion. |
I'm closing this out since no one is working on it and (despite it's age of the PR), the draft appears to be leading some folks to think the work is in progress. I'd be happy to see it reopened and pushed to completion since this would be an awesome feature! |
This is an continuation of #479.
The plan is to create a completely separate ruleset for Tonic/Prost that can be loaded by including a separate repository.