• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1"""Internal rule implementation for upb_*_proto_library() rules."""
2
3def _filter_none(elems):
4    out = []
5    for elem in elems:
6        if elem:
7            out.append(elem)
8    return out
9
10def upb_proto_rule_impl(ctx, cc_info_provider, srcs_provider):
11    """An implementation for upb_*proto_library() rules.
12
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.
19
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
28
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    ]
40