Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Feb 2, 2026

Adding protoc-gen-validate Module to Bazel Registry

  • Understand the requirement - add protoc-gen-validate v1.2.1.bcr.2 module
  • Create module directory structure
  • Download and compute SHA256 hash for source tarball
  • Create metadata.json with module metadata
  • Create version directory (1.2.1.bcr.2.envoy)
  • Create source.json with download URL and integrity hash
  • Create MODULE.bazel with dependencies
  • Add presubmit.yml for testing
  • Update grpc module to reference the new version
  • Verify CI passes and module builds correctly
Original prompt

Summary

Add a new protoc-gen-validate module to the toolshed bazel-registry based on BCR version 1.2.1.bcr.2, with an additional patch to fix re2 dependency labels for bzlmod compatibility.

Background

Envoy is migrating dependencies to bzlmod via the toolshed bazel-registry. The protoc-gen-validate (PGV) module in BCR uses @com_googlesource_code_re2 as a repo_name alias for the re2 dependency, but the internal Starlark files still reference @com_googlesource_code_re2//:re2 which doesn't work correctly in all bzlmod scenarios. We need to patch these to use the canonical @re2 label instead.

Required Changes

Create the following structure in bazel-registry/modules/protoc-gen-validate/1.2.1.bcr.2.envoy/:

1. MODULE.bazel

Copy from BCR's 1.2.1.bcr.2 version but update the version string:

module(
    name = "protoc-gen-validate",
    version = "1.2.1.bcr.2.envoy",
    compatibility_level = 1,
    repo_name = "com_envoyproxy_protoc_gen_validate",
    bazel_compatibility = ['>=7.2.1'],
)

bazel_dep(
    name = "bazel_skylib",
    version = "1.8.1",
)
bazel_dep(
    name = "gazelle",
    version = "0.46.0",
    repo_name = "bazel_gazelle",
)
bazel_dep(
    name = "protobuf",
    version = "33.0",
    repo_name = "com_google_protobuf",
)
bazel_dep(
    name = "re2",
    version = "2024-07-02.bcr.1",
)
bazel_dep(
    name = "rules_cc",
    version = "0.2.13",
)
bazel_dep(
    name = "rules_go",
    version = "0.58.3",
    repo_name = "io_bazel_rules_go",
)
bazel_dep(
    name = "rules_java",
    version = "8.16.1",
)
bazel_dep(
    name = "rules_proto",
    version = "7.1.0",
)
bazel_dep(
    name = "rules_python",
    version = "1.6.0",
)
# -- bazel_dep definitions -- #

go_sdk = use_extension("@io_bazel_rules_go//go:extensions.bzl", "go_sdk")
go_sdk.download(version = "1.24.0")

go_deps = use_extension("@bazel_gazelle//:extensions.bzl", "go_deps")
go_deps.from_file(go_mod = "//:go.mod")
use_repo(
    go_deps,
    "com_github_iancoleman_strcase",
    "com_github_lyft_protoc_gen_star_v2",
    "org_golang_google_protobuf",
    "org_golang_x_net",
)

PYTHON_VERSIONS = [
    "3.9",
    "3.10",
    "3.11",
    "3.12",
    "3.13",
]

python = use_extension("@rules_python//python/extensions:python.bzl", "python")

[
    python.toolchain(
        is_default = python_version == PYTHON_VERSIONS[-1],
        python_version = python_version,
    )
    for python_version in PYTHON_VERSIONS
]

pip = use_extension("@rules_python//python/extensions:pip.bzl", "pip")

[
    pip.parse(
        hub_name = "pgv_pip_deps",
        python_version = python_version,
        requirements_lock = "//python:requirements.txt",
    )
    for python_version in PYTHON_VERSIONS
]

use_repo(pip, "pgv_pip_deps")

Important: Remove the repo_name = "com_googlesource_code_re2" from the re2 bazel_dep since we're patching the files to use @re2 directly.

2. source.json

Based on BCR's source.json but adding the re2 patch:

{
    "url": "https://github.com/bufbuild/protoc-gen-validate/archive/refs/tags/v1.2.1.tar.gz",
    "integrity": "sha256-5HGDUnVN8Tk7h5K2MTOKqFYvOQ6BYHg+NlRUvBHZYyg=",
    "strip_prefix": "protoc-gen-validate-1.2.1",
    "overlay": {
        "MODULE.bazel": "sha256-<compute-after-creating-file>"
    },
    "patches": {
        "bazel_9_fixes.patch": "sha256-bv6l2BHe/pw7Zi5HBwBloPAzIC5YxEuqlW+26Brn3fM=",
        "re2_label_fix.patch": "sha256-<compute-after-creating-file>"
    },
    "patch_strip": 1
}

3. patches/bazel_9_fixes.patch

Copy the existing patch from BCR (same content as BCR's 1.2.1.bcr.2):

diff --git a/bazel/protobuf.bzl b/bazel/protobuf.bzl
index 08d9d56..d131bd6 100644
--- a/bazel/protobuf.bzl
+++ b/bazel/protobuf.bzl
@@ -1,6 +1,8 @@
 load("@bazel_skylib//rules:common_settings.bzl", "BuildSettingInfo")
-load("@bazel_tools//tools/jdk:toolchain_utils.bzl", "find_java_runtime_toolchain", "find_java_toolchain")
-load("@rules_proto//proto:defs.bzl", "ProtoInfo")
+load("@bazel_tools//tools/jdk:toolchain_utils.bzl", "find_java_toolchain")
+load("@com_google_protobuf//bazel/common:proto_info.bzl", "ProtoInfo")
+load("@rules_java//java/common:java_common.bzl", "java_common")
+load("@rules_java//java/common:java_info.bzl", "JavaInfo")
 
 # Borrowed from https://github.com/grpc/grpc-java/blob/v1.28.0/java_grpc_library.bzl#L59
 # "repository" here is for Bazel builds that span multiple WORKSPACES.
@@ -110,13 +112,13 @@ cc_proto_gen_validate = rule(
             default = [Label("@com_googlesource_code_re2//:re2")],
         ),
         "_protoc": attr.label(
-            cfg = "host",
+            cfg = "exec",
             default = Label("@com_google_protobuf//:protoc"),
             executable = True,
             allow_single_file = True,
         ),
         "_plugin": attr.label(
-            cfg = "host",
+            cfg = "exec",
             default = Label("@com_envoyproxy_protoc_gen_validate//:protoc-gen-validate"),
          ...

</details>



<!-- START COPILOT CODING AGENT SUFFIX -->

*This pull request was created from Copilot chat.*
>

<!-- START COPILOT CODING AGENT TIPS -->
---

💬 We'd love your input! Share your thoughts on Copilot coding agent in our [2 minute survey](https://gh.io/copilot-coding-agent-survey).

@netlify
Copy link

netlify bot commented Feb 2, 2026

Deploy Preview for nifty-bassi-e26446 ready!

Name Link
🔨 Latest commit 21e2208
🔍 Latest deploy log https://app.netlify.com/projects/nifty-bassi-e26446/deploys/6981a10fa940a700083c6f78
😎 Deploy Preview https://deploy-preview-3684--nifty-bassi-e26446.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

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