Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Jan 29, 2026

Protobuf's gzip_stream target hardcodes @zlib, causing header conflicts when Envoy uses @zlib-ng (GCC fails with ZLIB_VERSION redefinition under -Werror).

Changes

Created custom protobuf module at bazel-registry/modules/protobuf/33.4.envoy/:

  • MODULE.bazel: Based on BCR protobuf 33.4, version set to 33.4.envoy
  • patches/envoy.patch:
    • Adds label_flag for configurable zlib dependency (//:zlib)
    • Changes src/google/protobuf/io/BUILD.bazel from @zlib to //:zlib
    • Includes existing Envoy protobuf changes (protoc renaming, platform configs, warning suppressions)
  • source.json: References protobuf 33.4 release with patch SHA256
  • metadata.json: Module metadata

Usage

In Envoy's .bazelrc:

build --@protobuf//:zlib=@zlib-ng//:zlib-ng

The label_flag defaults to @zlib for backward compatibility but allows external override to any zlib implementation.

Original prompt

Problem

Envoy uses zlib-ng instead of standard zlib. Protobuf's gzip_stream target hardcodes @zlib as a dependency, which causes header conflicts when both @zlib and @zlib-ng headers end up in the same compilation unit (GCC fails with ZLIB_VERSION redefinition error due to -Werror).

Solution

Create a new module at bazel-registry/modules/protobuf/33.4.envoy/ that adds a label_flag for zlib so it can be configured externally.

Files to create

bazel-registry/modules/protobuf/33.4.envoy/
├── MODULE.bazel
├── source.json
└── patches/
    └── envoy.patch

Implementation Details

source.json

{
    "integrity": "sha256-aH6YpHGXO1xf1xF1DEC4uCwK3jP2Sdtl4AspDyk0Wis=",
    "strip_prefix": "protobuf-33.4",
    "url": "https://github.com/protocolbuffers/protobuf/releases/download/v33.4/protobuf-33.4.bazel.tar.gz",
    "patches": {
        "patches/envoy.patch": "sha256-CALCULATE_AFTER_CREATING_PATCH"
    },
    "patch_strip": 1
}

The integrity hash is from BCR's protobuf 33.4.

MODULE.bazel

Copy from BCR's protobuf 33.4 MODULE.bazel but:

  • Change version to "33.4.envoy"
  • Keep all essential bazel_dep entries including zlib
  • Can omit dev_dependency sections (ruby, rust, python dev toolchains) to reduce complexity

patches/envoy.patch

CRITICAL: To create this patch correctly, you must:

  1. Download/checkout the protobuf 33.4 source
  2. Make the required changes to the files
  3. Generate the patch using diff -ruN or git diff
  4. Clean up the checkout
  5. Verify the patch applies cleanly

The patch must include these changes:

1. Root BUILD.bazel - Add label_flag for zlib:

Add at the top (after existing loads):

load("@bazel_skylib//rules:common_settings.bzl", "label_flag")

Add the label_flag target:

label_flag(
    name = "zlib",
    build_setting_default = "@zlib",
    visibility = ["//visibility:public"],
)

2. Root BUILD.bazel - Existing Envoy changes:

Reference the existing patch from envoyproxy/envoy at bazel/protobuf.patch for:

  • Renaming protoc cc_binary to compiled_protoc
  • Adding platform config_settings (linux-aarch_64, linux-x86_64, osx-aarch_64, osx-x86_64, windows-x86_64)
  • Adding protoc alias with select for prebuilt protoc binaries
  • Adding protobuf_python_genproto alias

3. build_defs/cpp_opts.bzl - Add warning suppression:

Add to COPTS:

"-Wno-deprecated-declarations",

4. src/google/protobuf/io/BUILD.bazel - Use the label_flag:

Change the zlib dependency from:

"//conditions:default": ["@zlib"],

To:

"//conditions:default": ["//:zlib"],

This is the critical change that allows external configuration of which zlib to use.

Reference

The existing Envoy protobuf patch is at: https://github.com/envoyproxy/envoy/blob/main/bazel/protobuf.patch

Usage (for context, not part of this PR)

In Envoy's .bazelrc:

build --@protobuf//:zlib=@zlib-ng//:zlib-ng

Important Notes

  1. DO NOT invent SHA256 hashes - Calculate the patch hash after creating the patch file
  2. The patch must apply cleanly to protobuf 33.4 - Download the source and verify
  3. The label_flag requires bazel_skylib - Ensure the load statement is added
  4. Test the patch applies - After creating, apply it to a clean checkout to verify

This pull request was created from Copilot chat.


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

@netlify
Copy link

netlify bot commented Jan 29, 2026

Deploy Preview for nifty-bassi-e26446 ready!

Name Link
🔨 Latest commit ae70c30
🔍 Latest deploy log https://app.netlify.com/projects/nifty-bassi-e26446/deploys/697baa029677c2000855d735
😎 Deploy Preview https://deploy-preview-3660--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.

Copilot AI changed the title [WIP] Add protobuf module to configure zlib dependency Add protobuf 33.4.envoy module with configurable zlib dependency Jan 29, 2026
Copilot AI requested a review from phlax January 29, 2026 11:35
Signed-off-by: Ryan Northey <ryan@synca.io>
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