diff --git a/Cargo.lock b/Cargo.lock index b367c2b..f128f24 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -429,16 +429,15 @@ dependencies = [ name = "example-proto" version = "0.2.6" dependencies = [ - "anyhow", "once_cell", "prost", "prost-build", "prost-reflect", "prost-reflect-build", - "prost-reflect-validate", - "prost-types", "prost-validate", "prost-validate-build", + "tonic", + "tonic-build", ] [[package]] @@ -1667,6 +1666,20 @@ dependencies = [ "tracing", ] +[[package]] +name = "tonic-build" +version = "0.12.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9557ce109ea773b399c9b9e5dca39294110b74f1f342cb347a80d1fce8c26a11" +dependencies = [ + "prettyplease", + "proc-macro2", + "prost-build", + "prost-types", + "quote", + "syn 2.0.79", +] + [[package]] name = "tonic-types" version = "0.12.3" diff --git a/Cargo.toml b/Cargo.toml index ba2beb2..74392b2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -30,6 +30,7 @@ prost-reflect = { version = "0.14.1", features = ["derive", "serde"] } prost-reflect-build = "0.14.0" tonic = "0.12.3" tonic-types = "0.12.3" +tonic-build = "0.12.3" anyhow = "1.0.86" thiserror = "1.0.63" http = "1.1.0" diff --git a/example-proto/Cargo.toml b/example-proto/Cargo.toml index d8bc1b1..e1f29c4 100644 --- a/example-proto/Cargo.toml +++ b/example-proto/Cargo.toml @@ -11,14 +11,13 @@ publish = false [dependencies] prost = { workspace = true } -prost-types = { workspace = true } prost-reflect = { workspace = true } prost-validate = { workspace = true, features = ["derive"] } -prost-reflect-validate = { workspace = true } +tonic = { workspace = true } once_cell = { workspace = true } -anyhow = { workspace = true } [build-dependencies] prost-build = { workspace = true } prost-reflect-build = { workspace = true } prost-validate-build = { workspace = true } +tonic-build = { workspace = true } diff --git a/example-proto/build.rs b/example-proto/build.rs index 1a9c228..bb48ed5 100644 --- a/example-proto/build.rs +++ b/example-proto/build.rs @@ -1,8 +1,12 @@ fn main() -> Result<(), Box> { - let files = &["message.proto"]; + let files = &["message.proto", "service.proto"]; let includes = &["proto", "../prost-validate-types/proto"]; - let mut config = prost_build::Config::new(); + let mut config = { + let mut c = prost_build::Config::new(); + c.service_generator(tonic_build::configure().service_generator()); + c + }; prost_validate_build::Builder::new().configure(&mut config, files, includes)?; diff --git a/example-proto/proto/service.proto b/example-proto/proto/service.proto new file mode 100644 index 0000000..29e34d2 --- /dev/null +++ b/example-proto/proto/service.proto @@ -0,0 +1,11 @@ +syntax = "proto3"; + +package validate.example; + +import "validate/validate.proto"; + +import "message.proto"; + +service ExampleService { + rpc ExampleMethod (ExampleMessage) returns (ExampleMessage); +} diff --git a/prost-validate-build/README.md b/prost-validate-build/README.md index be33a9c..fe0e79b 100644 --- a/prost-validate-build/README.md +++ b/prost-validate-build/README.md @@ -60,16 +60,36 @@ fn main() -> Result<(), Box> { ### Generating `prost-build` configuration for usage with other generators -#### Example for `prost-reflect-build` +#### Example for `prost-reflect-build` and `tonic-build` + +`service.proto`: + +```proto +syntax = "proto3"; + +package validate.example; + +import "validate/validate.proto"; + +import "message.proto"; + +service ExampleService { + rpc ExampleMethod (ExampleMessage) returns (ExampleMessage); +} +``` `build.rs`: ```rust fn main() -> Result<(), Box> { - let files = &["message.proto"]; + let files = &["message.proto", "service.proto"]; let includes = &["proto", "../prost-validate-types/proto"]; - let mut config = prost_build::Config::new(); + let mut config = { + let mut c = prost_build::Config::new(); + c.service_generator(tonic_build::configure().service_generator()); + c + }; prost_validate_build::Builder::new().configure(&mut config, files, includes)?;