Skip to content

Commit

Permalink
Back out "Revert D52499874: [rust] rules: Better handling of exported…
Browse files Browse the repository at this point in the history
… deps"

Summary:
Original commit changeset: 0a89ff543b1a

Original Phabricator Diff: D52499874

Reviewed By: dtolnay

Differential Revision: D52749218

fbshipit-source-id: dbef3c9f7b65197134bce3bfe9b6119c99ee042c
  • Loading branch information
JakobDegen authored and facebook-github-bot committed Jan 16, 2024
1 parent 46681ff commit d4fe6cb
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 9 deletions.
11 changes: 9 additions & 2 deletions prelude/rust/link_info.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,15 @@ RustLinkInfo = provider(
"linkable_graphs": list[LinkableGraph],
# LinkGroupLibInfo intentionally omitted because the Rust -> Rust version
# never needs to be different from the Rust -> native version
# The native dependencies reachable from this Rust library through other
# Rust libraries
#
# Rust currently treats all native dependencies as being exported, in
# the sense of C++ `exported_deps`. However, they are not only exported
# from the Rust library that directly depends on them, they are also
# exported through any further chains of Rust libraries. This list
# tracks those dependencies
#
# FIXME(JakobDegen): We should not default to treating all native deps
# as exported.
"exported_link_deps": list[Dependency],
},
)
Expand Down
21 changes: 14 additions & 7 deletions prelude/rust/rust_library.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -547,7 +547,7 @@ def _rust_link_providers(
inherited_link_infos = inherited_merged_link_infos(ctx, dep_ctx)
inherited_shlibs = inherited_shared_libs(ctx, dep_ctx)
inherited_graphs = inherited_linkable_graphs(ctx, dep_ctx)
inherited_link_deps = inherited_exported_link_deps(ctx, dep_ctx)
inherited_exported_deps = inherited_exported_link_deps(ctx, dep_ctx)

if dep_ctx.advanced_unstable_linking:
# We have to produce a version of the providers that are defined in such
Expand All @@ -557,11 +557,15 @@ def _rust_link_providers(
#
# Note that all of this code is FORCE_RLIB specific. Disabling that
# setting requires replacing this with the "real" native providers
#
# As an optimization, we never bother reporting exported deps here.
# Whichever dependent uses the providers created here will take care of
# that for us.
merged_link_info = create_merged_link_info(
ctx,
cxx_toolchain.pic_behavior,
link_infos,
exported_deps = inherited_link_infos,
deps = inherited_link_infos,
preferred_linkage = Linkage("static"),
)
shared_libs = merge_shared_libraries(
Expand All @@ -584,7 +588,7 @@ def _rust_link_providers(
linkable_node = create_linkable_node(
ctx = ctx,
preferred_linkage = Linkage("static"),
exported_deps = inherited_graphs,
deps = inherited_graphs,
link_infos = link_infos,
# FIXME(JakobDegen): It should be ok to set this to `None`,
# but that breaks arc focus, and setting it to "" breaks
Expand All @@ -602,7 +606,7 @@ def _rust_link_providers(
ctx.actions,
deps = inherited_shlibs,
)
return (merged_link_info, shared_libs, inherited_graphs, inherited_link_deps)
return (merged_link_info, shared_libs, inherited_graphs, inherited_exported_deps)

def _rust_providers(
ctx: AnalysisContext,
Expand Down Expand Up @@ -723,6 +727,7 @@ def _native_providers(
inherited_link_infos = [rust_link_info.merged_link_info]
inherited_shlibs = [rust_link_info.shared_libs]
inherited_link_graphs = rust_link_info.linkable_graphs
inherited_exported_deps = rust_link_info.exported_link_deps

linker_info = compile_ctx.cxx_toolchain_info.linker_info
linker_type = linker_info.type
Expand All @@ -739,7 +744,8 @@ def _native_providers(
ctx,
compile_ctx.cxx_toolchain_info.pic_behavior,
link_infos,
exported_deps = inherited_link_infos,
deps = inherited_link_infos,
exported_deps = filter(None, [d.get(MergedLinkInfo) for d in inherited_exported_deps]),
preferred_linkage = preferred_linkage,
))

Expand Down Expand Up @@ -796,13 +802,14 @@ def _native_providers(
linkable_node = create_linkable_node(
ctx = ctx,
preferred_linkage = preferred_linkage,
exported_deps = inherited_link_graphs,
deps = inherited_link_graphs,
exported_deps = inherited_exported_deps,
link_infos = link_infos,
shared_libs = solibs,
default_soname = shlib_name,
),
),
deps = inherited_link_graphs,
deps = inherited_link_graphs + inherited_exported_deps,
)

providers.append(linkable_graph)
Expand Down

0 comments on commit d4fe6cb

Please sign in to comment.