Simplify generated string_view APIs.
[google-protobuf.git] / bazel / upb_c_proto_library.bzl
blobebeebed7f9060139b367e079b458a27acb0ce570
1 """upb_c_proto_library() exposes upb's generated C API for protobuf (foo.upb.h)"""
3 load("//bazel:upb_minitable_proto_library.bzl", "UpbMinitableCcInfo", "upb_minitable_proto_library_aspect")
4 load("//bazel/common:proto_info.bzl", "ProtoInfo")
5 load("//bazel/private:upb_proto_library_internal/aspect.bzl", "upb_proto_aspect_impl")
6 load("//bazel/private:upb_proto_library_internal/cc_library_func.bzl", "upb_use_cpp_toolchain")
7 load("//bazel/private:upb_proto_library_internal/rule.bzl", "upb_proto_rule_impl")
9 UpbWrappedCcInfo = provider(
10     "Provider for cc_info for protos",
11     fields = ["cc_info"],
14 _UpbWrappedGeneratedSrcsInfo = provider(
15     "Provider for generated sources",
16     fields = ["srcs"],
19 def _upb_c_proto_library_aspect_impl(target, ctx):
20     return upb_proto_aspect_impl(
21         target = target,
22         ctx = ctx,
23         generator = "upb",
24         cc_provider = UpbWrappedCcInfo,
25         dep_cc_provider = UpbMinitableCcInfo,
26         file_provider = _UpbWrappedGeneratedSrcsInfo,
27         provide_cc_shared_library_hints = False,
28     )
30 upb_c_proto_library_aspect = aspect(
31     attrs = {
32         "_copts": attr.label(
33             default = "//upb:upb_proto_library_copts__for_generated_code_only_do_not_use",
34         ),
35         "_upb_toolchain": attr.label(
36             default = Label("//upb_generator/c:toolchain"),
37         ),
38         "_cc_toolchain": attr.label(
39             default = "@bazel_tools//tools/cpp:current_cc_toolchain",
40         ),
41     },
42     implementation = _upb_c_proto_library_aspect_impl,
43     requires = [upb_minitable_proto_library_aspect],
44     required_aspect_providers = [UpbMinitableCcInfo],
45     provides = [
46         UpbWrappedCcInfo,
47         _UpbWrappedGeneratedSrcsInfo,
48     ],
49     attr_aspects = ["deps"],
50     fragments = ["cpp"],
51     toolchains = upb_use_cpp_toolchain(),
52     exec_groups = {
53         "proto_compiler": exec_group(),
54     },
57 def _upb_c_proto_library_rule_impl(ctx):
58     return upb_proto_rule_impl(ctx, UpbWrappedCcInfo, _UpbWrappedGeneratedSrcsInfo)
60 upb_c_proto_library = rule(
61     implementation = _upb_c_proto_library_rule_impl,
62     attrs = {
63         "deps": attr.label_list(
64             aspects = [upb_c_proto_library_aspect],
65             allow_rules = ["proto_library"],
66             providers = [ProtoInfo],
67         ),
68     },
69     provides = [CcInfo],