Avoid recursive call to `Insert` in the flat case.
[google-protobuf.git] / bazel / upb_minitable_proto_library.bzl
blob0a178421a2619e9af31bad7eabff37be4edbea9d
1 """upb_minitable_proto_library() exposes upb's generated minitables (foo.upb_minitable.h)"""
3 load("//bazel/common:proto_info.bzl", "ProtoInfo")
4 load("//bazel/private:upb_proto_library_internal/aspect.bzl", "upb_proto_aspect_impl")
5 load("//bazel/private:upb_proto_library_internal/cc_library_func.bzl", "upb_use_cpp_toolchain")
6 load("//bazel/private:upb_proto_library_internal/rule.bzl", "upb_proto_rule_impl")
8 UpbMinitableCcInfo = provider(
9     "Provider for cc_info for protos",
10     fields = ["cc_info"],
13 _UpbWrappedGeneratedSrcsInfo = provider(
14     "Provider for generated sources",
15     fields = ["srcs"],
18 def _upb_minitable_proto_library_aspect_impl(target, ctx):
19     return upb_proto_aspect_impl(
20         target = target,
21         ctx = ctx,
22         generator = "upb_minitable",
23         cc_provider = UpbMinitableCcInfo,
24         dep_cc_provider = None,
25         file_provider = _UpbWrappedGeneratedSrcsInfo,
26     )
28 def _get_upb_minitable_proto_library_aspect_provides():
29     provides = [
30         UpbMinitableCcInfo,
31         _UpbWrappedGeneratedSrcsInfo,
32     ]
34     if hasattr(cc_common, "CcSharedLibraryHintInfo"):
35         provides.append(cc_common.CcSharedLibraryHintInfo)
36     elif hasattr(cc_common, "CcSharedLibraryHintInfo_6_X_getter_do_not_use"):
37         # This branch can be deleted once 6.X is not supported by upb rules
38         provides.append(cc_common.CcSharedLibraryHintInfo_6_X_getter_do_not_use)
40     return provides
42 upb_minitable_proto_library_aspect = aspect(
43     attrs = {
44         "_copts": attr.label(
45             default = "//upb:upb_proto_library_copts__for_generated_code_only_do_not_use",
46         ),
47         "_upb_minitable_toolchain": attr.label(
48             default = Label("//upb_generator/minitable:toolchain"),
49         ),
50         "_cc_toolchain": attr.label(
51             default = "@bazel_tools//tools/cpp:current_cc_toolchain",
52         ),
53         "_fasttable_enabled": attr.label(default = "//upb:fasttable_enabled"),
54     },
55     implementation = _upb_minitable_proto_library_aspect_impl,
56     provides = _get_upb_minitable_proto_library_aspect_provides(),
57     attr_aspects = ["deps"],
58     fragments = ["cpp"],
59     toolchains = upb_use_cpp_toolchain(),
60     exec_groups = {
61         "proto_compiler": exec_group(),
62     },
65 def _upb_minitable_proto_library_rule_impl(ctx):
66     return upb_proto_rule_impl(ctx, UpbMinitableCcInfo, _UpbWrappedGeneratedSrcsInfo)
68 upb_minitable_proto_library = rule(
69     implementation = _upb_minitable_proto_library_rule_impl,
70     attrs = {
71         "deps": attr.label_list(
72             aspects = [upb_minitable_proto_library_aspect],
73             allow_rules = ["proto_library"],
74             providers = [ProtoInfo],
75         ),
76     },
77     provides = [CcInfo],