Skip to content

Commit

Permalink
rules: Key RustLinkInfo by LinkStrategy
Browse files Browse the repository at this point in the history
Summary:
This matches what `MergedLinkInfo` does

Also, renames `RustLinkStyleInfo` to `RustLinkStrategyInfo`

Reviewed By: dtolnay

Differential Revision: D52450314

fbshipit-source-id: a7d1ae4add333258bb3ea3435e1fae45970e966f
  • Loading branch information
JakobDegen authored and facebook-github-bot committed Jan 3, 2024
1 parent 792f9dc commit b0274ab
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 26 deletions.
4 changes: 2 additions & 2 deletions prelude/rust/build.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ load(
"RustCxxLinkGroupInfo", #@unused Used as a type
"RustDependency",
"RustLinkInfo",
"RustLinkStyleInfo",
"RustLinkStrategyInfo",
"attr_crate",
"attr_simple_crate_for_filenames",
"get_available_proc_macros",
Expand Down Expand Up @@ -223,7 +223,7 @@ def generate_rustdoc_test(
ctx: AnalysisContext,
compile_ctx: CompileContext,
link_strategy: LinkStrategy,
library: RustLinkStyleInfo,
library: RustLinkStrategyInfo,
params: BuildParams,
default_roots: list[str]) -> (cmd_args, dict[str, cmd_args]):
exec_is_windows = ctx.attrs._exec_os_type[OsLookup].platform == "windows"
Expand Down
11 changes: 5 additions & 6 deletions prelude/rust/link_info.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ RustProcMacroMarker = provider(fields = {
})

# Information which is keyed on link_style
RustLinkStyleInfo = record(
RustLinkStrategyInfo = record(
# Path to library or binary
rlib = field(Artifact),
# Transitive dependencies which are relevant to the consumer. For crate types which do not
Expand All @@ -121,8 +121,8 @@ RustLinkInfo = provider(
fields = {
# crate - crate name
"crate": CrateName,
# styles - information about each LinkStyle as RustLinkStyleInfo
"styles": dict[LinkStyle, RustLinkStyleInfo],
# strategies - information about each LinkStrategy as RustLinkStrategyInfo
"strategies": dict[LinkStrategy, RustLinkStrategyInfo],
# Propagate native linkable dependencies through rust libraries.
"exported_link_deps": list[Dependency],
# Propagate native linkable info through rust libraries.
Expand All @@ -138,11 +138,10 @@ def _adjust_link_strategy_for_rust_dependencies(dep_link_strategy: LinkStrategy)
else:
return dep_link_strategy

def strategy_info(info: RustLinkInfo, dep_link_strategy: LinkStrategy) -> RustLinkStyleInfo:
def strategy_info(info: RustLinkInfo, dep_link_strategy: LinkStrategy) -> RustLinkStrategyInfo:
rust_dep_link_strategy = _adjust_link_strategy_for_rust_dependencies(dep_link_strategy)

# FIXME(JakobDegen): Yeet `LinkStyle`
return info.styles[LinkStyle(rust_dep_link_strategy.value)]
return info.strategies[rust_dep_link_strategy]

# Any dependency of a Rust crate
RustOrNativeDependency = record(
Expand Down
4 changes: 2 additions & 2 deletions prelude/rust/rust-analyzer/resolve_deps.bxl
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# License, Version 2.0 found in the LICENSE-APACHE file in the root directory
# of this source tree.

load("@prelude//linking:link_info.bzl", "LinkStyle")
load("@prelude//linking:link_info.bzl", "LinkStrategy")
load("@prelude//rust:link_info.bzl", "RustLinkInfo")

def materialize(ctx, target):
Expand Down Expand Up @@ -154,7 +154,7 @@ def expand_proc_macros(ctx, targets):
proc_macro = getattr(attrs, "proc_macro", False)
if proc_macro:
analysis = ctx.analysis(target)
rlib = analysis.providers()[RustLinkInfo].styles[LinkStyle("shared")].rlib
rlib = analysis.providers()[RustLinkInfo].strategies[LinkStrategy("shared")].rlib
label = target.label.raw_target()
out[label] = {"actual": label, "dylib": ctx.output.ensure(rlib).abs_path()}
return out
Expand Down
31 changes: 15 additions & 16 deletions prelude/rust/rust_library.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ load(
":link_info.bzl",
"DEFAULT_STATIC_LINK_STYLE",
"RustLinkInfo",
"RustLinkStyleInfo",
"RustLinkStrategyInfo",
"RustProcMacroMarker", # @unused Used as a type
"attr_crate",
"inherited_exported_link_deps",
Expand Down Expand Up @@ -134,15 +134,14 @@ def prebuilt_rust_library_impl(ctx: AnalysisContext) -> list[Provider]:

# Rust link provider.
crate = attr_crate(ctx)
styles = {}
for style in LinkStyle:
dep_link_strategy = to_link_strategy(style)
tdeps, tmetadeps, external_debug_info, tprocmacrodeps = _compute_transitive_deps(ctx, dep_ctx, dep_link_strategy)
strategies = {}
for link_strategy in LinkStrategy:
tdeps, tmetadeps, external_debug_info, tprocmacrodeps = _compute_transitive_deps(ctx, dep_ctx, link_strategy)
external_debug_info = make_artifact_tset(
actions = ctx.actions,
children = external_debug_info,
)
styles[style] = RustLinkStyleInfo(
strategies[link_strategy] = RustLinkStrategyInfo(
rlib = ctx.attrs.rlib,
transitive_deps = tdeps,
rmeta = ctx.attrs.rlib,
Expand All @@ -155,7 +154,7 @@ def prebuilt_rust_library_impl(ctx: AnalysisContext) -> list[Provider]:
providers.append(
RustLinkInfo(
crate = crate,
styles = styles,
strategies = strategies,
exported_link_deps = inherited_exported_link_deps(ctx, dep_ctx),
merged_link_info = create_merged_link_info_for_propagation(ctx, inherited_merged_link_infos(ctx, dep_ctx)),
shared_libs = merge_shared_libraries(
Expand Down Expand Up @@ -459,7 +458,7 @@ def _handle_rust_artifact(
dep_ctx: DepCollectionContext,
params: BuildParams,
link: RustcOutput,
meta: RustcOutput) -> RustLinkStyleInfo:
meta: RustcOutput) -> RustLinkStrategyInfo:
"""
Return the RustLinkInfo for a given set of artifacts. The main consideration
is computing the right set of dependencies.
Expand All @@ -481,7 +480,7 @@ def _handle_rust_artifact(
artifacts = filter(None, [link.dwo_output_directory]),
children = external_debug_info,
)
return RustLinkStyleInfo(
return RustLinkStrategyInfo(
rlib = link.output,
transitive_deps = tdeps,
rmeta = meta.output,
Expand All @@ -492,7 +491,7 @@ def _handle_rust_artifact(
)
else:
# Proc macro deps are always the real thing
return RustLinkStyleInfo(
return RustLinkStrategyInfo(
rlib = link.output,
transitive_deps = tdeps,
rmeta = link.output,
Expand All @@ -504,7 +503,7 @@ def _handle_rust_artifact(

def _default_providers(
lang_style_param: dict[(LinkageLang, LibOutputStyle), BuildParams],
param_artifact: dict[BuildParams, RustLinkStyleInfo],
param_artifact: dict[BuildParams, RustLinkStrategyInfo],
rustdoc: Artifact,
rustdoc_test: (cmd_args, dict[str, cmd_args]),
doctests_enabled: bool,
Expand Down Expand Up @@ -568,7 +567,7 @@ def _rust_providers(
ctx: AnalysisContext,
compile_ctx: CompileContext,
lang_style_param: dict[(LinkageLang, LibOutputStyle), BuildParams],
param_artifact: dict[BuildParams, RustLinkStyleInfo]) -> list[Provider]:
param_artifact: dict[BuildParams, RustLinkStrategyInfo]) -> list[Provider]:
"""
Return the set of providers for Rust linkage.
"""
Expand All @@ -577,9 +576,9 @@ def _rust_providers(
pic_behavior = compile_ctx.cxx_toolchain_info.pic_behavior
preferred_linkage = Linkage(ctx.attrs.preferred_linkage)

style_info = {
link_style: param_artifact[lang_style_param[(LinkageLang("rust"), get_lib_output_style(to_link_strategy(link_style), preferred_linkage, pic_behavior))]]
for link_style in LinkStyle
strategy_info = {
link_strategy: param_artifact[lang_style_param[(LinkageLang("rust"), get_lib_output_style(link_strategy, preferred_linkage, pic_behavior))]]
for link_strategy in LinkStrategy
}

# Inherited link input and shared libraries. As in v1, this only includes
Expand All @@ -601,7 +600,7 @@ def _rust_providers(
# Create rust library provider.
providers.append(RustLinkInfo(
crate = crate,
styles = style_info,
strategies = strategy_info,
merged_link_info = create_merged_link_info_for_propagation(ctx, inherited_link_infos),
exported_link_deps = inherited_link_deps,
shared_libs = merge_shared_libraries(
Expand Down

0 comments on commit b0274ab

Please sign in to comment.