Skip to content

Commit 43e1aff

Browse files
habermancopybara-github
authored andcommitted
Remove ODR violation from WKT codegen (#12406)
Closes #12406 COPYBARA_INTEGRATE_REVIEW=#12406 from mkruskal-google:wkt 1c6748e FUTURE_COPYBARA_INTEGRATE_REVIEW=#12406 from mkruskal-google:wkt 1c6748e PiperOrigin-RevId: 522407931
1 parent 6038e9b commit 43e1aff

File tree

7 files changed

+49
-41
lines changed

7 files changed

+49
-41
lines changed

BUILD.bazel

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ proto_lang_toolchain(
322322
"//:descriptor_proto",
323323
],
324324
command_line = "--cpp_out=$(OUT)",
325-
runtime = ":protobuf",
325+
runtime = "//src/google/protobuf:protobuf_nowkt",
326326
visibility = ["//visibility:public"],
327327
)
328328

conformance/BUILD.bazel

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,9 @@ cc_library(
139139
deps = [
140140
":conformance_cc_proto",
141141
"//src/google/protobuf:descriptor_legacy",
142+
"//src/google/protobuf/util:differencer",
143+
"//src/google/protobuf/util:json_util",
144+
"//src/google/protobuf/util:type_resolver_util",
142145
"@com_google_absl//absl/strings",
143146
"@com_google_absl//absl/strings:str_format",
144147
],

examples/BUILD.bazel

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,19 @@ cc_proto_library(
3636
cc_binary(
3737
name = "add_person_cpp",
3838
srcs = ["add_person.cc"],
39-
deps = [":addressbook_cc_proto"],
39+
deps = [
40+
":addressbook_cc_proto",
41+
"@com_google_protobuf//:protobuf",
42+
],
4043
)
4144

4245
cc_binary(
4346
name = "list_people_cpp",
4447
srcs = ["list_people.cc"],
45-
deps = [":addressbook_cc_proto"],
48+
deps = [
49+
":addressbook_cc_proto",
50+
"@com_google_protobuf//:protobuf",
51+
],
4652
)
4753

4854
# Similar to cc_proto_library but for Java.

pkg/BUILD.bazel

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ cc_dist_library(
163163
deps = [
164164
"//src/google/protobuf:arena_align",
165165
"//src/google/protobuf:protobuf_nowkt",
166-
"//src/google/protobuf:wkt_cc_proto",
166+
"//src/google/protobuf:cmake_wkt_cc_proto",
167167
"//src/google/protobuf/compiler:importer",
168168
"//src/google/protobuf/json",
169169
"//src/google/protobuf/util:delimited_message_util",
@@ -200,7 +200,7 @@ cc_dist_library(
200200
testonly = 1,
201201
tags = ["manual"],
202202
deps = ["//src/google/protobuf:lite_test_util"],
203-
dist_deps = [":protobuf_lite"],
203+
dist_deps = [":protobuf"],
204204
)
205205

206206
cc_dist_library(

src/google/protobuf/BUILD.bazel

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,18 @@ WELL_KNOWN_TYPES = [
107107
"wrappers",
108108
]
109109

110+
proto_library(
111+
name = "wkt_proto",
112+
visibility = ["//visibility:private"],
113+
deps = [wkt + "_proto" for wkt in WELL_KNOWN_TYPES],
114+
)
115+
116+
cc_proto_library(
117+
name = "wkt_cc_proto",
118+
visibility = ["//pkg:__pkg__"],
119+
deps = ["wkt_proto"],
120+
)
121+
110122
# When we generate code for the well-known types, we put the resulting files in
111123
# wkt/google/protobuf and add ./wkt to the include paths below. This is a
112124
# somewhat strange setup but is necessary to satisfy these two constraints:
@@ -121,12 +133,12 @@ genrule(
121133
["wkt/google/protobuf/" + wkt + ".pb.h" for wkt in WELL_KNOWN_TYPES] +
122134
["wkt/google/protobuf/" + wkt + ".pb.cc" for wkt in WELL_KNOWN_TYPES],
123135
cmd = """
124-
$(execpath //src/google/protobuf/compiler:protoc_nowkt) \
136+
$(execpath //:protoc) \
125137
--cpp_out=dllexport_decl=PROTOBUF_EXPORT:$(RULEDIR)/wkt \
126138
--proto_path=$$(dirname $$(dirname $$(dirname $(location any.proto)))) \
127139
$(SRCS)
128140
""",
129-
exec_tools = ["//src/google/protobuf/compiler:protoc_nowkt"],
141+
exec_tools = ["//:protoc"],
130142
visibility = ["//visibility:private"],
131143
)
132144

@@ -139,8 +151,11 @@ staleness_test(
139151
tags = ["manual"],
140152
)
141153

154+
# This is necessary for our generated cmake configs to pick up the checked in
155+
# WKT files.
156+
# TODO(b/246826624) Remove this once we generate WKT code from cmake.
142157
cc_library(
143-
name = "wkt_cc_proto",
158+
name = "cmake_wkt_cc_proto",
144159
srcs = ["wkt/google/protobuf/" + wkt + ".pb.cc" for wkt in WELL_KNOWN_TYPES],
145160
hdrs = ["wkt/google/protobuf/" + wkt + ".pb.h" for wkt in WELL_KNOWN_TYPES],
146161
copts = COPTS,
@@ -466,6 +481,7 @@ cc_library(
466481
include_prefix = "google/protobuf",
467482
linkopts = LINK_OPTS,
468483
visibility = [
484+
"//:__pkg__",
469485
"//pkg:__pkg__",
470486
"//src/google/protobuf:__subpackages__",
471487
],
@@ -841,6 +857,7 @@ cc_library(
841857
visibility = ["//:__subpackages__"],
842858
deps = [
843859
"//src/google/protobuf/io",
860+
"//src/google/protobuf/util:differencer",
844861
"@com_google_googletest//:gtest",
845862
],
846863
)
@@ -993,9 +1010,11 @@ cc_test(
9931010
":cc_test_protos",
9941011
":protobuf",
9951012
":test_util",
1013+
":test_util2",
9961014
"//src/google/protobuf/io",
9971015
"//src/google/protobuf/stubs",
9981016
"//src/google/protobuf/testing",
1017+
"//src/google/protobuf/util:differencer",
9991018
"@com_google_googletest//:gtest",
10001019
"@com_google_googletest//:gtest_main",
10011020
],
@@ -1115,6 +1134,9 @@ cc_test(
11151134
":cc_test_protos",
11161135
":protobuf",
11171136
":test_util",
1137+
":test_util2",
1138+
"//src/google/protobuf/util:differencer",
1139+
"//src/google/protobuf/util:time_util",
11181140
"@com_google_absl//absl/container:flat_hash_map",
11191141
"@com_google_absl//absl/container:flat_hash_set",
11201142
"@com_google_googletest//:gtest",
@@ -1136,6 +1158,7 @@ cc_test(
11361158
"//src/google/protobuf/io",
11371159
"//src/google/protobuf/stubs",
11381160
"//src/google/protobuf/testing",
1161+
"//src/google/protobuf/util:differencer",
11391162
"@com_google_absl//absl/log:scoped_mock_log",
11401163
"@com_google_googletest//:gtest",
11411164
"@com_google_googletest//:gtest_main",
@@ -1294,6 +1317,7 @@ cc_test(
12941317
"//src/google/protobuf/io",
12951318
"//src/google/protobuf/stubs",
12961319
"//src/google/protobuf/testing",
1320+
"@com_google_absl//absl/log:die_if_null",
12971321
"@com_google_absl//absl/log:scoped_mock_log",
12981322
"@com_google_googletest//:gtest",
12991323
"@com_google_googletest//:gtest_main",
@@ -1356,6 +1380,7 @@ cc_test(
13561380
"//src/google/protobuf/io",
13571381
"//src/google/protobuf/stubs",
13581382
"//src/google/protobuf/testing",
1383+
"//src/google/protobuf/util:differencer",
13591384
"@com_google_absl//absl/log:scoped_mock_log",
13601385
"@com_google_googletest//:gtest",
13611386
"@com_google_googletest//:gtest_main",
@@ -1368,7 +1393,9 @@ cc_test(
13681393
deps = [
13691394
":cc_test_protos",
13701395
":protobuf",
1396+
"//src/google/protobuf/compiler:importer",
13711397
"//src/google/protobuf/compiler:retention",
1398+
"//src/google/protobuf/util:differencer",
13721399
"@com_google_googletest//:gtest_main",
13731400
],
13741401
)

src/google/protobuf/compiler/BUILD.bazel

Lines changed: 5 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -102,11 +102,15 @@ cc_library(
102102
)
103103

104104
cc_library(
105-
name = "protoc_lib_nowkt",
105+
name = "protoc_lib",
106106
srcs = [
107107
"main.cc",
108108
],
109109
copts = COPTS,
110+
visibility = [
111+
"//:__pkg__",
112+
"//pkg:__pkg__",
113+
],
110114
deps = [
111115
":code_generator",
112116
":command_line_interface",
@@ -124,29 +128,6 @@ cc_library(
124128
],
125129
)
126130

127-
cc_binary(
128-
name = "protoc_nowkt",
129-
copts = COPTS,
130-
linkopts = LINK_OPTS,
131-
visibility = [
132-
"//src/google/protobuf:__pkg__",
133-
],
134-
deps = [":protoc_lib_nowkt"],
135-
)
136-
137-
cc_library(
138-
name = "protoc_lib",
139-
copts = COPTS,
140-
visibility = [
141-
"//:__pkg__",
142-
"//pkg:__pkg__",
143-
],
144-
deps = [
145-
":protoc_lib_nowkt",
146-
"//:protobuf",
147-
],
148-
)
149-
150131
# Note: this is an alias for now. In the future, this rule will become the
151132
# cc_binary for protoc, and //:protoc will become an alias.
152133
alias(

src/google/protobuf/util/BUILD.bazel

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -214,15 +214,6 @@ proto_library(
214214
testonly = 1,
215215
srcs = ["json_format.proto"],
216216
strip_import_prefix = "/src",
217-
deps = [
218-
"//:any_proto",
219-
"//:duration_proto",
220-
"//:field_mask_proto",
221-
"//:struct_proto",
222-
"//:test_protos",
223-
"//:timestamp_proto",
224-
"//:wrappers_proto",
225-
],
226217
)
227218

228219
cc_proto_library(

0 commit comments

Comments
 (0)