Skip to content

Commit 3d4acde

Browse files
committed
Fix Protobuf version mismatch by disabling Bzlmod and moving toolchain registration
1 parent 3673f16 commit 3d4acde

4 files changed

Lines changed: 245 additions & 7 deletions

File tree

.bazelrc

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,12 @@ build:macos --cxxopt=-D_GLIBCXX_USE_CXX11_ABI=1
4343
# Disable sframe in assembler to avoid linker errors with gcc 15
4444
build:linux --copt=-Wa,--gsframe=no
4545

46-
47-
48-
49-
5046
# Suppress all warning messages.
5147
build:short_logs --output_filter=DONT_MATCH_ANYTHING
5248

5349
build:macos --macos_minimum_os=10.12
50+
51+
common --noenable_bzlmod
52+
53+
test --noincompatible_check_sharding_support
54+

WORKSPACE

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,10 +119,14 @@ http_archive(
119119
urls = [
120120
"https://github.com/protocolbuffers/protobuf/archive/refs/tags/v6.31.1.zip",
121121
],
122-
patches = ["//third_party:protobuf_retain_options.patch"],
122+
patches = ["//third_party:protobuf_tensorflow.patch"],
123123
patch_args = ["-p1"],
124124
)
125125

126+
register_toolchains(
127+
"@com_google_protobuf//bazel/private/toolchains:cc_source_toolchain_bazel7",
128+
)
129+
126130
# ===== TensorFlow dependency =====
127131
#
128132
# TensorFlow is imported here instead of in tf_serving_workspace() because
Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
--- a/bazel/private/proto_library_rule.bzl
2-
+++ b/b/bazel/private/proto_library_rule.bzl
3-
@@ -166,4 +166,3 @@
2+
+++ b/bazel/private/proto_library_rule.bzl
3+
@@ -165,5 +165,4 @@
4+
args = ctx.actions.args()
5+
46
if ctx.attr._experimental_proto_descriptor_sets_include_source_info[BuildSettingInfo].value:
57
args.add("--include_source_info")
68
- args.add("--retain_options")
Lines changed: 231 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,231 @@
1+
diff --git a/BUILD.bazel b/BUILD.bazel
2+
--- a/BUILD.bazel
3+
+++ b/BUILD.bazel
4+
@@ -555,7 +555,8 @@ proto_lang_toolchain(
5+
"//:cpp_features_proto",
6+
"//:descriptor_proto",
7+
],
8+
- command_line = "--cpp_out=$(OUT)",
9+
+ command_line = "--cpp_out=dllexport_decl=PROTOBUF_EXPORT:$(OUT)",
10+
+ protoc_minimal_do_not_use = "//:protoc",
11+
runtime = "//src/google/protobuf",
12+
visibility = ["//visibility:public"],
13+
)
14+
diff --git a/build_defs/BUILD.bazel b/build_defs/BUILD.bazel
15+
--- a/build_defs/BUILD.bazel
16+
+++ b/build_defs/BUILD.bazel
17+
@@ -1,6 +1,7 @@
18+
# Internal Starlark definitions for Protobuf.
19+
20+
load("@bazel_skylib//lib:selects.bzl", "selects")
21+
+load("@bazel_skylib//rules:common_settings.bzl", "bool_flag")
22+
load("@rules_pkg//pkg:mappings.bzl", "pkg_files", "strip_prefix")
23+
load("//bazel:cc_proto_library.bzl", starlark_cc_proto_library = "cc_proto_library")
24+
load(":cc_proto_blacklist_test.bzl", "cc_proto_blacklist_test")
25+
@@ -13,6 +14,20 @@ package(
26+
],
27+
)
28+
29+
+bool_flag(
30+
+ name = "use_dlls",
31+
+ build_setting_default = False,
32+
+ visibility = ["//visibility:public"],
33+
+)
34+
+
35+
+config_setting(
36+
+ name = "config_use_dlls",
37+
+ flag_values = {
38+
+ ":use_dlls": "True",
39+
+ },
40+
+ visibility = ["//visibility:public"],
41+
+)
42+
+
43+
create_compiler_config_setting(
44+
name = "config_msvc_cl",
45+
value = "msvc-cl",
46+
diff --git a/python/dist/system_python.bzl b/python/dist/system_python.bzl
47+
--- a/python/dist/system_python.bzl
48+
+++ b/python/dist/system_python.bzl
49+
@@ -73,11 +73,10 @@ load("@bazel_skylib//lib:selects.bzl", "selects")
50+
load("@bazel_skylib//rules:common_settings.bzl", "string_flag")
51+
load("@bazel_tools//tools/python:toolchain.bzl", "py_runtime_pair")
52+
53+
-cc_library(
54+
- name = "python_headers",
55+
- hdrs = glob(["python/**/*.h"], allow_empty = True),
56+
- includes = ["python"],
57+
- visibility = ["//visibility:public"],
58+
+alias(
59+
+ name = "python_headers",
60+
+ actual = "@rules_python//python/cc:current_py_cc_headers",
61+
+ visibility = ["//visibility:public"],
62+
)
63+
64+
string_flag(
65+
@@ -219,7 +218,7 @@ def _system_python_impl(repository_ctx):
66+
python3 = repository_ctx.which("python3")
67+
python_version = _get_python_version(repository_ctx)
68+
69+
- if path and python_version[0] == "3":
70+
+ if False:
71+
_populate_package(repository_ctx, path, python3, python_version)
72+
else:
73+
# buildifier: disable=print
74+
diff --git a/python/google/protobuf/__init__.py b/python/google/protobuf/__init__.py
75+
--- a/python/google/protobuf/__init__.py
76+
+++ b/python/google/protobuf/__init__.py
77+
@@ -8,3 +8,9 @@
78+
# Copyright 2007 Google Inc. All Rights Reserved.
79+
80+
__version__ = '6.31.1'
81+
+
82+
+if __name__ != '__main__':
83+
+ try:
84+
+ __import__('pkg_resources').declare_namespace(__name__)
85+
+ except ImportError:
86+
+ __path__ = __import__('pkgutil').extend_path(__path__, __name__)
87+
diff --git a/src/google/protobuf/BUILD.bazel b/src/google/protobuf/BUILD.bazel
88+
--- a/src/google/protobuf/BUILD.bazel
89+
+++ b/src/google/protobuf/BUILD.bazel
90+
@@ -525,6 +525,13 @@ cc_library(
91+
"serial_arena.h",
92+
"thread_safe_arena.h",
93+
],
94+
+ local_defines = select({
95+
+ "//build_defs:config_use_dlls": [
96+
+ "PROTOBUF_USE_DLLS",
97+
+ "LIBPROTOBUF_EXPORTS",
98+
+ ],
99+
+ "//conditions:default": [],
100+
+ }),
101+
strip_include_prefix = "/src",
102+
visibility = [
103+
"//:__subpackages__",
104+
@@ -657,7 +664,15 @@ cc_library(
105+
"serial_arena.h",
106+
"thread_safe_arena.h",
107+
"wire_format_lite.h",
108+
+ "port.h",
109+
],
110+
+ local_defines = select({
111+
+ "//build_defs:config_use_dlls": [
112+
+ "PROTOBUF_USE_DLLS",
113+
+ "LIBPROTOBUF_EXPORTS",
114+
+ ],
115+
+ "//conditions:default": [],
116+
+ }),
117+
copts = COPTS + select({
118+
"//build_defs:config_msvc": [],
119+
"//conditions:default": [
120+
@@ -767,6 +782,13 @@ cc_library(
121+
],
122+
hdrs = PROTOBUF_HEADERS,
123+
copts = COPTS,
124+
+ local_defines = select({
125+
+ "//build_defs:config_use_dlls": [
126+
+ "PROTOBUF_USE_DLLS",
127+
+ "LIBPROTOBUF_EXPORTS",
128+
+ ],
129+
+ "//conditions:default": [],
130+
+ }),
131+
linkopts = LINK_OPTS,
132+
strip_include_prefix = "/src",
133+
visibility = [
134+
diff --git a/src/google/protobuf/arena.cc b/src/google/protobuf/arena.cc
135+
--- a/src/google/protobuf/arena.cc
136+
+++ b/src/google/protobuf/arena.cc
137+
@@ -547,7 +547,7 @@ ThreadSafeArena::ThreadCache& ThreadSafeArena::thread_cache() {
138+
new internal::ThreadLocalStorage<ThreadCache>();
139+
return *thread_cache_->Get();
140+
}
141+
-#elif defined(PROTOBUF_USE_DLLS) && defined(_WIN32)
142+
+#elif defined(_WIN32)
143+
ThreadSafeArena::ThreadCache& ThreadSafeArena::thread_cache() {
144+
static PROTOBUF_THREAD_LOCAL ThreadCache thread_cache;
145+
return thread_cache;
146+
diff --git a/src/google/protobuf/io/BUILD.bazel b/src/google/protobuf/io/BUILD.bazel
147+
--- a/src/google/protobuf/io/BUILD.bazel
148+
+++ b/src/google/protobuf/io/BUILD.bazel
149+
@@ -22,6 +22,13 @@ cc_library(
150+
"zero_copy_stream_impl.h",
151+
"zero_copy_stream_impl_lite.h",
152+
],
153+
+ local_defines = select({
154+
+ "//build_defs:config_use_dlls": [
155+
+ "PROTOBUF_USE_DLLS",
156+
+ "LIBPROTOBUF_EXPORTS",
157+
+ ],
158+
+ "//conditions:default": [],
159+
+ }),
160+
copts = COPTS,
161+
strip_include_prefix = "/src",
162+
deps = [
163+
diff --git a/src/google/protobuf/port_def.inc b/src/google/protobuf/port_def.inc
164+
--- a/src/google/protobuf/port_def.inc
165+
+++ b/src/google/protobuf/port_def.inc
166+
@@ -421,7 +421,7 @@ static_assert(PROTOBUF_ABSL_MIN(20230125, 3),
167+
#endif
168+
169+
// Lexan sets both MSV_VER and clang, so handle it with the clang path.
170+
-#if defined(_MSC_VER) && !defined(__clang__)
171+
+#if defined(_MSC_VER)
172+
// MSVC 17 currently seems to raise an error about constant-initialized pointers.
173+
# if PROTOBUF_MSC_VER_MIN(1930)
174+
# define PROTOBUF_CONSTINIT
175+
diff --git a/src/google/protobuf/thread_safe_arena.h b/src/google/protobuf/thread_safe_arena.h
176+
--- a/src/google/protobuf/thread_safe_arena.h
177+
+++ b/src/google/protobuf/thread_safe_arena.h
178+
@@ -249,7 +249,7 @@ class PROTOBUF_EXPORT ThreadSafeArena {
179+
// iOS does not support __thread keyword so we use a custom thread local
180+
// storage class we implemented.
181+
static ThreadCache& thread_cache();
182+
-#elif defined(PROTOBUF_USE_DLLS) && defined(_WIN32)
183+
+#elif defined(_WIN32)
184+
// Thread local variables cannot be exposed through MSVC DLL interface but we
185+
// can wrap them in static functions.
186+
static ThreadCache& thread_cache();
187+
diff --git a/src/google/protobuf/port_def.inc b/src/google/protobuf/port_def.inc
188+
--- a/src/google/protobuf/port_def.inc
189+
+++ b/src/google/protobuf/port_def.inc
190+
@@ -196,5 +196,14 @@
191+
#else
192+
#define PROTOBUF_ALWAYS_INLINE_CALL
193+
#endif
194+
+
195+
+#define PROTOBUF_NAMESPACE "google::protobuf"
196+
+#define PROTOBUF_NAMESPACE_ID google::protobuf
197+
+#define PROTOBUF_NAMESPACE_OPEN \
198+
+ namespace google { \
199+
+ namespace protobuf {
200+
+#define PROTOBUF_NAMESPACE_CLOSE \
201+
+ } /* namespace protobuf */ \
202+
+ } /* namespace google */
203+
204+
#ifdef PROTOBUF_NDEBUG_INLINE
205+
206+
diff --git a/src/google/protobuf/BUILD.bazel b/src/google/protobuf/BUILD.bazel
207+
--- a/src/google/protobuf/BUILD.bazel
208+
+++ b/src/google/protobuf/BUILD.bazel
209+
@@ -295,7 +295,7 @@ cc_library(
210+
includes = ["wkt"],
211+
linkopts = LINK_OPTS,
212+
strip_include_prefix = "/src",
213+
- visibility = ["//pkg:__pkg__"],
214+
+ visibility = ["//visibility:public"],
215+
deps = [
216+
":port",
217+
":protobuf",
218+
diff --git a/src/google/protobuf/util/BUILD.bazel b/src/google/protobuf/util/BUILD.bazel
219+
--- a/src/google/protobuf/util/BUILD.bazel
220+
+++ b/src/google/protobuf/util/BUILD.bazel
221+
@@ -170,9 +170,8 @@ cc_library(
222+
],
223+
deps = [
224+
"//src/google/protobuf",
225+
- "//src/google/protobuf:duration_cc_proto",
226+
+ "//src/google/protobuf:cmake_wkt_cc_proto",
227+
"//src/google/protobuf:port",
228+
- "//src/google/protobuf:timestamp_cc_proto",
229+
"//src/google/protobuf/stubs",
230+
"@abseil-cpp//absl/log:absl_check",
231+
"@abseil-cpp//absl/numeric:int128",

0 commit comments

Comments
 (0)