1diff --git a/BUILD b/BUILD 2index dbae719ff..4e276c854 100644 3--- a/BUILD 4+++ b/BUILD 5@@ -23,7 +23,7 @@ config_setting( 6 # ZLIB configuration 7 ################################################################################ 8 9-ZLIB_DEPS = ["@zlib//:zlib"] 10+ZLIB_DEPS = ["@zlib"] 11 12 ################################################################################ 13 # Protobuf Runtime Library 14@@ -100,6 +100,7 @@ LINK_OPTS = select({ 15 16 load( 17 ":protobuf.bzl", 18+ "adapt_proto_library", 19 "cc_proto_library", 20 "py_proto_library", 21 "internal_copied_filegroup", 22@@ -143,6 +144,7 @@ cc_library( 23 copts = COPTS, 24 includes = ["src/"], 25 linkopts = LINK_OPTS, 26+ alwayslink = 1, 27 visibility = ["//visibility:public"], 28 ) 29 30@@ -213,6 +215,7 @@ cc_library( 31 copts = COPTS, 32 includes = ["src/"], 33 linkopts = LINK_OPTS, 34+ alwayslink = 1, 35 visibility = ["//visibility:public"], 36 deps = [":protobuf_lite"] + PROTOBUF_DEPS, 37 ) 38@@ -255,13 +258,15 @@ filegroup( 39 visibility = ["//visibility:public"], 40 ) 41 42-cc_proto_library( 43+adapt_proto_library( 44+ name = "cc_wkt_protos_genproto", 45+ deps = [proto + "_proto" for proto in WELL_KNOWN_PROTO_MAP.keys()], 46+ visibility = ["//visibility:public"], 47+) 48+ 49+cc_library( 50 name = "cc_wkt_protos", 51- srcs = WELL_KNOWN_PROTOS, 52- include = "src", 53- default_runtime = ":protobuf", 54- internal_bootstrap_hack = 1, 55- protoc = ":protoc", 56+ deprecation = "Only for backward compatibility. Do not use.", 57 visibility = ["//visibility:public"], 58 ) 59 60@@ -978,10 +983,10 @@ cc_library( 61 62 proto_lang_toolchain( 63 name = "cc_toolchain", 64+ blacklisted_protos = [proto + "_proto" for proto in WELL_KNOWN_PROTO_MAP.keys()], 65 command_line = "--cpp_out=$(OUT)", 66 runtime = ":protobuf", 67 visibility = ["//visibility:public"], 68- blacklisted_protos = [":_internal_wkt_protos_genrule"], 69 ) 70 71 proto_lang_toolchain( 72diff --git a/protobuf.bzl b/protobuf.bzl 73index e0653321f..4156a1275 100644 74--- a/protobuf.bzl 75+++ b/protobuf.bzl 76@@ -1,4 +1,5 @@ 77 load("@bazel_skylib//lib:versions.bzl", "versions") 78+load("@rules_proto//proto:defs.bzl", "ProtoInfo") 79 80 def _GetPath(ctx, path): 81 if ctx.label.workspace_root: 82@@ -85,6 +86,8 @@ def _proto_gen_impl(ctx): 83 for dep in ctx.attr.deps: 84 import_flags += dep.proto.import_flags 85 deps += dep.proto.deps 86+ import_flags = depset(import_flags).to_list() 87+ deps = depset(deps).to_list() 88 89 if not ctx.attr.gen_cc and not ctx.attr.gen_py and not ctx.executable.plugin: 90 return struct( 91@@ -222,6 +225,29 @@ Args: 92 outs: a list of labels of the expected outputs from the protocol compiler. 93 """ 94 95+def _adapt_proto_library_impl(ctx): 96+ deps = [dep[ProtoInfo] for dep in ctx.attr.deps] 97+ 98+ srcs = [src for dep in deps for src in dep.direct_sources] 99+ return struct( 100+ proto = struct( 101+ srcs = srcs, 102+ import_flags = ["-I{}".format(path) for dep in deps for path in dep.transitive_proto_path.to_list()], 103+ deps = srcs, 104+ ), 105+ ) 106+ 107+adapt_proto_library = rule( 108+ implementation = _adapt_proto_library_impl, 109+ attrs = { 110+ "deps": attr.label_list( 111+ mandatory = True, 112+ providers = [ProtoInfo], 113+ ), 114+ }, 115+ doc = "Adapts `proto_library` from `@rules_proto` to be used with `{cc,py}_proto_library` from this file.", 116+) 117+ 118 def cc_proto_library( 119 name, 120 srcs = [], 121@@ -229,7 +255,6 @@ def cc_proto_library( 122 cc_libs = [], 123 include = None, 124 protoc = "@com_google_protobuf//:protoc", 125- internal_bootstrap_hack = False, 126 use_grpc_plugin = False, 127 default_runtime = "@com_google_protobuf//:protobuf", 128 **kargs): 129@@ -247,41 +272,17 @@ def cc_proto_library( 130 cc_library. 131 include: a string indicating the include path of the .proto files. 132 protoc: the label of the protocol compiler to generate the sources. 133- internal_bootstrap_hack: a flag indicate the cc_proto_library is used only 134- for bootstraping. When it is set to True, no files will be generated. 135- The rule will simply be a provider for .proto files, so that other 136- cc_proto_library can depend on it. 137 use_grpc_plugin: a flag to indicate whether to call the grpc C++ plugin 138 when processing the proto files. 139 default_runtime: the implicitly default runtime which will be depended on by 140 the generated cc_library target. 141 **kargs: other keyword arguments that are passed to cc_library. 142- 143 """ 144 145 includes = [] 146 if include != None: 147 includes = [include] 148 149- if internal_bootstrap_hack: 150- # For pre-checked-in generated files, we add the internal_bootstrap_hack 151- # which will skip the codegen action. 152- proto_gen( 153- name = name + "_genproto", 154- srcs = srcs, 155- deps = [s + "_genproto" for s in deps], 156- includes = includes, 157- protoc = protoc, 158- visibility = ["//visibility:public"], 159- ) 160- 161- # An empty cc_library to make rule dependency consistent. 162- native.cc_library( 163- name = name, 164- **kargs 165- ) 166- return 167- 168 grpc_cpp_plugin = None 169 if use_grpc_plugin: 170 grpc_cpp_plugin = "//external:grpc_cpp_plugin" 171diff --git a/python/google/protobuf/pyext/message.cc b/python/google/protobuf/pyext/message.cc 172index 3530a9b37..c31fa8fcc 100644 173--- a/python/google/protobuf/pyext/message.cc 174+++ b/python/google/protobuf/pyext/message.cc 175@@ -2991,8 +2991,12 @@ bool InitProto2MessageModule(PyObject *m) { 176 reinterpret_cast<PyObject*>( 177 &RepeatedCompositeContainer_Type)); 178 179- // Register them as collections.Sequence 180+ // Register them as MutableSequence. 181+#if PY_MAJOR_VERSION >= 3 182+ ScopedPyObjectPtr collections(PyImport_ImportModule("collections.abc")); 183+#else 184 ScopedPyObjectPtr collections(PyImport_ImportModule("collections")); 185+#endif 186 if (collections == NULL) { 187 return false; 188 } 189diff --git a/python/google/protobuf/pyext/unknown_fields.cc b/python/google/protobuf/pyext/unknown_fields.cc 190index c3679c0d3..e80a1d97a 100755 191--- a/python/google/protobuf/pyext/unknown_fields.cc 192+++ b/python/google/protobuf/pyext/unknown_fields.cc 193@@ -221,7 +221,7 @@ const UnknownField* GetUnknownField(PyUnknownFieldRef* self) { 194 "The parent message might be cleared."); 195 return NULL; 196 } 197- ssize_t total_size = fields->field_count(); 198+ Py_ssize_t total_size = fields->field_count(); 199 if (self->index >= total_size) { 200 PyErr_Format(PyExc_ValueError, 201 "UnknownField does not exist. " 202