Skip to content

Commit 52aa150

Browse files
author
Adam Cozzette
authored
Tweak BUILD setup to make the layering check change less disruptive (#15838)
We recently updated the codebase to comply with the Bazel layering check, which essentially requires any C++ header inclusion to be matched with a build dependency on a target providing that header. As part of that, I removed a handful of dependencies from the `//:protobuf` target, since these dependencies were not set up in a way that respected the layering check. However, I realized that this may cause a number of breakages, especially since we did not provide the correct public targets until very recently. This change effectively adds back in the missing dependencies, so that projects which do not yet adhere to the layering check can continue to depend on them indirectly. This way, we still adhere to the layering check and make it possible for projects that depend on us to do so, but in most cases we won't immediately break anyone. PiperOrigin-RevId: 607021111
1 parent 62e7a56 commit 52aa150

File tree

3 files changed

+73
-33
lines changed

3 files changed

+73
-33
lines changed

BUILD.bazel

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -253,13 +253,13 @@ cc_binary(
253253
# a user-defined proto_lang_toolchain.
254254
alias(
255255
name = "protobuf",
256-
actual = "//src/google/protobuf",
256+
actual = "//src/google/protobuf:protobuf_layering_check_legacy",
257257
visibility = ["//visibility:public"],
258258
)
259259

260260
alias(
261261
name = "protobuf_nowkt",
262-
actual = "//src/google/protobuf:protobuf_nowkt",
262+
actual = "//src/google/protobuf:protobuf_layering_check_legacy",
263263
deprecation = "Use //:protobuf instead",
264264
visibility = ["//visibility:public"],
265265
)

rust/cpp_kernel/BUILD

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ cc_library(
1212
],
1313
deps = [
1414
":rust_alloc_for_cpp_api", # buildcleaner: keep
15-
"//:protobuf",
16-
"//:protobuf_lite",
15+
"//src/google/protobuf",
16+
"//src/google/protobuf:protobuf_lite",
1717
"@com_google_absl//absl/strings:string_view",
1818
],
1919
)

src/google/protobuf/BUILD.bazel

Lines changed: 69 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -515,6 +515,36 @@ cc_library(
515515
],
516516
)
517517

518+
PROTOBUF_HEADERS = [
519+
"cpp_edition_defaults.h",
520+
"cpp_features.pb.h",
521+
"descriptor.h",
522+
"descriptor.pb.h",
523+
"descriptor_database.h",
524+
"descriptor_visitor.h",
525+
"dynamic_message.h",
526+
"feature_resolver.h",
527+
"field_access_listener.h",
528+
"generated_enum_reflection.h",
529+
"generated_message_bases.h",
530+
"generated_message_reflection.h",
531+
"generated_message_tctable_gen.h",
532+
"internal_message_util.h",
533+
"map_entry.h",
534+
"map_field.h",
535+
"map_field_inl.h",
536+
"message.h",
537+
"metadata.h",
538+
"reflection.h",
539+
"reflection_internal.h",
540+
"reflection_mode.h",
541+
"reflection_ops.h",
542+
"service.h",
543+
"text_format.h",
544+
"unknown_field_set.h",
545+
"wire_format.h",
546+
]
547+
518548
cc_library(
519549
name = "protobuf",
520550
srcs = [
@@ -540,35 +570,7 @@ cc_library(
540570
"unknown_field_set.cc",
541571
"wire_format.cc",
542572
],
543-
hdrs = [
544-
"cpp_edition_defaults.h",
545-
"cpp_features.pb.h",
546-
"descriptor.h",
547-
"descriptor.pb.h",
548-
"descriptor_database.h",
549-
"descriptor_visitor.h",
550-
"dynamic_message.h",
551-
"feature_resolver.h",
552-
"field_access_listener.h",
553-
"generated_enum_reflection.h",
554-
"generated_message_bases.h",
555-
"generated_message_reflection.h",
556-
"generated_message_tctable_gen.h",
557-
"internal_message_util.h",
558-
"map_entry.h",
559-
"map_field.h",
560-
"map_field_inl.h",
561-
"message.h",
562-
"metadata.h",
563-
"reflection.h",
564-
"reflection_internal.h",
565-
"reflection_mode.h",
566-
"reflection_ops.h",
567-
"service.h",
568-
"text_format.h",
569-
"unknown_field_set.h",
570-
"wire_format.h",
571-
],
573+
hdrs = PROTOBUF_HEADERS,
572574
copts = COPTS,
573575
linkopts = LINK_OPTS,
574576
strip_include_prefix = "/src",
@@ -612,6 +614,44 @@ cc_library(
612614
],
613615
)
614616

617+
# This target exposes the headers for the protobuf runtime, and additionally
618+
# depends on the C++ well-known types and some other miscellaneous utilities.
619+
# The purpose is to preserve compatibility with projects that do not yet comply
620+
# with the layering check. Ideally everyone should get into compliance with the
621+
# layering check, which would mean for example taking a dependency on
622+
# //:any_cc_proto instead of relying on this target to make it available
623+
# indirectly.
624+
cc_library(
625+
name = "protobuf_layering_check_legacy",
626+
hdrs = PROTOBUF_HEADERS,
627+
copts = COPTS,
628+
linkopts = LINK_OPTS,
629+
strip_include_prefix = "/src",
630+
visibility = [
631+
"//:__subpackages__",
632+
],
633+
deps = [
634+
":any_cc_proto",
635+
":api_cc_proto",
636+
":duration_cc_proto",
637+
":empty_cc_proto",
638+
":field_mask_cc_proto",
639+
":protobuf",
640+
":source_context_cc_proto",
641+
":struct_cc_proto",
642+
":timestamp_cc_proto",
643+
":type_cc_proto",
644+
":wrappers_cc_proto",
645+
"//src/google/protobuf/compiler:importer",
646+
"//src/google/protobuf/util:delimited_message_util",
647+
"//src/google/protobuf/util:differencer",
648+
"//src/google/protobuf/util:field_mask_util",
649+
"//src/google/protobuf/util:json_util",
650+
"//src/google/protobuf/util:time_util",
651+
"//src/google/protobuf/util:type_resolver",
652+
],
653+
)
654+
615655
cc_test(
616656
name = "has_bits_test",
617657
srcs = ["has_bits_test.cc"],

0 commit comments

Comments
 (0)