Improve build.rs protobuf codegen and caching. - #2845
Draft
nathanielford wants to merge 2 commits into
Draft
Conversation
Avoid rebuilding in-tree protobuf files when source protos and generated markers are unchanged. Detect missing generated directories and proto timestamp changes automatically while preserving fast-path (~0.2s) builds. Remove redundant CARGO_MANIFEST_DIR usages.
…GEN flag * Check for protoc availability in build scripts and fall back to checked-in code with a warning if missing. * Add SKIP_GRPC_RUST_PROTO_CODEGEN environment variable detection to unconditionally skip codegen during CI checks. * Set SKIP_GRPC_RUST_PROTO_CODEGEN: 1 in semver CI workflow job.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
Improve build script around protobuf code generation. Ensure that:
Partially addresses #2661 (resolves build script codegen caching and unnecessary rebuilds; crate package separation between tonic and grpc examples remains open).
Problem
GRPC_RUST_REGENERATE_PROTOto regenerate. Ifgenerated/was missing or.protofiles were modified, builds failed or remained stale unless the flag was explicitly passed.cargo:rerun-if-changedon output directory paths (generated/) causes Cargo to register directory timestamp mutations during execution, leading to infinite rebuild loops.CARGO_MANIFEST_DIRwas read and used for path joins, despite Cargo guaranteeing the build script process working directory is already the package root.Changes
generated/.../generated.rs) and source proto inputs viacargo:rerun-if-changed..protomodification timestamps against generated marker files.CodeGenif:GRPC_RUST_REGENERATE_PROTOenvironment flag is provided.generated/or output marker files are missing..protofiles have newer modification timestamps than generated output files.CodeGenon unchanged runs, keeping no-op builds cached at ~0.2s.CARGO_MANIFEST_DIRconversions in favor of package-root relative paths.Affected Files
grpc-protobuf/build.rsexamples/build.rsTest Plan
cargo check -p grpc-protobufandcargo check -p examples --features grpc-helloworld,grpc-routeguide.generated/is deleted..protofiles are touched.cargo fmt --all --check,cargo clippy).