• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1"""upb_c_proto_reflection_library() exposes upb reflection for protobuf (foo.upbdefs.h)"""
2
3load("//bazel:upb_minitable_proto_library.bzl", "UpbMinitableCcInfo", "upb_minitable_proto_library_aspect")
4load("//bazel/common:proto_common.bzl", "proto_common")
5load("//bazel/common:proto_info.bzl", "ProtoInfo")
6load("//bazel/private:upb_proto_library_internal/aspect.bzl", "upb_proto_aspect_impl")
7load("//bazel/private:upb_proto_library_internal/cc_library_func.bzl", "upb_use_cpp_toolchain")
8load("//bazel/private:upb_proto_library_internal/rule.bzl", "upb_proto_rule_impl")
9
10_UpbDefsWrappedCcInfo = provider("Provider for cc_info for protos", fields = ["cc_info"])
11
12_WrappedDefsGeneratedSrcsInfo = provider(
13    "Provider for generated reflective sources",
14    fields = ["srcs"],
15)
16
17def _upb_proto_reflection_library_aspect_impl(target, ctx):
18    return upb_proto_aspect_impl(
19        target = target,
20        ctx = ctx,
21        generator = "upbdefs",
22        cc_provider = _UpbDefsWrappedCcInfo,
23        dep_cc_provider = UpbMinitableCcInfo,
24        file_provider = _WrappedDefsGeneratedSrcsInfo,
25        provide_cc_shared_library_hints = False,
26    )
27
28_upb_proto_reflection_library_aspect = aspect(
29    attrs = {
30        "_copts": attr.label(
31            default = "//upb:upb_proto_library_copts__for_generated_code_only_do_not_use",
32        ),
33        "_upbdefs_toolchain": attr.label(
34            default = Label("//upb_generator/reflection:toolchain"),
35            cfg = getattr(proto_common, "proto_lang_toolchain_cfg", "target"),
36        ),
37        "_cc_toolchain": attr.label(
38            default = "@bazel_tools//tools/cpp:current_cc_toolchain",
39        ),
40    },
41    implementation = _upb_proto_reflection_library_aspect_impl,
42    requires = [upb_minitable_proto_library_aspect],
43    required_aspect_providers = [UpbMinitableCcInfo],
44    provides = [
45        _UpbDefsWrappedCcInfo,
46        _WrappedDefsGeneratedSrcsInfo,
47    ],
48    attr_aspects = ["deps"],
49    fragments = ["cpp"],
50    toolchains = upb_use_cpp_toolchain(),
51    exec_groups = {
52        "proto_compiler": exec_group(),
53    },
54)
55
56def _upb_proto_reflection_library_rule_impl(ctx):
57    return upb_proto_rule_impl(ctx, _UpbDefsWrappedCcInfo, _WrappedDefsGeneratedSrcsInfo)
58
59upb_proto_reflection_library = rule(
60    implementation = _upb_proto_reflection_library_rule_impl,
61    attrs = {
62        "deps": attr.label_list(
63            aspects = [_upb_proto_reflection_library_aspect],
64            allow_rules = ["proto_library"],
65            providers = [ProtoInfo],
66        ),
67    },
68    provides = [CcInfo],
69)
70