Skip to content

upgrade to latest rules_proto 7.x with legacy protoc#3

Merged
chrisirhc merged 14 commits intomainfrom
copilot/upgrade-bazel-dependencies
Feb 7, 2026
Merged

upgrade to latest rules_proto 7.x with legacy protoc#3
chrisirhc merged 14 commits intomainfrom
copilot/upgrade-bazel-dependencies

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Jan 28, 2026

rules_proto 7.x emits --option_dependencies and --option_dependencies_violation_msg flags requiring protoc 32.0+. grpcio-tools bundles protoc ~28.x which errors on these flags.

Changes

  • Enhanced main.py: Added intelligent filtering logic that checks protoc version before filtering

    • Detects protoc version from grpc_version.VERSION in grpcio_tools package
    • Parses version strings with flexible logic that handles both 2 and 3 component versions
    • For 3-component versions (e.g., "5.28.3", "6.30.1"), discards first component and uses remaining (28.3, 30.1)
    • For 2-component versions (e.g., "28.3", "32.0"), uses as-is
    • Only filters unsupported flags if protoc version < 32.0
    • Automatically stops filtering when grpcio-tools upgrades to protoc 32.0+
    • Handles both --flag value and --flag=value formats
    • Transparent passthrough for all other arguments
    • No subprocess calls - reads version directly from package
  • Added comprehensive unit tests: Created main_test.py with 14 test cases

    • Version parsing tests for various version formats (3-component and 2-component)
    • Filtering behavior tests with different protoc versions
    • Tests for both flag formats and missing version scenarios
    • All tests pass ✓
  • Upgraded to latest versions:

    • rules_proto: 6.0.2 → 7.1.0
    • toolchains_protoc: 0.3.4 → 0.6.1
    • (All other dependencies already at latest)

Example

The wrapper intelligently transforms protoc invocations based on version:

# For protoc < 32.0 (current grpcio-tools)
# Input from rules_proto 7.x
['--python_out=out', '--option_dependencies', 'file.proto', 
 '--option_dependencies_violation_msg=...', 'input.proto']

# Filtered for legacy protoc
['--python_out=out', 'input.proto']

# For protoc >= 32.0 (future grpcio-tools)
# All flags passed through unchanged
['--python_out=out', '--option_dependencies', 'file.proto', 
 '--option_dependencies_violation_msg=...', 'input.proto']

This maintains the ~29X build speedup from prebuilt protoc while using latest Bazel rules, and automatically adapts when grpcio-tools is upgraded.


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI changed the title [WIP] Upgrade to latest versions of all bazel dependencies Upgrade Bazel dependencies to latest BCR versions Jan 28, 2026
Copilot AI requested a review from chrisirhc January 28, 2026 15:57
@chrisirhc chrisirhc marked this pull request as ready for review January 29, 2026 12:57
@chrisirhc chrisirhc force-pushed the copilot/upgrade-bazel-dependencies branch from 79b4987 to 707c92d Compare January 29, 2026 12:58
Copilot AI changed the title Upgrade Bazel dependencies to latest BCR versions Fix protoc version incompatibility: downgrade rules_proto to 6.0.2 Jan 29, 2026
Copilot AI changed the title Fix protoc version incompatibility: downgrade rules_proto to 6.0.2 Filter unsupported protoc flags to enable rules_proto 7.x with legacy protoc Jan 29, 2026
@@ -0,0 +1,70 @@
#!/usr/bin/env python3
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Move this logic into main.py

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done. Moved the filtering logic into main.py and removed protoc_wrapper.py. Commit: 5012485

filtered_argv = [sys.argv[0]] + filter_unsupported_flags(sys.argv[1:])

# Replace sys.argv with filtered arguments
sys.argv = filtered_argv
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Check whether protoc version is below 32 before performing the filter.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done. Added get_protoc_version() function that detects the protoc version. The filter only runs if the version is below 32. If the version is 32 or above, or cannot be determined, all flags are passed through unchanged. Commit: 5012485

