-
Notifications
You must be signed in to change notification settings - Fork 434
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
FR: Add tonic/prost rules #915
Comments
Right now there are two drafts for adding these rules: As of right now, they're both pretty dated and likely will not work with the current rev of the rules. Hopefully this effort is revived 😄 |
Hopefully, for folks looking to use a modern version of protobuf for proto generation, |
Even without tonic/prost rules, which would certainly make for less boilerplate, it's not too bad. https://github.com/shikhar/bazel-tonic is an example project I created that entirely uses |
I think it might be better to not have these in I have rules that can live in there in the works. |
I'd welcome it! I think it'd be better to keep proto/grpc rules all together. Even if they're for different languages. |
I saw rules-proto-grpc/rules_proto_grpc#143 was recently opened. Seems like there's some interest in adding something like that to |
Oh hi, I stubled across this from your cross-link 👋 I'm stuck at the moment with Tonic/Prost support in rules_proto_grpc since they don't have protoc plugins available and instead require you use their own generation method that itself wraps protoc. It seems there were previously plugins and could be again in the future if there's demand. Otherwise I may have to figure out a way to wrap their generation method in a pseudo-plugin just to satisfy protoc, similar to what was done in those links above. |
Its not plugins that were previously available, its more we are all on the bleeding edge.
You are waiting on this tokio-rs/prost#492.
I am going to try to push up my rules as they are for getting that working, there is some abuse of patch in cargo-raze to pull a few small tweaks to let things work.
I am going to look at what @Tuetuopay has done w.r.t a single lib.rs for this (its not needed fully for rules_gprc, but I think its a generally good change), along with some tweaks to see if descriptors can be included for grpc-reflection.
…On Thu, Sep 23, 2021, at 4:11 PM, Adam Liddell wrote:
Oh hi, I stubled across this from your cross-link 👋
I'm stuck at the moment with Tonic/Prost support in rules_proto_grpc since they don't have protoc plugins available and instead require you use their own generation method that itself wraps protoc. It seems there were previously plugins and could be again in the future if there's demand. Otherwise I may have to figure out a way to wrap their generation method in a pseudo-plugin just to satisfy protoc, similar to what was done in those links above.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub <#915 (comment)>, or unsubscribe <https://github.com/notifications/unsubscribe-auth/AAA6X34UR4ZEHNIFHZ2IAC3UDOXZJANCNFSM5C7KA6TQ>.
Triage notifications on the go with GitHub Mobile for iOS <https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675> or Android <https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub>.
|
@GregBowyer is tokio-rs/prost#492 (comment) meaningful info for you? If the changes there were to go in a separate crate, would it still be possible to use them to write prost/tonic rules? |
I'm unable to use |
I have an alternative fix 💪 ✅ It's not optimal, but this is a blocking issue for me, so I needed some way past it. First you do like you always would with
build.rs use std::fs;
use std::path::Path;
const PROTO_OUT_DIR: &str = "./src/rust";
fn main() -> Result<(), Box<dyn std::error::Error>> {
if Path::new(PROTO_OUT_DIR).is_dir() {
fs::remove_dir_all(PROTO_OUT_DIR)?;
}
fs::create_dir(PROTO_OUT_DIR).expect("Failed to create out dir");
fs::write(
format!("{}/mod.rs", PROTO_OUT_DIR),
"pub mod sensors_service;",
)?;
let files = vec!["proto/sensors_service.proto"];
let includes = vec!["proto"];
tonic_build::configure()
.build_client(true)
.build_server(true)
.format(true)
.out_dir(PROTO_OUT_DIR)
.compile(&files, &includes)?;
Ok(())
} Cargo.toml [package]
name = "protos"
version = "0.1.0"
authors = ["sollimann <[email protected]>"]
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
tonic = { version = "0.4", features = ["prost"] }
prost = "0.7"
prost-types = "0.7"
serde = { version = "1.0", features = ["derive"] }
[build-dependencies]
tonic-build = "0.4"
prost-build = "0.7" BUILD.bazel load("@rules_rust//rust:defs.bzl", "rust_library")
package(default_visibility = ["//visibility:public"])
rust_library(
name = "protos",
srcs = glob(["**/*.rs"]),
# crate_features = [
# "default",
# "std",
# ],
crate_root = "src/lib.rs",
data = [],
edition = "2021",
rustc_flags = [
"--cap-lints=allow",
],
version = "0.1.0",
visibility = [
# had to add this line to be able to add /protos ass dep to grpc-connector-service
"//services/grpc-connector-service:__subpackages__",
],
deps = [
"//protos/cargo:prost",
"//protos/cargo:prost_build",
"//protos/cargo:prost_types",
"//protos/cargo:serde",
"//protos/cargo:tonic",
"//protos/cargo:tonic_build",
],
) |
tokio-rs/prost#492 (comment) seems like a relevant update to this thread
|
Popping in to let you know that I pushed |
Has anyone managed to get this to work with protoc-gen-tonic and/or protoc-gen-prost? |
I've implemented support for |
In order to include this in rust sources this needs to be included directly downstream. Ideally we had a simple proto library target we could use instead, but the rust ecosystem is a bit bifurcated. bazelbuild/rules_rust#915 Signed-off-by: Keith Smiley <[email protected]> Signed-off-by: Keith Smiley <[email protected]> Co-authored-by: Elliot Jackson <[email protected]>
## 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.
## 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.
This is a fairly common request. It would be nice if there were some tonic/prost rules in the
@rules_rust//proto
package since the existing rules there are using the protobuf-rs crate which only supports a (now) 3 year old version of protobuf (see stepancheg/rust-protobuf#518).The text was updated successfully, but these errors were encountered: