diff --git a/bazel/protobuf.patch b/bazel/protobuf.patch new file mode 100644 index 0000000000..ddf57eb69a --- /dev/null +++ b/bazel/protobuf.patch @@ -0,0 +1,10 @@ +--- BUILD ++++ BUILD +@@ -1110,6 +1110,7 @@ py_library( + ":python_common_test_protos", + ":python_specific_test_protos", + ], ++ visibility = ["//visibility:public"], + ) + + internal_protobuf_py_tests( diff --git a/bazel/workspace_deps.bzl b/bazel/workspace_deps.bzl index 0f47720c08..f825cf9c66 100644 --- a/bazel/workspace_deps.bzl +++ b/bazel/workspace_deps.bzl @@ -19,6 +19,14 @@ def upb_deps(): "https://mirror.bazel.build/github.com/protocolbuffers/protobuf/archive/v3.19.1.tar.gz", "https://github.com/protocolbuffers/protobuf/archive/v3.19.1.tar.gz", ], + patches = [ + "//bazel:protobuf.patch", + ], + patch_cmds = [ + "rm python/google/protobuf/__init__.py", + "rm python/google/protobuf/pyext/__init__.py", + "rm python/google/protobuf/internal/__init__.py", + ] ) maybe( diff --git a/python/BUILD b/python/BUILD index 68cd74a790..a00b0d00ba 100644 --- a/python/BUILD +++ b/python/BUILD @@ -93,10 +93,28 @@ genrule( cmd = "cp $< $@", ) +genrule( + name = "api_implementation_ext", + srcs = [":api_implementation"], + outs = ["google/protobuf/internal/_api_implementation" + EXT_SUFFIX], + cmd = "cp $< $@", +) + py_test( name = "minimal_test", - srcs = ["minimal_test.py"], - data = [":message_ext"], + #srcs = ["minimal_test.py"], + srcs = [ + "minimal_test.py", + "@com_google_protobuf//:python_tests", + ], + deps = [ + "@com_google_protobuf//:python_tests", + ], + data = [ + "@com_google_protobuf//:python_tests", + ":message_ext", + ":api_implementation_ext", + ], imports = ["."], legacy_create_init = False, ) diff --git a/python/message.c b/python/message.c index 728b1163d2..e486fde65b 100644 --- a/python/message.c +++ b/python/message.c @@ -332,7 +332,7 @@ static bool PyUpb_CMessage_InitMapAttribute(PyObject* _self, PyObject* name, return ok >= 0; } -static bool PyUpb_CMessage_InitRepeatedAttribute() { +static bool PyUpb_CMessage_InitRepeatedAttribute(void) { // TODO(haberman): disabled until repeated container is in. // PyObject* repeated = PyUpb_CMessage_GetAttr(_self, name); // PyObject* tmp = PyUpb_RepeatedContainer_Extend(repeated, value); @@ -1537,7 +1537,7 @@ static PyType_Spec PyUpb_MessageMeta_Spec = { PyUpb_MessageMeta_Slots, }; -static PyObject* PyUpb_MessageMeta_CreateType() { +static PyObject* PyUpb_MessageMeta_CreateType(void) { PyObject* bases = Py_BuildValue("(O)", &PyType_Type); if (!bases) return NULL; PyUpb_MessageMeta_Spec.basicsize = diff --git a/python/minimal_test.py b/python/minimal_test.py index 13f1124f30..32b83338f6 100644 --- a/python/minimal_test.py +++ b/python/minimal_test.py @@ -29,6 +29,7 @@ import unittest from google.protobuf.pyext import _message +from google.protobuf.internal import api_implementation class TestMessageExtension(unittest.TestCase): @@ -48,9 +49,11 @@ class TestMessageExtension(unittest.TestCase): def test_lib_is_upb(self): # Ensure we are not pulling in a different protobuf library on the # system. + print(_message._IS_UPB) self.assertTrue(_message._IS_UPB) + self.assertEqual(api_implementation.Type(), "cpp") -TestMessageExtension.test_descriptor_pool.__unittest_expecting_failure__ = True +#TestMessageExtension.test_descriptor_pool.__unittest_expecting_failure__ = True if __name__ == '__main__': diff --git a/python/protobuf.c b/python/protobuf.c index afe92c6401..09b1552db9 100644 --- a/python/protobuf.c +++ b/python/protobuf.c @@ -288,7 +288,8 @@ PyMODINIT_FUNC PyInit__message(void) { state->obj_cache = PyUpb_WeakMap_New(); if (!PyUpb_InitDescriptorContainers(m) || !PyUpb_InitDescriptorPool(m) || - !PyUpb_InitDescriptor(m) || !PyUpb_InitArena(m)) { + !PyUpb_InitDescriptor(m) || !PyUpb_InitArena(m) || + !PyUpb_InitMessage(m)) { Py_DECREF(m); return NULL; }