load("@rules_cc//cc/common:cc_info.bzl", "CcInfo")
def _cc_headers_files_impl(ctx):
headers = ctx.attr.lib[CcInfo].compilation_context.headers
return [DefaultInfo(files = headers)]
cc_headers_files = rule(
implementation = _cc_headers_files_impl,
doc = "Collect all of a cc_library's compilation headers as raw files.",
attrs = {
"lib": attr.label(providers = [CcInfo]),
},
)
def _cc_header_pick_impl(ctx):
wanted = ctx.attr.basename
picked = [
h
for h in ctx.attr.lib[CcInfo].compilation_context.headers.to_list()
if h.basename == wanted
]
if len(picked) != 1:
fail("expected exactly one header named %s, found %d" % (wanted, len(picked)))
return [DefaultInfo(files = depset(picked))]
cc_header_pick = rule(
implementation = _cc_header_pick_impl,
doc = "Pick a single header file from a cc_library by basename (for $(location)).",
attrs = {
"lib": attr.label(providers = [CcInfo]),
"basename": attr.string(mandatory = True),
},
)