2024-08-09 22:16:57 +02:00
|
|
|
HEADER_DEP_SUFFIX = "_header_dep"
|
2024-08-16 17:22:09 +02:00
|
|
|
LINK_DEP_SUFFIX = "_link_dep"
|
2024-08-09 22:16:57 +02:00
|
|
|
|
|
|
|
def create_header_dep_impl(ctx):
|
|
|
|
compilation_context = cc_common.create_compilation_context(
|
|
|
|
includes = depset(transitive = [header_dep[CcInfo].compilation_context.includes for header_dep in ctx.attr.header_deps]),
|
|
|
|
headers = depset(transitive = [header_dep[CcInfo].compilation_context.headers for header_dep in ctx.attr.header_deps]),
|
|
|
|
)
|
|
|
|
|
|
|
|
return CcInfo(compilation_context = compilation_context)
|
|
|
|
|
|
|
|
create_header_dep = rule(
|
|
|
|
create_header_dep_impl,
|
|
|
|
attrs = {
|
|
|
|
"header_deps": attr.label_list(providers = [CcInfo]),
|
|
|
|
},
|
|
|
|
doc = "create header only CcInfo",
|
|
|
|
fragments = ["cpp"],
|
|
|
|
)
|
2024-08-16 17:22:09 +02:00
|
|
|
|
|
|
|
def create_link_dep_impl(ctx):
|
|
|
|
deps = []
|
|
|
|
for dep in ctx.attr.link_deps:
|
|
|
|
if dep[CcInfo].linking_context:
|
|
|
|
for input in dep[CcInfo].linking_context.linker_inputs.to_list():
|
|
|
|
for library in input.libraries:
|
|
|
|
if library.dynamic_library:
|
2024-09-13 23:42:44 +02:00
|
|
|
dep = library.resolved_symlink_dynamic_library.path
|
|
|
|
if dep not in deps:
|
|
|
|
deps.append(library.resolved_symlink_dynamic_library.path)
|
2024-08-16 17:22:09 +02:00
|
|
|
if library.static_library:
|
2024-09-13 23:42:44 +02:00
|
|
|
dep = library.static_library.path
|
|
|
|
if dep not in deps:
|
|
|
|
deps.append(library.static_library.path)
|
|
|
|
|
|
|
|
link_list = ctx.actions.declare_file(ctx.attr.target_name + "_links.list")
|
2024-09-20 03:01:07 +02:00
|
|
|
ctx.actions.write(
|
|
|
|
output = link_list,
|
|
|
|
content = "\n".join(deps),
|
2024-09-13 23:42:44 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
return DefaultInfo(files = depset([link_list]))
|
2024-08-16 17:22:09 +02:00
|
|
|
|
|
|
|
create_link_deps = rule(
|
|
|
|
create_link_dep_impl,
|
|
|
|
attrs = {
|
2024-09-13 23:42:44 +02:00
|
|
|
"target_name": attr.string(),
|
2024-08-16 17:22:09 +02:00
|
|
|
"link_deps": attr.label_list(providers = [CcInfo]),
|
|
|
|
},
|
|
|
|
doc = "create a psuedo target to query link deps for",
|
|
|
|
)
|