Skip to content

Commit

Permalink
Make Codegen script more configurable (#3635)
Browse files Browse the repository at this point in the history
Adds a method that allows supplying a prost config.
  • Loading branch information
imotov authored Jul 14, 2023
1 parent ad28cfb commit 0ad4922
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 8 deletions.
1 change: 1 addition & 0 deletions quickwit/Cargo.lock

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

20 changes: 19 additions & 1 deletion quickwit/quickwit-codegen/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,25 @@ fn main() {
}
```

5. If any parts of the protocol should be serialized as `bytes::Bytes` instead of `Vec[u8]` list paths to these elements in the last argument.
5. If additional prost settings need to be configured they can be provided the following way:

```rust
use quickwit_codegen::Codegen;

fn main() {
let mut config = prost_build::Config::default();
config.bytes(["PingRequest.name", "PingResponse.name"]);
Codegen::run_with_config(
"src/hello.proto",
"src/",
"crate::HelloResult",
"crate::HelloError"
&[],
config
).unwrap();
}
```


6. Import and implement the generated service trait and use the various generated adapters to instantiate a gRPC server, or use a local or remote gRPC implementation with the same client interface.

Expand Down
1 change: 0 additions & 1 deletion quickwit/quickwit-codegen/example/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ fn main() {
"crate::HelloResult",
"crate::HelloError",
&[],
&[],
)
.unwrap();
}
21 changes: 18 additions & 3 deletions quickwit/quickwit-codegen/src/codegen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,31 @@ impl Codegen {
out_dir: &str,
result_type_path: &str,
error_type_path: &str,
bytes: &[&str],
includes: &[&str],
) -> anyhow::Result<()> {
Self::run_with_config(
protos,
out_dir,
result_type_path,
error_type_path,
includes,
prost_build::Config::default(),
)
}

pub fn run_with_config(
protos: &[&str],
out_dir: &str,
result_type_path: &str,
error_type_path: &str,
includes: &[&str],
mut prost_config: prost_build::Config,
) -> anyhow::Result<()> {
let service_generator = Box::new(QuickwitServiceGenerator::new(
result_type_path,
error_type_path,
));

let mut prost_config = prost_build::Config::default();
prost_config
.protoc_arg("--experimental_allow_proto3_optional")
.type_attribute(
Expand All @@ -50,7 +66,6 @@ impl Codegen {
"DocBatch.doc_buffer",
"#[schema(value_type = String, format = Binary)]",
)
.bytes(bytes)
.service_generator(service_generator)
.out_dir(out_dir);

Expand Down
1 change: 0 additions & 1 deletion quickwit/quickwit-control-plane/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ fn main() {
"crate::Result",
"crate::ControlPlaneError",
&[],
&[],
)
.unwrap();
}
1 change: 1 addition & 0 deletions quickwit/quickwit-ingest/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ quickwit-actors = { workspace = true, features = ["testsuite"] }

[build-dependencies]
quickwit-codegen = { workspace = true }
prost-build = { workspace = true }

[features]
testsuite = ["mockall"]
6 changes: 4 additions & 2 deletions quickwit/quickwit-ingest/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,15 @@
use quickwit_codegen::Codegen;

fn main() {
Codegen::run(
let mut config = prost_build::Config::default();
config.bytes(["DocBatch.doc_buffer"]);
Codegen::run_with_config(
&["src/ingest_service.proto"],
"src/codegen/",
"crate::Result",
"crate::IngestServiceError",
&["DocBatch.doc_buffer"],
&[],
config,
)
.unwrap();
}

0 comments on commit 0ad4922

Please sign in to comment.