Skip to content

Commit

Permalink
core: apply protobuf patch to prevent duplicate symbols (#618)
Browse files Browse the repository at this point in the history
Fixes #617, which resulted in duplicate symbols from protobuf being present in the final Envoy Mobile binary.

The [root cause](bazelbuild/bazel#10484) is being [patched in Bazel](bazelbuild/bazel#10493). In the meantime, we can revert these two commits in protobuf ([first](protocolbuffers/protobuf@7b28278), [second](protocolbuffers/protobuf@a03d332)) and apply the diff as a patch until we're able to update Bazel with the fix. More context on the protobuf issue is available [here](protocolbuffers/protobuf#7046).

Notes:
- This should be reverted after updating Bazel with the fix
- The version of protobuf specified in the `http_archive` should be in lockstep with upstream Envoy's version
- Upstream Envoy's `@envoy//bazel:protobuf.patch` patch is also included here

Signed-off-by: Michael Rebello <me@michaelrebello.com>
  • Loading branch information
rebello95 committed Dec 31, 2019
1 parent d27f0de commit 3052a69
Show file tree
Hide file tree
Showing 2 changed files with 108 additions and 0 deletions.
15 changes: 15 additions & 0 deletions WORKSPACE
@@ -1,5 +1,20 @@
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive", "http_file", "http_jar")

# Patch protobuf to prevent duplicate symbols: https://github.com/lyft/envoy-mobile/issues/617
# More details: https://github.com/protocolbuffers/protobuf/issues/7046
# TODO: Remove after https://github.com/bazelbuild/bazel/pull/10493 is merged to Bazel
# Reverts:
# - https://github.com/protocolbuffers/protobuf/commit/7b28278c7d4f4175e70aef2f89d304696eb85ae3
# - https://github.com/protocolbuffers/protobuf/commit/a03d332aca5d33c5d4b2cd25037c9e37d57eff02
http_archive(
name = "com_google_protobuf",
patch_args = ["-p1"],
patches = ["@envoy//bazel:protobuf.patch", "//bazel:protobuf.patch"],
sha256 = "d7cfd31620a352b2ee8c1ed883222a0d77e44346643458e062e86b1d069ace3e",
strip_prefix = "protobuf-3.10.1",
urls = ["https://github.com/protocolbuffers/protobuf/releases/download/v3.10.1/protobuf-all-3.10.1.tar.gz"],
)

# Patch upstream Abseil to prevent Foundation dependency from leaking into Android builds.
# Workaround for https://github.com/abseil/abseil-cpp/issues/326.
# TODO: Should be removed in https://github.com/lyft/envoy-mobile/issues/136 once rules_android
Expand Down
93 changes: 93 additions & 0 deletions bazel/protobuf.patch
@@ -0,0 +1,93 @@
diff --git a/BUILD b/BUILD
index efc3d8e7f..425eb15d5 100644
--- a/BUILD
+++ b/BUILD
@@ -247,36 +247,38 @@ cc_library(
# Map of all well known protos.
# name => (include path, imports)
WELL_KNOWN_PROTO_MAP = {
- "any": ("src/google/protobuf/any.proto", []),
+ "any": ("google/protobuf/any.proto", []),
"api": (
- "src/google/protobuf/api.proto",
+ "google/protobuf/api.proto",
[
"source_context",
"type",
],
),
"compiler_plugin": (
- "src/google/protobuf/compiler/plugin.proto",
+ "google/protobuf/compiler/plugin.proto",
["descriptor"],
),
- "descriptor": ("src/google/protobuf/descriptor.proto", []),
- "duration": ("src/google/protobuf/duration.proto", []),
- "empty": ("src/google/protobuf/empty.proto", []),
- "field_mask": ("src/google/protobuf/field_mask.proto", []),
- "source_context": ("src/google/protobuf/source_context.proto", []),
- "struct": ("src/google/protobuf/struct.proto", []),
- "timestamp": ("src/google/protobuf/timestamp.proto", []),
+ "descriptor": ("google/protobuf/descriptor.proto", []),
+ "duration": ("google/protobuf/duration.proto", []),
+ "empty": ("google/protobuf/empty.proto", []),
+ "field_mask": ("google/protobuf/field_mask.proto", []),
+ "source_context": ("google/protobuf/source_context.proto", []),
+ "struct": ("google/protobuf/struct.proto", []),
+ "timestamp": ("google/protobuf/timestamp.proto", []),
"type": (
- "src/google/protobuf/type.proto",
+ "google/protobuf/type.proto",
[
"any",
"source_context",
],
),
- "wrappers": ("src/google/protobuf/wrappers.proto", []),
+ "wrappers": ("google/protobuf/wrappers.proto", []),
}

-WELL_KNOWN_PROTOS = [value[0] for value in WELL_KNOWN_PROTO_MAP.values()]
+RELATIVE_WELL_KNOWN_PROTOS = [proto[1][0] for proto in WELL_KNOWN_PROTO_MAP.items()]
+
+WELL_KNOWN_PROTOS = ["src/" + s for s in RELATIVE_WELL_KNOWN_PROTOS]

filegroup(
name = "well_known_protos",
@@ -306,10 +308,17 @@ cc_proto_library(
# )
################################################################################

+internal_copied_filegroup(
+ name = "_internal_wkt_protos",
+ srcs = WELL_KNOWN_PROTOS,
+ dest = "",
+ strip_prefix = "src",
+ visibility = ["//visibility:private"],
+)
+
[proto_library(
name = proto[0] + "_proto",
srcs = [proto[1][0]],
- strip_import_prefix = "src",
visibility = ["//visibility:public"],
deps = [dep + "_proto" for dep in proto[1][1]],
) for proto in WELL_KNOWN_PROTO_MAP.items()]
@@ -869,7 +878,7 @@ internal_copied_filegroup(

# TODO(dzc): Remove this once py_proto_library can have labels in srcs, in
# which case we can simply add :protos_python in srcs.
-COPIED_WELL_KNOWN_PROTOS = ["python/" + s[4:] for s in WELL_KNOWN_PROTOS]
+COPIED_WELL_KNOWN_PROTOS = ["python/" + s for s in RELATIVE_WELL_KNOWN_PROTOS]

py_proto_library(
name = "protobuf_python",
@@ -988,7 +997,7 @@ cc_library(

proto_lang_toolchain(
name = "cc_toolchain",
- blacklisted_protos = [proto + "_proto" for proto in WELL_KNOWN_PROTO_MAP.keys()],
+ blacklisted_protos = [":_internal_wkt_protos_genrule"],
command_line = "--cpp_out=$(OUT)",
runtime = ":protobuf",
visibility = ["//visibility:public"],

0 comments on commit 3052a69

Please sign in to comment.