2
0
Fork 0
mirror of https://github.com/bazelbuild/rules_cc synced 2024-11-27 20:43:26 +00:00

C++: Remove linked_statically_by from cc_shared_library

RELNOTES:none
PiperOrigin-RevId: 295131987
Change-Id: I507106a7553da61f706b64c9232e4b7ea9a180d9
This commit is contained in:
Googler 2020-02-14 06:11:13 -08:00 committed by Copybara-Service
parent 4de26b53a6
commit a2060ec7c9

View file

@ -9,18 +9,10 @@ load("//cc:find_cc_toolchain.bzl", "find_cc_toolchain")
# TODO(#5200): Add export_define to library_to_link and cc_library # TODO(#5200): Add export_define to library_to_link and cc_library
# TODO(plf): Even though at the begining the idea was to completely forbid
# anyone to link a library statically without permission from the library owner,
# there have been complaints about this. linked_statically_by is hard to use
# and too restrictive. static_deps will completely replace linked_statically_by.
# Library authors will still have control of who exports them by using exported_by.
GraphNodeInfo = provider( GraphNodeInfo = provider(
fields = { fields = {
"children": "Other GraphNodeInfo from dependencies of this target", "children": "Other GraphNodeInfo from dependencies of this target",
"label": "Label of the target visited", "label": "Label of the target visited",
# TODO(plf): Completely remove linked_statically_by.
"linked_statically_by": "The value of this attribute if the target has it",
}, },
) )
CcSharedLibraryInfo = provider( CcSharedLibraryInfo = provider(
@ -52,9 +44,9 @@ def _separate_static_and_dynamic_link_libraries(
node_label = str(node.label) node_label = str(node.label)
if node_label in can_be_linked_dynamically: if node_label in can_be_linked_dynamically:
link_dynamically_labels[node_label] = None link_dynamically_labels[node_label] = True
elif node_label not in preloaded_deps_direct_labels: elif node_label not in preloaded_deps_direct_labels:
link_statically_labels[node_label] = node.linked_statically_by link_statically_labels[node_label] = True
all_children.extend(node.children) all_children.extend(node.children)
return (link_statically_labels, link_dynamically_labels) return (link_statically_labels, link_dynamically_labels)
@ -211,14 +203,6 @@ def _filter_inputs(
else: else:
can_be_linked_statically = False can_be_linked_statically = False
# TODO(plf): This loop will go away when linked_statically_by is
# replaced completely by static_deps.
for linked_statically_by in link_statically_labels[owner]:
if linked_statically_by == str(ctx.label):
can_be_linked_statically = True
break
if not can_be_linked_statically:
for static_dep_path in ctx.attr.static_deps: for static_dep_path in ctx.attr.static_deps:
target_specified = _is_target_specified(static_dep_path) target_specified = _is_target_specified(static_dep_path)
static_dep_path_label = ctx.label.relative(static_dep_path) static_dep_path_label = ctx.label.relative(static_dep_path)
@ -364,13 +348,8 @@ def _graph_structure_aspect_impl(target, ctx):
if GraphNodeInfo in dep: if GraphNodeInfo in dep:
children.append(dep[GraphNodeInfo]) children.append(dep[GraphNodeInfo])
linked_statically_by = []
if hasattr(ctx.rule.attr, "linked_statically_by"):
linked_statically_by = [str(label) for label in ctx.rule.attr.linked_statically_by]
return [GraphNodeInfo( return [GraphNodeInfo(
label = ctx.label, label = ctx.label,
linked_statically_by = linked_statically_by,
children = children, children = children,
)] )]
@ -385,9 +364,6 @@ cc_shared_library = rule(
"dynamic_deps": attr.label_list(providers = [CcSharedLibraryInfo]), "dynamic_deps": attr.label_list(providers = [CcSharedLibraryInfo]),
"exports": attr.label_list(providers = [CcInfo], aspects = [graph_structure_aspect]), "exports": attr.label_list(providers = [CcInfo], aspects = [graph_structure_aspect]),
"preloaded_deps": attr.label_list(providers = [CcInfo]), "preloaded_deps": attr.label_list(providers = [CcInfo]),
# TODO(plf): Replaces linked_statically_by attribute. Instead of
# linked_statically_by attribute in each cc_library we will have the
# attribute exported_by which will restrict exportability.
"static_deps": attr.string_list(), "static_deps": attr.string_list(),
"user_link_flags": attr.string_list(), "user_link_flags": attr.string_list(),
"visibility_file": attr.label(allow_single_file = True), "visibility_file": attr.label(allow_single_file = True),