From 271b874e53c82e4382ce7953b5cf5b250dc3b68d Mon Sep 17 00:00:00 2001 From: Michael Rebello Date: Mon, 30 Dec 2019 18:24:11 -0800 Subject: [PATCH 1/6] core: apply protobuf patch to prevent duplicate symbols Signed-off-by: Michael Rebello --- WORKSPACE | 14 +++++++ bazel/protobuf_1.patch | 13 +++++++ bazel/protobuf_2.patch | 84 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 111 insertions(+) create mode 100644 bazel/protobuf_1.patch create mode 100644 bazel/protobuf_2.patch diff --git a/WORKSPACE b/WORKSPACE index ff779454c7..3c29d1d06a 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -170,6 +170,20 @@ grpc_java_repositories( omit_net_zlib = True, ) +# Apply patches to protobuf to prevent duplicate symbols: https://github.com/lyft/envoy-mobile/issues/617. +# TODO: Remove after https://github.com/bazelbuild/bazel/pull/10493 is merged to Bazel and we upgrade. +http_archive( + name = "com_google_protobuf", + patches = ["//bazel:protobuf1.patch", "//bazel:protobuf2.patch"], + sha256 = "3df786d47a813a2912f0fcdd79c2bc49be123a8c37949e45dbb16bcec4883b11", + strip_prefix = "boringssl-6263268b8c1b78a8a9b65acd6f5dd5c04dd9b0e1", + urls = ["https://github.com/protocolbuffers/protobuf/archive/6263268b8c1b78a8a9b65acd6f5dd5c04dd9b0e1.tar.gz"], +) + +load("@com_google_protobuf//:protobuf_deps.bzl", "protobuf_deps") + +protobuf_deps() + http_archive( name = "rules_proto_grpc", sha256 = "1e08cd6c61f893417b14930ca342950f5f22f71f929a38a8c4bbfeae2a80d03e", diff --git a/bazel/protobuf_1.patch b/bazel/protobuf_1.patch new file mode 100644 index 0000000000..2ddb8380b1 --- /dev/null +++ b/bazel/protobuf_1.patch @@ -0,0 +1,13 @@ +diff --git a/BUILD b/BUILD +index 78e5906f50..6665de94d4 100644 +--- a/BUILD ++++ b/BUILD +@@ -1012,7 +1012,7 @@ cc_library( + + proto_lang_toolchain( + name = "cc_toolchain", +- blacklisted_protos = [":_internal_wkt_protos_genrule"], ++ blacklisted_protos = [proto + "_proto" for proto in WELL_KNOWN_PROTO_MAP.keys()], + command_line = "--cpp_out=$(OUT)", + runtime = ":protobuf", + visibility = ["//visibility:public"], diff --git a/bazel/protobuf_2.patch b/bazel/protobuf_2.patch new file mode 100644 index 0000000000..1e0d094573 --- /dev/null +++ b/bazel/protobuf_2.patch @@ -0,0 +1,84 @@ +diff --git a/BUILD b/BUILD +index 93b948ce36..e531c6847a 100644 +--- a/BUILD ++++ b/BUILD +@@ -242,38 +242,36 @@ cc_library( + # Map of all well known protos. + # name => (include path, imports) + WELL_KNOWN_PROTO_MAP = { +- "any": ("google/protobuf/any.proto", []), ++ "any": ("src/google/protobuf/any.proto", []), + "api": ( +- "google/protobuf/api.proto", ++ "src/google/protobuf/api.proto", + [ + "source_context", + "type", + ], + ), + "compiler_plugin": ( +- "google/protobuf/compiler/plugin.proto", ++ "src/google/protobuf/compiler/plugin.proto", + ["descriptor"], + ), +- "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", []), ++ "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", []), + "type": ( +- "google/protobuf/type.proto", ++ "src/google/protobuf/type.proto", + [ + "any", + "source_context", + ], + ), +- "wrappers": ("google/protobuf/wrappers.proto", []), ++ "wrappers": ("src/google/protobuf/wrappers.proto", []), + } + +-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] ++WELL_KNOWN_PROTOS = [value[0] for value in WELL_KNOWN_PROTO_MAP.values()] + + filegroup( + name = "well_known_protos", +@@ -303,17 +301,10 @@ 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()] +@@ -893,7 +884,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 for s in RELATIVE_WELL_KNOWN_PROTOS] ++COPIED_WELL_KNOWN_PROTOS = ["python/" + s[4:] for s in WELL_KNOWN_PROTOS] + + py_proto_library( + name = "protobuf_python", From ac834a792f67c17fb802442e29eaa8e8c5a234ce Mon Sep 17 00:00:00 2001 From: Michael Rebello Date: Mon, 30 Dec 2019 18:37:14 -0800 Subject: [PATCH 2/6] Update WORKSPACE Signed-off-by: Michael Rebello --- WORKSPACE | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/WORKSPACE b/WORKSPACE index 3c29d1d06a..3523c195d8 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -1,5 +1,16 @@ load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive", "http_file", "http_jar") +# Apply patches to 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 and we upgrade. +http_archive( + name = "com_google_protobuf", + patches = ["//bazel:protobuf_1.patch", "//bazel:protobuf_2.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 @@ -170,20 +181,6 @@ grpc_java_repositories( omit_net_zlib = True, ) -# Apply patches to protobuf to prevent duplicate symbols: https://github.com/lyft/envoy-mobile/issues/617. -# TODO: Remove after https://github.com/bazelbuild/bazel/pull/10493 is merged to Bazel and we upgrade. -http_archive( - name = "com_google_protobuf", - patches = ["//bazel:protobuf1.patch", "//bazel:protobuf2.patch"], - sha256 = "3df786d47a813a2912f0fcdd79c2bc49be123a8c37949e45dbb16bcec4883b11", - strip_prefix = "boringssl-6263268b8c1b78a8a9b65acd6f5dd5c04dd9b0e1", - urls = ["https://github.com/protocolbuffers/protobuf/archive/6263268b8c1b78a8a9b65acd6f5dd5c04dd9b0e1.tar.gz"], -) - -load("@com_google_protobuf//:protobuf_deps.bzl", "protobuf_deps") - -protobuf_deps() - http_archive( name = "rules_proto_grpc", sha256 = "1e08cd6c61f893417b14930ca342950f5f22f71f929a38a8c4bbfeae2a80d03e", From aeddf33ad12740432b2d5160f1af039f6e3e2f7e Mon Sep 17 00:00:00 2001 From: Michael Rebello Date: Mon, 30 Dec 2019 21:38:17 -0800 Subject: [PATCH 3/6] fixes Signed-off-by: Michael Rebello --- WORKSPACE | 3 +- bazel/protobuf.patch | 93 ++++++++++++++++++++++++++++++++++++++++++ bazel/protobuf_1.patch | 13 ------ bazel/protobuf_2.patch | 84 -------------------------------------- 4 files changed, 95 insertions(+), 98 deletions(-) create mode 100644 bazel/protobuf.patch delete mode 100644 bazel/protobuf_1.patch delete mode 100644 bazel/protobuf_2.patch diff --git a/WORKSPACE b/WORKSPACE index 3523c195d8..d84257ebed 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -5,7 +5,8 @@ load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive", "http_file" # TODO: Remove after https://github.com/bazelbuild/bazel/pull/10493 is merged to Bazel and we upgrade. http_archive( name = "com_google_protobuf", - patches = ["//bazel:protobuf_1.patch", "//bazel:protobuf_2.patch"], + patch_args = ["-p1"], + patches = ["//bazel:protobuf.patch", "@envoy//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"], diff --git a/bazel/protobuf.patch b/bazel/protobuf.patch new file mode 100644 index 0000000000..c7ac9902f8 --- /dev/null +++ b/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"], diff --git a/bazel/protobuf_1.patch b/bazel/protobuf_1.patch deleted file mode 100644 index 2ddb8380b1..0000000000 --- a/bazel/protobuf_1.patch +++ /dev/null @@ -1,13 +0,0 @@ -diff --git a/BUILD b/BUILD -index 78e5906f50..6665de94d4 100644 ---- a/BUILD -+++ b/BUILD -@@ -1012,7 +1012,7 @@ cc_library( - - proto_lang_toolchain( - name = "cc_toolchain", -- blacklisted_protos = [":_internal_wkt_protos_genrule"], -+ blacklisted_protos = [proto + "_proto" for proto in WELL_KNOWN_PROTO_MAP.keys()], - command_line = "--cpp_out=$(OUT)", - runtime = ":protobuf", - visibility = ["//visibility:public"], diff --git a/bazel/protobuf_2.patch b/bazel/protobuf_2.patch deleted file mode 100644 index 1e0d094573..0000000000 --- a/bazel/protobuf_2.patch +++ /dev/null @@ -1,84 +0,0 @@ -diff --git a/BUILD b/BUILD -index 93b948ce36..e531c6847a 100644 ---- a/BUILD -+++ b/BUILD -@@ -242,38 +242,36 @@ cc_library( - # Map of all well known protos. - # name => (include path, imports) - WELL_KNOWN_PROTO_MAP = { -- "any": ("google/protobuf/any.proto", []), -+ "any": ("src/google/protobuf/any.proto", []), - "api": ( -- "google/protobuf/api.proto", -+ "src/google/protobuf/api.proto", - [ - "source_context", - "type", - ], - ), - "compiler_plugin": ( -- "google/protobuf/compiler/plugin.proto", -+ "src/google/protobuf/compiler/plugin.proto", - ["descriptor"], - ), -- "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", []), -+ "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", []), - "type": ( -- "google/protobuf/type.proto", -+ "src/google/protobuf/type.proto", - [ - "any", - "source_context", - ], - ), -- "wrappers": ("google/protobuf/wrappers.proto", []), -+ "wrappers": ("src/google/protobuf/wrappers.proto", []), - } - --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] -+WELL_KNOWN_PROTOS = [value[0] for value in WELL_KNOWN_PROTO_MAP.values()] - - filegroup( - name = "well_known_protos", -@@ -303,17 +301,10 @@ 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()] -@@ -893,7 +884,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 for s in RELATIVE_WELL_KNOWN_PROTOS] -+COPIED_WELL_KNOWN_PROTOS = ["python/" + s[4:] for s in WELL_KNOWN_PROTOS] - - py_proto_library( - name = "protobuf_python", From c7045716be4ea8babb9640d21145ebc8061174ea Mon Sep 17 00:00:00 2001 From: Michael Rebello Date: Mon, 30 Dec 2019 21:38:43 -0800 Subject: [PATCH 4/6] Update WORKSPACE Signed-off-by: Michael Rebello --- WORKSPACE | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/WORKSPACE b/WORKSPACE index d84257ebed..0a6e4b2781 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -6,7 +6,7 @@ load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive", "http_file" http_archive( name = "com_google_protobuf", patch_args = ["-p1"], - patches = ["//bazel:protobuf.patch", "@envoy//bazel:protobuf.patch"], + 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"], From 5ccd780622bd40f22fbc9b51523ad2887f130a19 Mon Sep 17 00:00:00 2001 From: Michael Rebello Date: Mon, 30 Dec 2019 21:57:52 -0800 Subject: [PATCH 5/6] docs Signed-off-by: Michael Rebello --- WORKSPACE | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/WORKSPACE b/WORKSPACE index 0a6e4b2781..0fff2303a6 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -1,8 +1,11 @@ load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive", "http_file", "http_jar") -# Apply patches to 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 and we upgrade. +# 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"], From e4e0ee59a8a7c141f20a950176d128b71c7410c3 Mon Sep 17 00:00:00 2001 From: Michael Rebello Date: Mon, 30 Dec 2019 22:01:42 -0800 Subject: [PATCH 6/6] Update protobuf.patch Signed-off-by: Michael Rebello --- bazel/protobuf.patch | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/bazel/protobuf.patch b/bazel/protobuf.patch index c7ac9902f8..649f9263d3 100644 --- a/bazel/protobuf.patch +++ b/bazel/protobuf.patch @@ -46,18 +46,18 @@ index efc3d8e7f..425eb15d5 100644 - "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, @@ -74,16 +74,16 @@ index efc3d8e7f..425eb15d5 100644 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()],