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

Add Rust Tonic and Prost support #143

Closed
aaliddell opened this issue Sep 17, 2021 · 7 comments
Closed

Add Rust Tonic and Prost support #143

aaliddell opened this issue Sep 17, 2021 · 7 comments
Labels
enhancement New feature or request lang-rust Rust rules specific resolved-next-release Code to resolve issue is pending release

Comments

@aaliddell
Copy link
Member

aaliddell commented Sep 17, 2021

Either as additional rules or to replace the current rules as breaking change. These are better supported than the current grpcio etc crates and avoid the flakeyness of the current grpc-sys workarounds.

To do this requires that they have protoc plugins, which neither currently have since they share the same builder core. Currently blocked on:

@aaliddell aaliddell added enhancement New feature or request blocked-external Waiting on external issue/release lang-rust Rust rules specific labels Sep 17, 2021
@titanous
Copy link
Contributor

I'm interested in implementing this. I think it would make sense to remove the existing rules and replace them with new rules (that have tonic and prost in the rule names in case other libraries become popular in the future).

@aaliddell
Copy link
Member Author

Do the upstream libraries actually have working protoc plugins yet? There seem to be some external ones, but are these official?

@titanous
Copy link
Contributor

They aren't official but they seem to work fine.

@UebelAndre
Copy link

bazelbuild/rules_rust#915 (comment) may be useful here.

@titanous
Copy link
Contributor

I've made good progress implementing this, but I've run into an issue where the tonic (gRPC) plugin wants to write to the output files from the prost plugin, and I can't see an existing way to make this happen in compile.bzl. Suggestions?

@titanous
Copy link
Contributor

I've implemented this in #202.

alexjpwalker added a commit to typedb/typedb-dependencies that referenced this issue Nov 21, 2022
## What is the goal of this PR?

We added the `rust_tonic_compile` rule which compiles `.proto` files
into Rust sources that depend on the `tonic` and `prost` crates.

## What are the changes implemented in this PR?

We had an existing Rust binary for compiling proto files into a Tonic
library - a Cargo build script in `typedb-protocol`. But Cargo users
shouldn't have to run `protoc` on their machine to compile
`typedb-client` (which is what happens with a Cargo build script).
Rather, the `typedb-protocol` crate should contain the generated Rust
gRPC + Protobuf sources.

So we've created a rule, `rust_tonic_compile`, that internally runs a
`rust_binary` (similarly to how many of our rules run Kotlin binaries),
which uses `tonic_build` to compile `.proto` files into Rust sources,
and exposes the outputs. Any `rust_library` can then depend on these
generated sources. The API is similar to Java and Python
(`java_grpc_compile` and `python_grpc_compile` respectively), and the
`antlr` rule from `rules_antlr` behaves similarly, too.

Ideally, we wouldn't need our own rule to do this, however, the Bazel
rules repos that contain Rust gRPC + Protobuf rules only support the
`grpc` crate, and not the more popular `tonic` crate. Moreover, all of
them already have open PRs for adding such functionality:

- rules-proto-grpc/rules_proto_grpc#143
- stackb/rules_proto#201
- bazelbuild/rules_rust#915

Given that our implementation is **very minimal** (~30 lines of code) it
should incur a very low maintenance effort.
jamesreprise pushed a commit to jamesreprise/vaticle-dependencies that referenced this issue Dec 5, 2022
## What is the goal of this PR?

We added the `rust_tonic_compile` rule which compiles `.proto` files
into Rust sources that depend on the `tonic` and `prost` crates.

## What are the changes implemented in this PR?

We had an existing Rust binary for compiling proto files into a Tonic
library - a Cargo build script in `typedb-protocol`. But Cargo users
shouldn't have to run `protoc` on their machine to compile
`typedb-client` (which is what happens with a Cargo build script).
Rather, the `typedb-protocol` crate should contain the generated Rust
gRPC + Protobuf sources.

So we've created a rule, `rust_tonic_compile`, that internally runs a
`rust_binary` (similarly to how many of our rules run Kotlin binaries),
which uses `tonic_build` to compile `.proto` files into Rust sources,
and exposes the outputs. Any `rust_library` can then depend on these
generated sources. The API is similar to Java and Python
(`java_grpc_compile` and `python_grpc_compile` respectively), and the
`antlr` rule from `rules_antlr` behaves similarly, too.

Ideally, we wouldn't need our own rule to do this, however, the Bazel
rules repos that contain Rust gRPC + Protobuf rules only support the
`grpc` crate, and not the more popular `tonic` crate. Moreover, all of
them already have open PRs for adding such functionality:

- rules-proto-grpc/rules_proto_grpc#143
- stackb/rules_proto#201
- bazelbuild/rules_rust#915

Given that our implementation is **very minimal** (~30 lines of code) it
should incur a very low maintenance effort.
@aaliddell aaliddell added resolved-next-release Code to resolve issue is pending release and removed blocked-external Waiting on external issue/release labels Sep 8, 2023
@aaliddell
Copy link
Member Author

Closed by #265

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request lang-rust Rust rules specific resolved-next-release Code to resolve issue is pending release
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants