Skip to content

Commit 4d98a60

Browse files
capickettfacebook-github-bot
authored andcommitted
Rename non_rust functions to generalize for both rust + non_rust
Summary: In preparation for the next diff in this stack, I've split out the renaming to a pure refactor, for ease of review. Reviewed By: zertosh Differential Revision: D50804300 fbshipit-source-id: 243335f03e5ca2eda3b3020a4075f573d8b48a42
1 parent bfaf1bb commit 4d98a60

File tree

4 files changed

+65
-59
lines changed

4 files changed

+65
-59
lines changed

prelude/rust/build.bzl

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@ load(
6767
"attr_simple_crate_for_filenames",
6868
"get_available_proc_macros",
6969
"inherited_external_debug_info",
70-
"inherited_non_rust_link_info",
71-
"inherited_non_rust_shared_libs",
70+
"inherited_merged_link_infos",
71+
"inherited_shared_libs",
7272
"normalize_crate",
7373
"resolve_rust_deps",
7474
"style_info",
@@ -230,7 +230,7 @@ def generate_rustdoc_test(
230230
if link_style == LinkStyle("shared"):
231231
shlib_info = merge_shared_libraries(
232232
ctx.actions,
233-
deps = inherited_non_rust_shared_libs(ctx, include_doc_deps = True),
233+
deps = inherited_shared_libs(ctx, include_doc_deps = True),
234234
)
235235
for soname, shared_lib in traverse_shared_library_info(shlib_info).items():
236236
shared_libs[soname] = shared_lib.lib
@@ -258,7 +258,7 @@ def generate_rustdoc_test(
258258
LinkArgs(flags = extra_link_args),
259259
get_link_args_for_strategy(
260260
ctx,
261-
inherited_non_rust_link_info(ctx, include_doc_deps = True),
261+
inherited_merged_link_infos(ctx, include_doc_deps = True),
262262
# TODO(cjhopman): It's unclear how rust is using link_style. I'm not sure if it's intended to be a LibOutputStyle or a LinkStrategy.
263263
to_link_strategy(link_style),
264264
),
@@ -435,14 +435,14 @@ def rust_compile(
435435
# of that style.
436436

437437
if rust_cxx_link_group_info:
438-
inherited_non_rust_link_args = LinkArgs(
438+
inherited_link_args = LinkArgs(
439439
infos = rust_cxx_link_group_info.filtered_links + [rust_cxx_link_group_info.symbol_files_info],
440440
)
441441

442442
else:
443-
inherited_non_rust_link_args = get_link_args_for_strategy(
443+
inherited_link_args = get_link_args_for_strategy(
444444
ctx,
445-
inherited_non_rust_link_info(
445+
inherited_merged_link_infos(
446446
ctx,
447447
include_doc_deps = False,
448448
),
@@ -455,7 +455,7 @@ def rust_compile(
455455
compile_ctx.cxx_toolchain_info,
456456
[
457457
LinkArgs(flags = extra_link_args),
458-
inherited_non_rust_link_args,
458+
inherited_link_args,
459459
],
460460
"{}-{}".format(subdir, tempfile),
461461
output_short_path = emit_output.short_path,

prelude/rust/link_info.bzl

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -121,12 +121,12 @@ RustLinkInfo = provider(
121121
"crate": CrateName,
122122
# styles - information about each LinkStyle as RustLinkStyleInfo
123123
"styles": dict[LinkStyle, RustLinkStyleInfo],
124-
# Propagate non-rust native linkable dependencies through rust libraries.
125-
"non_rust_exported_link_deps": typing.Any,
126-
# Propagate non-rust native linkable info through rust libraries.
127-
"non_rust_link_info": typing.Any,
128-
# Propagate non-rust shared libraries through rust libraries.
129-
"non_rust_shared_libs": typing.Any,
124+
# Propagate native linkable dependencies through rust libraries.
125+
"exported_link_deps": typing.Any,
126+
# Propagate native linkable info through rust libraries.
127+
"merged_link_info": typing.Any,
128+
# Propagate shared libraries through rust libraries.
129+
"shared_libs": typing.Any,
130130
},
131131
)
132132

@@ -253,7 +253,7 @@ def resolve_rust_deps(
253253
def get_available_proc_macros(ctx: AnalysisContext) -> dict[TargetLabel, Dependency]:
254254
return {x.label.raw_target(): x for x in ctx.plugins[RustProcMacroPlugin]}
255255

256-
def _non_rust_linkable_graph(
256+
def _create_linkable_graph(
257257
ctx: AnalysisContext,
258258
deps: list[Dependency]) -> LinkableGraph:
259259
linkable_graph = create_linkable_graph(
@@ -323,19 +323,21 @@ def _rust_link_infos(
323323
def normalize_crate(label: str) -> str:
324324
return label.replace("-", "_")
325325

326-
def inherited_non_rust_exported_link_deps(ctx: AnalysisContext) -> list[Dependency]:
326+
# TODO(pickett): Currently this assumes the library target is being built as a
327+
# staticlib or cdylib.
328+
def inherited_exported_link_deps(ctx: AnalysisContext) -> list[Dependency]:
327329
deps = {}
328330
for dep in _non_rust_link_deps(ctx):
329331
deps[dep.label] = dep
330332
for info in _rust_link_infos(ctx):
331-
for dep in info.non_rust_exported_link_deps:
333+
for dep in info.exported_link_deps:
332334
deps[dep.label] = dep
333335
return deps.values()
334336

335-
def inherited_non_rust_link_group_info(
337+
def inherited_rust_cxx_link_group_info(
336338
ctx: AnalysisContext,
337339
link_style: [LinkStyle, None] = None) -> RustCxxLinkGroupInfo:
338-
link_deps = inherited_non_rust_exported_link_deps(ctx)
340+
link_deps = inherited_exported_link_deps(ctx)
339341

340342
# Assume a rust executable wants to use link groups if a link group map
341343
# is present
@@ -346,7 +348,7 @@ def inherited_non_rust_link_group_info(
346348
link_group_preferred_linkage = get_link_group_preferred_linkage(link_groups.values())
347349

348350
auto_link_group_specs = get_auto_link_group_specs(ctx, link_group_info)
349-
linkable_graph = _non_rust_linkable_graph(
351+
linkable_graph = _create_linkable_graph(
350352
ctx,
351353
link_deps,
352354
)
@@ -413,20 +415,24 @@ def inherited_non_rust_link_group_info(
413415
link_group_preferred_linkage = link_group_preferred_linkage,
414416
)
415417

416-
def inherited_non_rust_link_info(
418+
# TODO(pickett): Currently this assumes the library target is being built as a
419+
# staticlib or cdylib.
420+
def inherited_merged_link_infos(
417421
ctx: AnalysisContext,
418422
include_doc_deps: bool = False) -> list[MergedLinkInfo]:
419423
infos = []
420424
infos.extend(_non_rust_link_infos(ctx, include_doc_deps))
421-
infos.extend([d.non_rust_link_info for d in _rust_link_infos(ctx, include_doc_deps) if d.non_rust_link_info])
425+
infos.extend([d.merged_link_info for d in _rust_link_infos(ctx, include_doc_deps) if d.merged_link_info])
422426
return infos
423427

424-
def inherited_non_rust_shared_libs(
428+
# TODO(pickett): Currently this assumes the library target is being built as a
429+
# staticlib or cdylib.
430+
def inherited_shared_libs(
425431
ctx: AnalysisContext,
426432
include_doc_deps: bool = False) -> list[SharedLibraryInfo]:
427433
infos = []
428434
infos.extend(_non_rust_shared_lib_infos(ctx, include_doc_deps))
429-
infos.extend([d.non_rust_shared_libs for d in _rust_link_infos(ctx, include_doc_deps)])
435+
infos.extend([d.shared_libs for d in _rust_link_infos(ctx, include_doc_deps)])
430436
return infos
431437

432438
def inherited_external_debug_info(
@@ -437,16 +443,16 @@ def inherited_external_debug_info(
437443
non_rust_dep_link_style = dep_link_style
438444

439445
inherited_debug_infos = []
440-
inherited_non_rust_link_infos = []
446+
inherited_link_infos = []
441447

442448
for d in resolve_deps(ctx):
443449
if RustLinkInfo in d.dep:
444450
inherited_debug_infos.append(d.dep[RustLinkInfo].styles[rust_dep_link_style].external_debug_info)
445-
inherited_non_rust_link_infos.append(d.dep[RustLinkInfo].non_rust_link_info)
451+
inherited_link_infos.append(d.dep[RustLinkInfo].merged_link_info)
446452
elif MergedLinkInfo in d.dep:
447-
inherited_non_rust_link_infos.append(d.dep[MergedLinkInfo])
453+
inherited_link_infos.append(d.dep[MergedLinkInfo])
448454

449-
link_args = get_link_args_for_strategy(ctx, inherited_non_rust_link_infos, to_link_strategy(non_rust_dep_link_style))
455+
link_args = get_link_args_for_strategy(ctx, inherited_link_infos, to_link_strategy(non_rust_dep_link_style))
450456
inherited_debug_infos.append(unpack_external_debug_info(ctx.actions, link_args))
451457

452458
return make_artifact_tset(

prelude/rust/rust_binary.bzl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,8 @@ load(
6464
"DEFAULT_STATIC_LINK_STYLE",
6565
"attr_simple_crate_for_filenames",
6666
"enable_link_groups",
67-
"inherited_non_rust_link_group_info",
68-
"inherited_non_rust_shared_libs",
67+
"inherited_rust_cxx_link_group_info",
68+
"inherited_shared_libs",
6969
)
7070
load(":resources.bzl", "rust_attr_resources")
7171

@@ -131,7 +131,7 @@ def _rust_binary_common(
131131
filtered_targets = []
132132

133133
if enable_link_groups(ctx, link_style, specified_link_style, is_binary = True):
134-
rust_cxx_link_group_info = inherited_non_rust_link_group_info(
134+
rust_cxx_link_group_info = inherited_rust_cxx_link_group_info(
135135
ctx,
136136
link_style = link_style,
137137
)
@@ -147,7 +147,7 @@ def _rust_binary_common(
147147
if link_style == LinkStyle("shared") or rust_cxx_link_group_info != None:
148148
shlib_info = merge_shared_libraries(
149149
ctx.actions,
150-
deps = inherited_non_rust_shared_libs(ctx),
150+
deps = inherited_shared_libs(ctx),
151151
)
152152

153153
link_group_ctx = LinkGroupContext(

prelude/rust/rust_library.bzl

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -97,10 +97,10 @@ load(
9797
"RustLinkStyleInfo",
9898
"RustProcMacroMarker", # @unused Used as a type
9999
"attr_crate",
100+
"inherited_exported_link_deps",
100101
"inherited_external_debug_info",
101-
"inherited_non_rust_exported_link_deps",
102-
"inherited_non_rust_link_info",
103-
"inherited_non_rust_shared_libs",
102+
"inherited_merged_link_infos",
103+
"inherited_shared_libs",
104104
"resolve_deps",
105105
"resolve_rust_deps",
106106
"style_info",
@@ -142,11 +142,11 @@ def prebuilt_rust_library_impl(ctx: AnalysisContext) -> list[Provider]:
142142
RustLinkInfo(
143143
crate = crate,
144144
styles = styles,
145-
non_rust_exported_link_deps = inherited_non_rust_exported_link_deps(ctx),
146-
non_rust_link_info = create_merged_link_info_for_propagation(ctx, inherited_non_rust_link_info(ctx)),
147-
non_rust_shared_libs = merge_shared_libraries(
145+
exported_link_deps = inherited_exported_link_deps(ctx),
146+
merged_link_info = create_merged_link_info_for_propagation(ctx, inherited_merged_link_infos(ctx)),
147+
shared_libs = merge_shared_libraries(
148148
ctx.actions,
149-
deps = inherited_non_rust_shared_libs(ctx),
149+
deps = inherited_shared_libs(ctx),
150150
),
151151
),
152152
)
@@ -532,27 +532,27 @@ def _rust_providers(
532532
# non-Rust rules, found by walking through -- and ignoring -- Rust libraries
533533
# to find non-Rust native linkables and libraries.
534534
if not ctx.attrs.proc_macro:
535-
inherited_non_rust_link_deps = inherited_non_rust_exported_link_deps(ctx)
536-
inherited_non_rust_link = inherited_non_rust_link_info(ctx)
537-
inherited_non_rust_shlibs = inherited_non_rust_shared_libs(ctx)
535+
inherited_link_deps = inherited_exported_link_deps(ctx)
536+
inherited_link_infos = inherited_merged_link_infos(ctx)
537+
inherited_shlibs = inherited_shared_libs(ctx)
538538
else:
539539
# proc-macros are just used by the compiler and shouldn't propagate
540540
# their native deps to the link line of the target.
541-
inherited_non_rust_link = []
542-
inherited_non_rust_shlibs = []
543-
inherited_non_rust_link_deps = []
541+
inherited_link_infos = []
542+
inherited_shlibs = []
543+
inherited_link_deps = []
544544

545545
providers = []
546546

547547
# Create rust library provider.
548548
providers.append(RustLinkInfo(
549549
crate = crate,
550550
styles = style_info,
551-
non_rust_link_info = create_merged_link_info_for_propagation(ctx, inherited_non_rust_link),
552-
non_rust_exported_link_deps = inherited_non_rust_link_deps,
553-
non_rust_shared_libs = merge_shared_libraries(
551+
merged_link_info = create_merged_link_info_for_propagation(ctx, inherited_link_infos),
552+
exported_link_deps = inherited_link_deps,
553+
shared_libs = merge_shared_libraries(
554554
ctx.actions,
555-
deps = inherited_non_rust_shlibs,
555+
deps = inherited_shlibs,
556556
),
557557
))
558558

@@ -571,9 +571,9 @@ def _native_providers(
571571
dependencies are bundled into the Rust crate itself. We need to break out of
572572
this mode of operation.
573573
"""
574-
inherited_non_rust_link_deps = inherited_non_rust_exported_link_deps(ctx)
575-
inherited_non_rust_link = inherited_non_rust_link_info(ctx)
576-
inherited_non_rust_shlibs = inherited_non_rust_shared_libs(ctx)
574+
inherited_link_deps = inherited_exported_link_deps(ctx)
575+
inherited_link_infos = inherited_merged_link_infos(ctx)
576+
inherited_shlibs = inherited_shared_libs(ctx)
577577
linker_info = compile_ctx.cxx_toolchain_info.linker_info
578578
linker_type = linker_info.type
579579

@@ -639,14 +639,14 @@ def _native_providers(
639639

640640
# TODO(cjhopman): This is preserving existing behavior, but it doesn't make sense. These lists can be passed
641641
# unmerged to create_merged_link_info below. Potentially that could change link order, so needs to be done more carefully.
642-
merged_inherited_non_rust_link = create_merged_link_info_for_propagation(ctx, inherited_non_rust_link)
642+
merged_inherited_link = create_merged_link_info_for_propagation(ctx, inherited_link_infos)
643643

644644
# Native link provider.
645645
providers.append(create_merged_link_info(
646646
ctx,
647647
compile_ctx.cxx_toolchain_info.pic_behavior,
648648
link_infos,
649-
exported_deps = [merged_inherited_non_rust_link],
649+
exported_deps = [merged_inherited_link],
650650
preferred_linkage = preferred_linkage,
651651
))
652652

@@ -671,7 +671,7 @@ def _native_providers(
671671
providers.append(merge_shared_libraries(
672672
ctx.actions,
673673
create_shared_libraries(ctx, solibs),
674-
inherited_non_rust_shlibs,
674+
inherited_shlibs,
675675
))
676676

677677
# Omnibus root provider.
@@ -689,7 +689,7 @@ def _native_providers(
689689
external_debug_info = external_debug_infos[LibOutputStyle("pic_archive")],
690690
),
691691
),
692-
deps = inherited_non_rust_link_deps,
692+
deps = inherited_link_deps,
693693
)
694694
providers.append(linkable_root)
695695

@@ -704,18 +704,18 @@ def _native_providers(
704704
linkable_node = create_linkable_node(
705705
ctx = ctx,
706706
preferred_linkage = preferred_linkage,
707-
exported_deps = inherited_non_rust_link_deps,
707+
exported_deps = inherited_link_deps,
708708
link_infos = link_infos,
709709
shared_libs = solibs,
710710
default_soname = shlib_name,
711711
),
712712
),
713-
deps = inherited_non_rust_link_deps,
713+
deps = inherited_link_deps,
714714
)
715715

716716
providers.append(linkable_graph)
717717

718-
providers.append(merge_link_group_lib_info(deps = inherited_non_rust_link_deps))
718+
providers.append(merge_link_group_lib_info(deps = inherited_link_deps))
719719

720720
return providers
721721

0 commit comments

Comments
 (0)