blob: c00d824145f8ffac53386bf249f4fb38cf877205 [file] [log] [blame]
Adam Cozzette501ecec2023-09-26 14:36:20 -07001"""upb_minitable_proto_library() exposes upb's generated minitables (foo.upb_minitable.h)"""
2
3load("//bazel:upb_proto_library_internal/aspect.bzl", "upb_proto_aspect_impl")
4load("//bazel:upb_proto_library_internal/cc_library_func.bzl", "upb_use_cpp_toolchain")
5load("//bazel:upb_proto_library_internal/rule.bzl", "upb_proto_rule_impl")
6
7UpbMinitableCcInfo = provider(
8 "Provider for cc_info for protos",
9 fields = ["cc_info"],
10)
11
12_UpbWrappedGeneratedSrcsInfo = provider(
13 "Provider for generated sources",
14 fields = ["srcs"],
15)
16
17def _upb_minitable_proto_library_aspect_impl(target, ctx):
18 return upb_proto_aspect_impl(
19 target = target,
20 ctx = ctx,
21 generator = "upb_minitable",
22 cc_provider = UpbMinitableCcInfo,
23 dep_cc_provider = None,
24 file_provider = _UpbWrappedGeneratedSrcsInfo,
25 )
26
27def _get_upb_minitable_proto_library_aspect_provides():
28 provides = [
29 UpbMinitableCcInfo,
30 _UpbWrappedGeneratedSrcsInfo,
31 ]
32
33 if hasattr(cc_common, "CcSharedLibraryHintInfo"):
34 provides.append(cc_common.CcSharedLibraryHintInfo)
35 elif hasattr(cc_common, "CcSharedLibraryHintInfo_6_X_getter_do_not_use"):
36 # This branch can be deleted once 6.X is not supported by upb rules
37 provides.append(cc_common.CcSharedLibraryHintInfo_6_X_getter_do_not_use)
38
39 return provides
40
41upb_minitable_proto_library_aspect = aspect(
42 attrs = {
43 "_copts": attr.label(
44 default = "//upb:upb_proto_library_copts__for_generated_code_only_do_not_use",
45 ),
Joshua Haberman2c7193b2023-09-27 13:26:21 -070046 "_upb_minitable_toolchain": attr.label(
Adam Cozzette12c7bb02023-09-28 12:54:11 -070047 default = Label("//upb_generator:protoc-gen-upb_minitable_toolchain"),
Adam Cozzette501ecec2023-09-26 14:36:20 -070048 ),
49 "_cc_toolchain": attr.label(
50 default = "@bazel_tools//tools/cpp:current_cc_toolchain",
51 ),
Adam Cozzette501ecec2023-09-26 14:36:20 -070052 "_fasttable_enabled": attr.label(default = "//upb:fasttable_enabled"),
53 },
54 implementation = _upb_minitable_proto_library_aspect_impl,
55 provides = _get_upb_minitable_proto_library_aspect_provides(),
56 attr_aspects = ["deps"],
57 fragments = ["cpp"],
58 toolchains = upb_use_cpp_toolchain(),
Joshua Haberman2c7193b2023-09-27 13:26:21 -070059 exec_groups = {
60 "proto_compiler": exec_group(),
61 },
Adam Cozzette501ecec2023-09-26 14:36:20 -070062)
63
64def _upb_minitable_proto_library_rule_impl(ctx):
65 return upb_proto_rule_impl(ctx, UpbMinitableCcInfo, _UpbWrappedGeneratedSrcsInfo)
66
67upb_minitable_proto_library = rule(
68 output_to_genfiles = True,
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)