Skip to content

Commit 5ddb1fc

Browse files
Remove ODR violation from WKT codegen (#12406) (#12419)
* Remove ODR violation from WKT codegen (#12406) Closes #12406 COPYBARA_INTEGRATE_REVIEW=#12406 from mkruskal-google:wkt 1c6748e PiperOrigin-RevId: 522418175 * Removed legacy target. --------- Co-authored-by: Mike Kruskal <[email protected]>
1 parent f1c7820 commit 5ddb1fc

File tree

8 files changed

+49
-44
lines changed

8 files changed

+49
-44
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
@@ -138,6 +138,9 @@ cc_library(
138138
includes = ["."],
139139
deps = [
140140
":conformance_cc_proto",
141+
"//src/google/protobuf/util:differencer",
142+
"//src/google/protobuf/util:json_util",
143+
"//src/google/protobuf/util:type_resolver_util",
141144
"@com_google_absl//absl/strings",
142145
"@com_google_absl//absl/strings:str_format",
143146
],

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
@@ -380,7 +380,7 @@ cc_dist_library(
380380
deps = [
381381
"//src/google/protobuf:arena_align",
382382
"//src/google/protobuf:protobuf_nowkt",
383-
"//src/google/protobuf:wkt_cc_proto",
383+
"//src/google/protobuf:cmake_wkt_cc_proto",
384384
"//src/google/protobuf/compiler:importer",
385385
"//src/google/protobuf/json",
386386
"//src/google/protobuf/util:delimited_message_util",
@@ -416,7 +416,7 @@ cc_dist_library(
416416
testonly = 1,
417417
tags = ["manual"],
418418
deps = ["//src/google/protobuf:lite_test_util"],
419-
dist_deps = [":protobuf_lite"],
419+
dist_deps = [":protobuf"],
420420
)
421421

422422
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,
@@ -425,6 +440,7 @@ cc_library(
425440
include_prefix = "google/protobuf",
426441
linkopts = LINK_OPTS,
427442
visibility = [
443+
"//:__pkg__",
428444
"//pkg:__pkg__",
429445
"//src/google/protobuf:__subpackages__",
430446
],
@@ -784,6 +800,7 @@ cc_library(
784800
visibility = ["//:__subpackages__"],
785801
deps = [
786802
"//src/google/protobuf/io",
803+
"//src/google/protobuf/util:differencer",
787804
"@com_google_googletest//:gtest",
788805
],
789806
)
@@ -935,9 +952,11 @@ cc_test(
935952
":cc_test_protos",
936953
":protobuf",
937954
":test_util",
955+
":test_util2",
938956
"//src/google/protobuf/io",
939957
"//src/google/protobuf/stubs",
940958
"//src/google/protobuf/testing",
959+
"//src/google/protobuf/util:differencer",
941960
"@com_google_googletest//:gtest",
942961
"@com_google_googletest//:gtest_main",
943962
],
@@ -1057,6 +1076,9 @@ cc_test(
10571076
":cc_test_protos",
10581077
":protobuf",
10591078
":test_util",
1079+
":test_util2",
1080+
"//src/google/protobuf/util:differencer",
1081+
"//src/google/protobuf/util:time_util",
10601082
"@com_google_absl//absl/container:flat_hash_map",
10611083
"@com_google_absl//absl/container:flat_hash_set",
10621084
"@com_google_googletest//:gtest",
@@ -1078,6 +1100,7 @@ cc_test(
10781100
"//src/google/protobuf/io",
10791101
"//src/google/protobuf/stubs",
10801102
"//src/google/protobuf/testing",
1103+
"//src/google/protobuf/util:differencer",
10811104
"@com_google_absl//absl/log:scoped_mock_log",
10821105
"@com_google_googletest//:gtest",
10831106
"@com_google_googletest//:gtest_main",
@@ -1235,6 +1258,7 @@ cc_test(
12351258
"//src/google/protobuf/io",
12361259
"//src/google/protobuf/stubs",
12371260
"//src/google/protobuf/testing",
1261+
"@com_google_absl//absl/log:die_if_null",
12381262
"@com_google_absl//absl/log:scoped_mock_log",
12391263
"@com_google_googletest//:gtest",
12401264
"@com_google_googletest//:gtest_main",
@@ -1296,6 +1320,7 @@ cc_test(
12961320
"//src/google/protobuf/io",
12971321
"//src/google/protobuf/stubs",
12981322
"//src/google/protobuf/testing",
1323+
"//src/google/protobuf/util:differencer",
12991324
"@com_google_absl//absl/log:scoped_mock_log",
13001325
"@com_google_googletest//:gtest",
13011326
"@com_google_googletest//:gtest_main",
@@ -1308,7 +1333,9 @@ cc_test(
13081333
deps = [
13091334
":cc_test_protos",
13101335
":protobuf",
1336+
"//src/google/protobuf/compiler:importer",
13111337
"//src/google/protobuf/compiler:retention",
1338+
"//src/google/protobuf/util:differencer",
13121339
"@com_google_googletest//:gtest_main",
13131340
],
13141341
)

src/google/protobuf/compiler/BUILD.bazel

Lines changed: 5 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -99,11 +99,15 @@ cc_library(
9999
)
100100

101101
cc_library(
102-
name = "protoc_lib_nowkt",
102+
name = "protoc_lib",
103103
srcs = [
104104
"main.cc",
105105
],
106106
copts = COPTS,
107+
visibility = [
108+
"//:__pkg__",
109+
"//pkg:__pkg__",
110+
],
107111
deps = [
108112
":code_generator",
109113
":command_line_interface",
@@ -120,29 +124,6 @@ cc_library(
120124
],
121125
)
122126

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

src/google/protobuf/util/BUILD.bazel

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

227218
cc_proto_library(

src/google/protobuf/util/json_format.proto

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,6 @@ syntax = "proto2";
3838

3939
package protobuf_unittest;
4040

41-
import "google/protobuf/any.proto";
42-
import "google/protobuf/struct.proto";
43-
4441
message TestFlagsAndStrings {
4542
required int32 A = 1;
4643
repeated group RepeatedGroup = 2 {

0 commit comments

Comments
 (0)