xref: /aosp_15_r20/external/tflite-support/third_party/com_google_protobuf_fixes.diff (revision b16991f985baa50654c05c5adbb3c8bbcfb40082)
1diff --git a/BUILD b/BUILD
2index 79871d621..51b3a063f 100644
3--- a/BUILD
4+++ b/BUILD
5@@ -26,7 +26,7 @@ config_setting(
6 # ZLIB configuration
7 ################################################################################
8
9-ZLIB_DEPS = ["@zlib//:zlib"]
10+ZLIB_DEPS = ["@zlib"]
11
12 ################################################################################
13 # Protobuf Runtime Library
14@@ -157,6 +157,7 @@ cc_library(
15     includes = ["src/"],
16     linkopts = LINK_OPTS,
17     visibility = ["//visibility:public"],
18+    alwayslink = 1,
19 )
20
21 PROTOBUF_DEPS = select({
22@@ -230,6 +231,7 @@ cc_library(
23     linkopts = LINK_OPTS,
24     visibility = ["//visibility:public"],
25     deps = [":protobuf_lite"] + PROTOBUF_DEPS,
26+    alwayslink = 1,
27 )
28
29 # This provides just the header files for use in projects that need to build
30@@ -318,13 +320,13 @@ cc_proto_library(
31
32 [native_cc_proto_library(
33     name = proto + "_cc_proto",
34-    deps = [proto + "_proto"],
35     visibility = ["//visibility:private"],
36+    deps = [proto + "_proto"],
37 ) for proto in WELL_KNOWN_PROTO_MAP.keys()]
38
39 cc_proto_blacklist_test(
40     name = "cc_proto_blacklist_test",
41-    deps = [proto + "_cc_proto" for proto in WELL_KNOWN_PROTO_MAP.keys()]
42+    deps = [proto + "_cc_proto" for proto in WELL_KNOWN_PROTO_MAP.keys()],
43 )
44
45 ################################################################################
46@@ -900,7 +902,6 @@ py_proto_library(
47     py_extra_srcs = glob(["python/**/__init__.py"]),
48     py_libs = [
49         ":python_srcs",
50-        "@six//:six",
51     ],
52     srcs_version = "PY2AND3",
53     visibility = ["//visibility:public"],
54@@ -1002,7 +1003,9 @@ cc_library(
55 # Note: We use `native_proto_common` here because we depend on an implementation-detail of
56 # `proto_lang_toolchain`, which may not be available on `proto_common`.
57 reject_blacklisted_files = hasattr(native_proto_common, "proto_lang_toolchain_rejects_files_do_not_use_or_we_will_break_you_without_mercy")
58+
59 cc_toolchain_blacklisted_protos = [proto + "_proto" for proto in WELL_KNOWN_PROTO_MAP.keys()] if reject_blacklisted_files else [":well_known_protos"]
60+
61 proto_lang_toolchain(
62     name = "cc_toolchain",
63     blacklisted_protos = cc_toolchain_blacklisted_protos,
64diff --git a/protobuf.bzl b/protobuf.bzl
65index 829464d44..4ac23594b 100644
66--- a/protobuf.bzl
67+++ b/protobuf.bzl
68@@ -87,6 +87,8 @@ def _proto_gen_impl(ctx):
69     for dep in ctx.attr.deps:
70         import_flags += dep.proto.import_flags
71         deps += dep.proto.deps
72+    import_flags = depset(import_flags).to_list()
73+    deps = depset(deps).to_list()
74
75     if not ctx.attr.gen_cc and not ctx.attr.gen_py and not ctx.executable.plugin:
76         return struct(
77diff --git a/src/google/protobuf/io/gzip_stream.h b/src/google/protobuf/io/gzip_stream.h
78index b1ce1d36c..d5d560ea7 100644
79--- a/src/google/protobuf/io/gzip_stream.h
80+++ b/src/google/protobuf/io/gzip_stream.h
81@@ -47,10 +47,12 @@
82 #include <google/protobuf/stubs/common.h>
83 #include <google/protobuf/io/zero_copy_stream.h>
84 #include <google/protobuf/port.h>
85-#include <zlib.h>
86-
87 #include <google/protobuf/port_def.inc>
88
89+#if HAVE_ZLIB
90+#include <zlib.h>
91+#endif  // HAVE_ZLIB
92+
93 namespace google {
94 namespace protobuf {
95 namespace io {
96@@ -76,8 +78,10 @@ class PROTOBUF_EXPORT GzipInputStream : public ZeroCopyInputStream {
97   virtual ~GzipInputStream();
98
99   // Return last error message or NULL if no error.
100+#if HAVE_ZLIB
101   inline const char* ZlibErrorMessage() const { return zcontext_.msg; }
102   inline int ZlibErrorCode() const { return zerror_; }
103+#endif  // HAVE_ZLIB
104
105   // implements ZeroCopyInputStream ----------------------------------
106   bool Next(const void** data, int* size);
107@@ -90,8 +94,10 @@ class PROTOBUF_EXPORT GzipInputStream : public ZeroCopyInputStream {
108
109   ZeroCopyInputStream* sub_stream_;
110
111+ #if HAVE_ZLIB
112   z_stream zcontext_;
113   int zerror_;
114+ #endif // HAVE_ZLIB
115
116   void* output_buffer_;
117   void* output_position_;
118@@ -142,9 +148,11 @@ class PROTOBUF_EXPORT GzipOutputStream : public ZeroCopyOutputStream {
119
120   virtual ~GzipOutputStream();
121
122+#if HAVE_ZLIB
123   // Return last error message or NULL if no error.
124   inline const char* ZlibErrorMessage() const { return zcontext_.msg; }
125   inline int ZlibErrorCode() const { return zerror_; }
126+#endif  // HAVE_ZLIB
127
128   // Flushes data written so far to zipped data in the underlying stream.
129   // It is the caller's responsibility to flush the underlying stream if
130@@ -177,8 +185,10 @@ class PROTOBUF_EXPORT GzipOutputStream : public ZeroCopyOutputStream {
131   void* sub_data_;
132   int sub_data_size_;
133
134+#if HAVE_ZLIB
135   z_stream zcontext_;
136   int zerror_;
137+#endif  //HAVE_ZLIB
138   void* input_buffer_;
139   size_t input_buffer_length_;
140
141