Skip to content

Commit

Permalink
Back out "Revert D52536616: [buck2] link groups: Add `ignore_force_st…
Browse files Browse the repository at this point in the history
…atic_follows_dependents` option"

Summary: ^

Reviewed By: dtolnay

Differential Revision: D52749220

fbshipit-source-id: 41a0b6d3c5639d54901c79d91cd6887f20c81c4d
  • Loading branch information
JakobDegen authored and facebook-github-bot committed Jan 16, 2024
1 parent d4fe6cb commit 1921ba0
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 6 deletions.
6 changes: 4 additions & 2 deletions prelude/cxx/link_groups.bzl
Expand Up @@ -419,7 +419,9 @@ def get_filtered_labels_to_links_map(
target_link_group = link_group_mappings.get(target)

# Always add force-static libs to the link.
if force_static_follows_dependents and node.preferred_linkage == Linkage("static"):
if (force_static_follows_dependents and
node.preferred_linkage == Linkage("static") and
not node.ignore_force_static_follows_dependents):
add_link(target, output_style)
elif not target_link_group and not link_group:
# Ungrouped linkable targets belong to the unlabeled executable
Expand Down Expand Up @@ -535,7 +537,7 @@ def find_relevant_roots(
# link group.
def collect_and_traverse_roots(roots, node_target):
node = linkable_graph_node_map.get(node_target)
if node.preferred_linkage == Linkage("static"):
if node.preferred_linkage == Linkage("static") and not node.ignore_force_static_follows_dependents:
return node.deps + node.exported_deps
node_link_group = link_group_mappings.get(node_target)
if node_link_group == MATCH_ALL_LABEL:
Expand Down
6 changes: 5 additions & 1 deletion prelude/linking/linkable_graph.bzl
Expand Up @@ -87,6 +87,8 @@ LinkableNode = record(
# Whether the node should appear in the android mergemap (which provides information about the original
# soname->final merged lib mapping)
include_in_android_mergemap = field(bool),
# Don't follow dependents on this node even if has preferred linkage static
ignore_force_static_follows_dependents = field(bool),

# Only allow constructing within this file.
_private = _DisallowConstruction,
Expand Down Expand Up @@ -144,7 +146,8 @@ def create_linkable_node(
shared_libs: dict[str, LinkedObject] = {},
can_be_asset: bool = True,
include_in_android_mergemap: bool = True,
linker_flags: [LinkerFlags, None] = None) -> LinkableNode:
linker_flags: [LinkerFlags, None] = None,
ignore_force_static_follows_dependents: bool = False) -> LinkableNode:
for output_style in _get_required_outputs_for_linkage(preferred_linkage):
expect(
output_style in link_infos,
Expand All @@ -164,6 +167,7 @@ def create_linkable_node(
include_in_android_mergemap = include_in_android_mergemap,
default_soname = default_soname,
linker_flags = linker_flags,
ignore_force_static_follows_dependents = ignore_force_static_follows_dependents,
_private = _DisallowConstruction(),
)

Expand Down
20 changes: 17 additions & 3 deletions prelude/rust/rust_library.bzl
Expand Up @@ -179,7 +179,13 @@ def prebuilt_rust_library_impl(ctx: AnalysisContext) -> list[Provider]:
external_debug_info = external_debug_info,
)

merged_link_info, shared_libs, inherited_graphs, inherited_link_deps = _rust_link_providers(ctx, dep_ctx, cxx_toolchain, link_infos)
merged_link_info, shared_libs, inherited_graphs, inherited_link_deps = _rust_link_providers(
ctx,
dep_ctx,
cxx_toolchain,
link_infos,
Linkage(ctx.attrs.preferred_linkage),
)
providers.append(
RustLinkInfo(
crate = crate,
Expand Down Expand Up @@ -528,7 +534,8 @@ def _rust_link_providers(
ctx: AnalysisContext,
dep_ctx: DepCollectionContext,
cxx_toolchain: CxxToolchainInfo,
link_infos: dict[LibOutputStyle, LinkInfos]) -> (
link_infos: dict[LibOutputStyle, LinkInfos],
preferred_linkage: Linkage) -> (
MergedLinkInfo,
SharedLibraryInfo,
list[LinkableGraph],
Expand Down Expand Up @@ -594,6 +601,13 @@ def _rust_link_providers(
# but that breaks arc focus, and setting it to "" breaks
# somerge
default_soname = get_default_shared_library_name(cxx_toolchain.linker_info, ctx.label),
# Link groups have a heuristic in which they assume that a
# preferred_linkage = "static" library needs to be linked
# into every single link group, instead of just one.
# Applying that same heuristic to Rust seems right, but only
# if this target actually requested that. Opt ourselves out
# if it didn't.
ignore_force_static_follows_dependents = preferred_linkage != Linkage("static"),
),
label = new_label,
),
Expand Down Expand Up @@ -628,7 +642,7 @@ def _rust_providers(
link, meta = param_artifact[params]
strategy_info[link_strategy] = _handle_rust_artifact(ctx, compile_ctx.dep_ctx, params.crate_type, link_strategy, link, meta)

merged_link_info, shared_libs, inherited_graphs, inherited_link_deps = _rust_link_providers(ctx, compile_ctx.dep_ctx, compile_ctx.cxx_toolchain_info, link_infos)
merged_link_info, shared_libs, inherited_graphs, inherited_link_deps = _rust_link_providers(ctx, compile_ctx.dep_ctx, compile_ctx.cxx_toolchain_info, link_infos, Linkage(ctx.attrs.preferred_linkage))

# Create rust library provider.
rust_link_info = RustLinkInfo(
Expand Down

0 comments on commit 1921ba0

Please sign in to comment.