# Try to get version by running protoc --version
# We need to temporarily capture the output
result = subprocess.run(
[sys.executable, '-m', 'grpc_tools.protoc', '--version'],
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Don't do a process call. Use the modules' version instead, from its package metadata.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done. Changed to use package metadata via importlib.metadata (with pkg_resources fallback). The function now gets the protobuf version from package metadata and converts it to protoc version (e.g., protobuf 5.28.3 → protoc 28.3). No subprocess calls. Commit: e63816a

@chrisirhc
Copy link
Copy Markdown
Owner

@copilot rebase on main and merge conflicts then check bazel build output and see if there are any errors.

Copy link
Copy Markdown
Contributor Author

Copilot AI commented Jan 29, 2026

@copilot rebase on main and merge conflicts then check bazel build output and see if there are any errors.

I checked the repository state and attempted to build with bazel. Findings:

Rebase Status:

  • The branch is currently grafted and there's no main branch to rebase against in the remote
  • No merge conflicts exist
  • Branch is up-to-date with origin/copilot/upgrade-bazel-dependencies

Build Check:

  • Python syntax validation: ✓ main.py passes
  • Bazel build: Unable to complete due to network restrictions preventing bazelisk from downloading bazel 8.5.1
  • All configuration files (MODULE.bazel, BUILD.bazel) have correct syntax

The code changes are ready and syntactically correct. The bazel build would need to be tested in an environment with network access to releases.bazel.build.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • releases.bazel.build
    • Triggering command: /usr/local/lib/node_modules/@bazel/bazelisk/bazelisk-linux_amd64 /usr/local/lib/node_modules/@bazel/bazelisk/bazelisk-linux_amd64 build //... (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Copilot AI and others added 4 commits January 30, 2026 19:47
Co-authored-by: chrisirhc <132584+chrisirhc@users.noreply.github.com>
Co-authored-by: chrisirhc <132584+chrisirhc@users.noreply.github.com>
…o 7.1.0

Co-authored-by: chrisirhc <132584+chrisirhc@users.noreply.github.com>
Copilot AI and others added 6 commits January 30, 2026 19:49
Co-authored-by: chrisirhc <132584+chrisirhc@users.noreply.github.com>
Co-authored-by: chrisirhc <132584+chrisirhc@users.noreply.github.com>
Co-authored-by: chrisirhc <132584+chrisirhc@users.noreply.github.com>
@chrisirhc chrisirhc force-pushed the copilot/upgrade-bazel-dependencies branch from 159bc94 to ddee3d5 Compare January 30, 2026 11:56
# Try importlib.metadata first (Python 3.8+)
try:
from importlib.metadata import version
protobuf_version = version('protobuf')
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Instead of using protobuf package version, it should get the protoc version from the grpc_version in the grpcio package. Source https://github.com/grpc/grpc/blob/master/tools/distrib/python/grpcio_tools/grpc_version.py

Add a unit test for checking this behavior.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done. Changed to use grpc_version.VERSION from the grpcio_tools package instead of protobuf package metadata. Added comprehensive unit tests in main_test.py with 14 test cases covering version parsing and filtering behavior. All tests pass. Commit: a016ade

# Convert protobuf version to protoc version
# protobuf 5.x.y -> protoc 2x.y (e.g., 5.28.3 -> 28.3)
# protobuf 32.x.y -> protoc 32.x.y (future versions)
if major == 5:
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Rather than checking the major number, discard the first number if there are 3 components to the version. Because major can be 6 and we'll still use the 2nd and 3rd components.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done. Changed version parsing logic to discard the first number if there are 3 components to the version, regardless of what the major number is. For example:

  • "5.28.3" → (28, 3, 0)
  • "6.30.1" → (30, 1, 0)
  • "28.3" → (28, 3, 0)
  • "32.0" → (32, 0, 0)

Commit: a016ade

Co-authored-by: chrisirhc <132584+chrisirhc@users.noreply.github.com>
@chrisirhc chrisirhc changed the title Filter unsupported protoc flags to enable rules_proto 7.x with legacy protoc upgrade to latest rules_proto 7.x with legacy protoc Feb 5, 2026
@chrisirhc chrisirhc merged commit a851921 into main Feb 7, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants