Skip to content

grpc: crate maintenance#2654

Open
dfawley wants to merge 11 commits into
grpc:masterfrom
dfawley:alltogether
Open

grpc: crate maintenance#2654
dfawley wants to merge 11 commits into
grpc:masterfrom
dfawley:alltogether

Conversation

@dfawley
Copy link
Copy Markdown
Member

@dfawley dfawley commented May 23, 2026

  1. Rework the codegen crate:
  • protoc-gen-rust-grpc is now a real Rust crate that is able to build protoc (for now) and our plugin binary.
  • grpc-protobuf-build uses protoc-gen-rust-grpc to produce the binaries, instead of requiring the user to put them in their path.
  • Reworked the caching of the binaries a little. I thought we'd be able to use the standard Rust caching, but it didn't work for various reasons. So maybe this isn't much better than what was there before. LMK.
  • We now run cargo build for interop inside the CI's environment instead of in the run environment which uses MSYS and for some reason doesn't like the way we're doing the caching. (Maybe this is a good enough reason to go back to how the cache was working before?)
  1. Add a grpc/README.md, and add more info to Cargo.tomls, remove publish=false to allow them to be published, etc.

@dfawley dfawley added this to the grpc-next milestone May 23, 2026
@dfawley dfawley requested a review from arjan-bal May 23, 2026 00:14
Comment on lines +49 to +50
// If a prebuilt binary directory is specified but was empty, save the newly compiled
// binaries there so they can be cached and reused.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The cargo docs discourage writing artifacts outside of OUT_DIR. I suspect this may also lead to race conditions if there are multiple versions of the crate being built concurrently.

Is this being done only to speed up CI? I feel it's better to manually build the binaries using CMake once in CI instead of having a flag in the production build script to support this. Please let me know if you think otherwise.

Also, why does the regular Rust build cache not work in CI? Is it something that can be addressed by spending more time on the configuration, or is it a limitation in Swatinem/rust-cache@v2?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There were many issues with the Swatinem/rust-cache@v2 crate. First, I had to give it a shared cache location, and I had to set cache-workspace-crates. I ran into more problems, and ultimately I couldn't get it working, and also the cache files were very large. I think maybe we should revert back to the manual caching that it was doing before, and just change the way the compilation worked to use cargo instead of cmake from the commandline?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So it's easy enough to build this crate, then find the binary locations from the OUT_DIR (there's functions in lib.rs to tell us that). So we can find them and copy them out. But I think we have to be able to read them from the cache location and copy them back from there as part of build.rs -- if we're doing it outside of the build process, I don't know how we can determine where we should put them, and compiling the crate to call the functions it has would require building them. So I guess we can't completely go back to the way it was before. We could move the copying-out into it, though, though I suspect it's fine.

Also maybe we should publish our binary and download it / protoc instead of building by default?

Comment thread codegen/src/main.rs
Comment on lines -100 to -101
// TODO: Once the codegen is updated to allow the `OUT_DIR` env var to
// be unset, change this to use `.output_dir` instead.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since the OUT_DIR override is still present, we should leave a comment explaining why it's required.

Comment thread grpc-protobuf-build/Cargo.toml Outdated
prettyplease = "0.2.35"
protobuf-codegen = { version = "4.34.0-release" }
syn = "2.0.104"
protoc-gen-rust-grpc = { version = "0.9.0-alpha.1", path = "../protoc-gen-rust-grpc" }
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should the version of the protoc-gen-rust-grpc dependency also be 0.9.0-alpha.2?

Comment thread grpc-protobuf/Cargo.toml Outdated
[dependencies]
bytes = "1.11.1"
grpc = { path = "../grpc" }
grpc = { version = "0.9.0-alpha.1", path = "../grpc" }
Copy link
Copy Markdown
Contributor

@arjan-bal arjan-bal May 25, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should the version of the grpc dependency be 0.9.0-alpha.2? Or is it intentionally using the second latest version?

Comment thread interop/Cargo.toml Outdated
[build-dependencies]
tonic-prost-build = {path = "../tonic-prost-build"}
grpc-protobuf-build = {path = "../grpc-protobuf-build"}
protoc-gen-rust-grpc = {path = "../protoc-gen-rust-grpc"} No newline at end of file
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: No newline at end of file.

Comment thread protoc-gen-rust-grpc/src/lib.rs Outdated
@@ -0,0 +1,52 @@
/*
*
* Copyright 2025 gRPC authors.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: The copyright year needs to be 2026.


Note: as part of compiling, the source files for `protoc` are downloaded from
the [protobuf github repository](https://github.com/protocolbuffers/protobuf).
The archive's checksum is verified before compiling.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a fallback which skips hash verification for unknown versions, should we remove that to avoid supply chain attacks?

else()
message(WARNING "Unknown protobuf version ${VERSION}, downloading without hash verification")
set(HASH "")
endif()

Comment thread .github/workflows/CI.yml
path: protoc-cache
key: protoc-binaries-${{ runner.os }}-${{ hashFiles('protoc-gen-rust-grpc/src/cpp_source/**') }}
- uses: Swatinem/rust-cache@v2
- run: cargo build -p interop
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this done to avoid building the binaries twice, once for TLS and once for non-TLS tests? Maybe we should add this to the comment in test.sh. It took me a couple of minutes to understand the use reason for caching the artifacts in CI.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See PR description:

We now run cargo build for interop inside the CI's environment instead of in the run environment which uses MSYS and for some reason doesn't like the way we're doing the caching. (Maybe this is a good enough reason to go back to how the cache was working before?)

I can try to expand on this in the comment in test.sh if we don't decide to change things further.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants