Skip to content

Commit

Permalink
add usage with tonic-build doc
Browse files Browse the repository at this point in the history
Signed-off-by: Adphi <philippe.adrien.nousse@gmail.com>
  • Loading branch information
Adphi committed Jan 9, 2025
1 parent 5114a70 commit 2a2642e
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 11 deletions.
19 changes: 16 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
5 changes: 2 additions & 3 deletions example-proto/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
8 changes: 6 additions & 2 deletions example-proto/build.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
fn main() -> Result<(), Box<dyn std::error::Error>> {
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)?;

Expand Down
11 changes: 11 additions & 0 deletions example-proto/proto/service.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
syntax = "proto3";

package validate.example;

import "validate/validate.proto";

import "message.proto";

service ExampleService {
rpc ExampleMethod (ExampleMessage) returns (ExampleMessage);
}
26 changes: 23 additions & 3 deletions prost-validate-build/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,16 +60,36 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {

### 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<dyn std::error::Error>> {
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)?;

Expand Down

0 comments on commit 2a2642e

Please # to comment.