Auto-generate files after cl/701102058
[google-protobuf.git] / bazel / private / upb_proto_library_internal / rule.bzl
blobfeb29292c3d67e87edb1c9ddaf2ab414cc1647db
1 """Internal rule implementation for upb_*_proto_library() rules."""
3 def _filter_none(elems):
4     out = []
5     for elem in elems:
6         if elem:
7             out.append(elem)
8     return out
10 def upb_proto_rule_impl(ctx, cc_info_provider, srcs_provider):
11     """An implementation for upb_*proto_library() rules.
13     Args:
14       ctx: The rule `ctx` argument
15       cc_info_provider: The provider containing a wrapped CcInfo that will be exposed to users who
16         depend on this rule.
17       srcs_provider: The provider containing the generated source files. This will be used to make
18         the DefaultInfo return the source files.
20     Returns:
21       Providers for this rule.
22     """
23     if len(ctx.attr.deps) != 1:
24         fail("only one deps dependency allowed.")
25     dep = ctx.attr.deps[0]
26     srcs = dep[srcs_provider].srcs
27     cc_info = dep[cc_info_provider].cc_info
29     lib = cc_info.linking_context.linker_inputs.to_list()[0].libraries[0]
30     files = _filter_none([
31         lib.static_library,
32         lib.pic_static_library,
33         lib.dynamic_library,
34     ])
35     return [
36         DefaultInfo(files = depset(files + srcs.hdrs + srcs.srcs)),
37         srcs,
38         cc_info,
39     ]