• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1"""upb_minitable_proto_library() exposes upb's generated minitables (foo.upb_minitable.h)"""
2
3load("//bazel/common:proto_info.bzl", "ProtoInfo")
4load("//bazel/private:upb_proto_library_internal/aspect.bzl", "upb_proto_aspect_impl")
5load("//bazel/private:upb_proto_library_internal/cc_library_func.bzl", "upb_use_cpp_toolchain")
6load("//bazel/private:upb_proto_library_internal/rule.bzl", "upb_proto_rule_impl")
7
8UpbMinitableCcInfo = provider(
9    "Provider for cc_info for protos",
10    fields = ["cc_info"],
11)
12
13_UpbWrappedGeneratedSrcsInfo = provider(
14    "Provider for generated sources",
15    fields = ["srcs"],
16)
17
18def _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    )
27
28def _get_upb_minitable_proto_library_aspect_provides():
29    provides = [
30        UpbMinitableCcInfo,
31        _UpbWrappedGeneratedSrcsInfo,
32    ]
33
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)
39
40    return provides
41
42upb_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    },
63)
64
65def _upb_minitable_proto_library_rule_impl(ctx):
66    return upb_proto_rule_impl(ctx, UpbMinitableCcInfo, _UpbWrappedGeneratedSrcsInfo)
67
68upb_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],
78)
79