Remove ODR violation from WKT codegen (#12406)

Closes #12406

COPYBARA_INTEGRATE_REVIEW=https://github.com/protocolbuffers/protobuf/pull/12406 from mkruskal-google:wkt 1c6748e6aa
PiperOrigin-RevId: 522418175
pull/12420/head
Mike Kruskal 2 years ago committed by Copybara-Service
parent 6038e9b9fe
commit f51923041d
  1. 2
      BUILD.bazel
  2. 3
      conformance/BUILD.bazel
  3. 10
      examples/BUILD.bazel
  4. 4
      pkg/BUILD.bazel
  5. 33
      src/google/protobuf/BUILD.bazel
  6. 29
      src/google/protobuf/compiler/BUILD.bazel
  7. 9
      src/google/protobuf/util/BUILD.bazel
  8. 3
      src/google/protobuf/util/json_format.proto

@ -322,7 +322,7 @@ proto_lang_toolchain(
"//:descriptor_proto", "//:descriptor_proto",
], ],
command_line = "--cpp_out=$(OUT)", command_line = "--cpp_out=$(OUT)",
runtime = ":protobuf", runtime = "//src/google/protobuf:protobuf_nowkt",
visibility = ["//visibility:public"], visibility = ["//visibility:public"],
) )

@ -139,6 +139,9 @@ cc_library(
deps = [ deps = [
":conformance_cc_proto", ":conformance_cc_proto",
"//src/google/protobuf:descriptor_legacy", "//src/google/protobuf:descriptor_legacy",
"//src/google/protobuf/util:differencer",
"//src/google/protobuf/util:json_util",
"//src/google/protobuf/util:type_resolver_util",
"@com_google_absl//absl/strings", "@com_google_absl//absl/strings",
"@com_google_absl//absl/strings:str_format", "@com_google_absl//absl/strings:str_format",
], ],

@ -36,13 +36,19 @@ cc_proto_library(
cc_binary( cc_binary(
name = "add_person_cpp", name = "add_person_cpp",
srcs = ["add_person.cc"], srcs = ["add_person.cc"],
deps = [":addressbook_cc_proto"], deps = [
":addressbook_cc_proto",
"@com_google_protobuf//:protobuf",
],
) )
cc_binary( cc_binary(
name = "list_people_cpp", name = "list_people_cpp",
srcs = ["list_people.cc"], srcs = ["list_people.cc"],
deps = [":addressbook_cc_proto"], deps = [
":addressbook_cc_proto",
"@com_google_protobuf//:protobuf",
],
) )
# Similar to cc_proto_library but for Java. # Similar to cc_proto_library but for Java.

@ -163,7 +163,7 @@ cc_dist_library(
deps = [ deps = [
"//src/google/protobuf:arena_align", "//src/google/protobuf:arena_align",
"//src/google/protobuf:protobuf_nowkt", "//src/google/protobuf:protobuf_nowkt",
"//src/google/protobuf:wkt_cc_proto", "//src/google/protobuf:cmake_wkt_cc_proto",
"//src/google/protobuf/compiler:importer", "//src/google/protobuf/compiler:importer",
"//src/google/protobuf/json", "//src/google/protobuf/json",
"//src/google/protobuf/util:delimited_message_util", "//src/google/protobuf/util:delimited_message_util",
@ -200,7 +200,7 @@ cc_dist_library(
testonly = 1, testonly = 1,
tags = ["manual"], tags = ["manual"],
deps = ["//src/google/protobuf:lite_test_util"], deps = ["//src/google/protobuf:lite_test_util"],
dist_deps = [":protobuf_lite"], dist_deps = [":protobuf"],
) )
cc_dist_library( cc_dist_library(

@ -107,6 +107,18 @@ WELL_KNOWN_TYPES = [
"wrappers", "wrappers",
] ]
proto_library(
name = "wkt_proto",
visibility = ["//visibility:private"],
deps = [wkt + "_proto" for wkt in WELL_KNOWN_TYPES],
)
cc_proto_library(
name = "wkt_cc_proto",
visibility = ["//pkg:__pkg__"],
deps = ["wkt_proto"],
)
# When we generate code for the well-known types, we put the resulting files in # When we generate code for the well-known types, we put the resulting files in
# wkt/google/protobuf and add ./wkt to the include paths below. This is a # wkt/google/protobuf and add ./wkt to the include paths below. This is a
# somewhat strange setup but is necessary to satisfy these two constraints: # somewhat strange setup but is necessary to satisfy these two constraints:
@ -121,12 +133,12 @@ genrule(
["wkt/google/protobuf/" + wkt + ".pb.h" for wkt in WELL_KNOWN_TYPES] + ["wkt/google/protobuf/" + wkt + ".pb.h" for wkt in WELL_KNOWN_TYPES] +
["wkt/google/protobuf/" + wkt + ".pb.cc" for wkt in WELL_KNOWN_TYPES], ["wkt/google/protobuf/" + wkt + ".pb.cc" for wkt in WELL_KNOWN_TYPES],
cmd = """ cmd = """
$(execpath //src/google/protobuf/compiler:protoc_nowkt) \ $(execpath //:protoc) \
--cpp_out=dllexport_decl=PROTOBUF_EXPORT:$(RULEDIR)/wkt \ --cpp_out=dllexport_decl=PROTOBUF_EXPORT:$(RULEDIR)/wkt \
--proto_path=$$(dirname $$(dirname $$(dirname $(location any.proto)))) \ --proto_path=$$(dirname $$(dirname $$(dirname $(location any.proto)))) \
$(SRCS) $(SRCS)
""", """,
exec_tools = ["//src/google/protobuf/compiler:protoc_nowkt"], exec_tools = ["//:protoc"],
visibility = ["//visibility:private"], visibility = ["//visibility:private"],
) )
@ -139,8 +151,11 @@ staleness_test(
tags = ["manual"], tags = ["manual"],
) )
# This is necessary for our generated cmake configs to pick up the checked in
# WKT files.
# TODO(b/246826624) Remove this once we generate WKT code from cmake.
cc_library( cc_library(
name = "wkt_cc_proto", name = "cmake_wkt_cc_proto",
srcs = ["wkt/google/protobuf/" + wkt + ".pb.cc" for wkt in WELL_KNOWN_TYPES], srcs = ["wkt/google/protobuf/" + wkt + ".pb.cc" for wkt in WELL_KNOWN_TYPES],
hdrs = ["wkt/google/protobuf/" + wkt + ".pb.h" for wkt in WELL_KNOWN_TYPES], hdrs = ["wkt/google/protobuf/" + wkt + ".pb.h" for wkt in WELL_KNOWN_TYPES],
copts = COPTS, copts = COPTS,
@ -466,6 +481,7 @@ cc_library(
include_prefix = "google/protobuf", include_prefix = "google/protobuf",
linkopts = LINK_OPTS, linkopts = LINK_OPTS,
visibility = [ visibility = [
"//:__pkg__",
"//pkg:__pkg__", "//pkg:__pkg__",
"//src/google/protobuf:__subpackages__", "//src/google/protobuf:__subpackages__",
], ],
@ -841,6 +857,7 @@ cc_library(
visibility = ["//:__subpackages__"], visibility = ["//:__subpackages__"],
deps = [ deps = [
"//src/google/protobuf/io", "//src/google/protobuf/io",
"//src/google/protobuf/util:differencer",
"@com_google_googletest//:gtest", "@com_google_googletest//:gtest",
], ],
) )
@ -993,9 +1010,11 @@ cc_test(
":cc_test_protos", ":cc_test_protos",
":protobuf", ":protobuf",
":test_util", ":test_util",
":test_util2",
"//src/google/protobuf/io", "//src/google/protobuf/io",
"//src/google/protobuf/stubs", "//src/google/protobuf/stubs",
"//src/google/protobuf/testing", "//src/google/protobuf/testing",
"//src/google/protobuf/util:differencer",
"@com_google_googletest//:gtest", "@com_google_googletest//:gtest",
"@com_google_googletest//:gtest_main", "@com_google_googletest//:gtest_main",
], ],
@ -1115,6 +1134,9 @@ cc_test(
":cc_test_protos", ":cc_test_protos",
":protobuf", ":protobuf",
":test_util", ":test_util",
":test_util2",
"//src/google/protobuf/util:differencer",
"//src/google/protobuf/util:time_util",
"@com_google_absl//absl/container:flat_hash_map", "@com_google_absl//absl/container:flat_hash_map",
"@com_google_absl//absl/container:flat_hash_set", "@com_google_absl//absl/container:flat_hash_set",
"@com_google_googletest//:gtest", "@com_google_googletest//:gtest",
@ -1136,6 +1158,7 @@ cc_test(
"//src/google/protobuf/io", "//src/google/protobuf/io",
"//src/google/protobuf/stubs", "//src/google/protobuf/stubs",
"//src/google/protobuf/testing", "//src/google/protobuf/testing",
"//src/google/protobuf/util:differencer",
"@com_google_absl//absl/log:scoped_mock_log", "@com_google_absl//absl/log:scoped_mock_log",
"@com_google_googletest//:gtest", "@com_google_googletest//:gtest",
"@com_google_googletest//:gtest_main", "@com_google_googletest//:gtest_main",
@ -1294,6 +1317,7 @@ cc_test(
"//src/google/protobuf/io", "//src/google/protobuf/io",
"//src/google/protobuf/stubs", "//src/google/protobuf/stubs",
"//src/google/protobuf/testing", "//src/google/protobuf/testing",
"@com_google_absl//absl/log:die_if_null",
"@com_google_absl//absl/log:scoped_mock_log", "@com_google_absl//absl/log:scoped_mock_log",
"@com_google_googletest//:gtest", "@com_google_googletest//:gtest",
"@com_google_googletest//:gtest_main", "@com_google_googletest//:gtest_main",
@ -1356,6 +1380,7 @@ cc_test(
"//src/google/protobuf/io", "//src/google/protobuf/io",
"//src/google/protobuf/stubs", "//src/google/protobuf/stubs",
"//src/google/protobuf/testing", "//src/google/protobuf/testing",
"//src/google/protobuf/util:differencer",
"@com_google_absl//absl/log:scoped_mock_log", "@com_google_absl//absl/log:scoped_mock_log",
"@com_google_googletest//:gtest", "@com_google_googletest//:gtest",
"@com_google_googletest//:gtest_main", "@com_google_googletest//:gtest_main",
@ -1368,7 +1393,9 @@ cc_test(
deps = [ deps = [
":cc_test_protos", ":cc_test_protos",
":protobuf", ":protobuf",
"//src/google/protobuf/compiler:importer",
"//src/google/protobuf/compiler:retention", "//src/google/protobuf/compiler:retention",
"//src/google/protobuf/util:differencer",
"@com_google_googletest//:gtest_main", "@com_google_googletest//:gtest_main",
], ],
) )

@ -102,11 +102,15 @@ cc_library(
) )
cc_library( cc_library(
name = "protoc_lib_nowkt", name = "protoc_lib",
srcs = [ srcs = [
"main.cc", "main.cc",
], ],
copts = COPTS, copts = COPTS,
visibility = [
"//:__pkg__",
"//pkg:__pkg__",
],
deps = [ deps = [
":code_generator", ":code_generator",
":command_line_interface", ":command_line_interface",
@ -124,29 +128,6 @@ cc_library(
], ],
) )
cc_binary(
name = "protoc_nowkt",
copts = COPTS,
linkopts = LINK_OPTS,
visibility = [
"//src/google/protobuf:__pkg__",
],
deps = [":protoc_lib_nowkt"],
)
cc_library(
name = "protoc_lib",
copts = COPTS,
visibility = [
"//:__pkg__",
"//pkg:__pkg__",
],
deps = [
":protoc_lib_nowkt",
"//:protobuf",
],
)
# Note: this is an alias for now. In the future, this rule will become the # Note: this is an alias for now. In the future, this rule will become the
# cc_binary for protoc, and //:protoc will become an alias. # cc_binary for protoc, and //:protoc will become an alias.
alias( alias(

@ -214,15 +214,6 @@ proto_library(
testonly = 1, testonly = 1,
srcs = ["json_format.proto"], srcs = ["json_format.proto"],
strip_import_prefix = "/src", strip_import_prefix = "/src",
deps = [
"//:any_proto",
"//:duration_proto",
"//:field_mask_proto",
"//:struct_proto",
"//:test_protos",
"//:timestamp_proto",
"//:wrappers_proto",
],
) )
cc_proto_library( cc_proto_library(

@ -38,9 +38,6 @@ syntax = "proto2";
package protobuf_unittest; package protobuf_unittest;
import "google/protobuf/any.proto";
import "google/protobuf/struct.proto";
message TestFlagsAndStrings { message TestFlagsAndStrings {
required int32 A = 1; required int32 A = 1;
repeated group RepeatedGroup = 2 { repeated group RepeatedGroup = 2 {

Loading…
Cancel
Save