diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index e187bcd41..57ffa443d 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -46,10 +46,6 @@ jobs: steps: - uses: actions/checkout@v4 - uses: hecrj/setup-rust-action@v2 - - name: Install protoc - uses: taiki-e/install-action@v2 - with: - tool: protoc@3.25.1 - uses: Swatinem/rust-cache@v2 - run: cargo run --package codegen - run: git diff --exit-code diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 4a47e263c..c7d116c01 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -211,8 +211,7 @@ example would explicitly use `Timeout::new`. For example: When making changes to `tonic-build` that affects the generated code you will need to ensure that each of the sub crates gets updated as well. Each of the sub crates like, for example `tonic-health`, generate their gRPC code via `codegen` -crate. This requires `Protocol Buffers Compiler` of which version is same as the -one used in the GitHub Action (see [`codegen` job](./.github/workflows/CI.yml)). +crate. ``` cargo run --package codegen diff --git a/codegen/Cargo.toml b/codegen/Cargo.toml index f4d9f3290..1a8ff398d 100644 --- a/codegen/Cargo.toml +++ b/codegen/Cargo.toml @@ -8,4 +8,5 @@ version = "0.1.0" [dependencies] tempfile = "3.8.0" +protox = "0.7" tonic-build = {path = "../tonic-build", default-features = false, features = ["prost", "cleanup-markdown"]} diff --git a/codegen/src/main.rs b/codegen/src/main.rs index e67be9b4d..d74d8f1ae 100644 --- a/codegen/src/main.rs +++ b/codegen/src/main.rs @@ -1,4 +1,11 @@ -use std::path::{Path, PathBuf}; +use std::{ + fs::File, + io::{BufWriter, Write as _}, + path::{Path, PathBuf}, +}; + +use protox::prost::{bytes::BytesMut, Message as _}; +use tonic_build::FileDescriptorSet; fn main() { // tonic-health @@ -82,12 +89,15 @@ fn codegen( let out_dir = root_dir.join(out_dir); let file_descriptor_set_path = root_dir.join(file_descriptor_set_path); + let fds = protox::compile(&iface_files, &include_dirs).unwrap(); + + write_fds(&fds, &file_descriptor_set_path); + tonic_build::configure() .build_client(build_client) .build_server(build_server) .out_dir(&tempdir) - .file_descriptor_set_path(file_descriptor_set_path) - .compile_protos(&iface_files, &include_dirs) + .compile_fds(fds) .unwrap(); for path in std::fs::read_dir(tempdir.path()).unwrap() { @@ -105,3 +115,10 @@ fn codegen( std::fs::copy(&path, &to).unwrap(); } } + +fn write_fds(fds: &FileDescriptorSet, path: &Path) { + let mut writer = BufWriter::new(File::create(path).unwrap()); + let mut buf = BytesMut::with_capacity(fds.encoded_len()); + fds.encode(&mut buf).unwrap(); + writer.write_all(&buf).unwrap(); +} diff --git a/tonic-health/src/generated/grpc_health_v1.bin b/tonic-health/src/generated/grpc_health_v1.bin index 52efb3122..06b20f41f 100644 Binary files a/tonic-health/src/generated/grpc_health_v1.bin and b/tonic-health/src/generated/grpc_health_v1.bin differ diff --git a/tonic-reflection/src/generated/reflection_v1.bin b/tonic-reflection/src/generated/reflection_v1.bin index 4b4ecaef9..b6add193e 100644 Binary files a/tonic-reflection/src/generated/reflection_v1.bin and b/tonic-reflection/src/generated/reflection_v1.bin differ diff --git a/tonic-reflection/src/generated/reflection_v1alpha1.bin b/tonic-reflection/src/generated/reflection_v1alpha1.bin index 62d18b45b..5d3cd025d 100644 Binary files a/tonic-reflection/src/generated/reflection_v1alpha1.bin and b/tonic-reflection/src/generated/reflection_v1alpha1.bin differ diff --git a/tonic-types/src/generated/types.bin b/tonic-types/src/generated/types.bin index 8af4e92be..94b818cff 100644 Binary files a/tonic-types/src/generated/types.bin and b/tonic-types/src/generated/types.bin differ