Adds UnsafeCollectionOperations for unsafe access to RepeatedField<T> (#16772)
[google-protobuf.git] / bazel / upb_proto_reflection_library.bzl
blob8347dfb7f0c152301a638695bb28c363428fd2b7
1 """upb_c_proto_reflection_library() exposes upb reflection for protobuf (foo.upbdefs.h)"""
3 load("//bazel:upb_minitable_proto_library.bzl", "UpbMinitableCcInfo", "upb_minitable_proto_library_aspect")
4 load("//bazel/common:proto_common.bzl", "proto_common")
5 load("//bazel/common:proto_info.bzl", "ProtoInfo")
6 load("//bazel/private:upb_proto_library_internal/aspect.bzl", "upb_proto_aspect_impl")
7 load("//bazel/private:upb_proto_library_internal/cc_library_func.bzl", "upb_use_cpp_toolchain")
8 load("//bazel/private:upb_proto_library_internal/rule.bzl", "upb_proto_rule_impl")
10 _UpbDefsWrappedCcInfo = provider("Provider for cc_info for protos", fields = ["cc_info"])
12 _WrappedDefsGeneratedSrcsInfo = provider(
13     "Provider for generated reflective sources",
14     fields = ["srcs"],
17 def _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     )
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     },
56 def _upb_proto_reflection_library_rule_impl(ctx):
57     return upb_proto_rule_impl(ctx, _UpbDefsWrappedCcInfo, _WrappedDefsGeneratedSrcsInfo)
59 upb_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],