Skip to content

Commit d91735d

Browse files
authored
Streamline deps handling in collect_deps (#3645)
We already call `transform_deps` in all cases upstream, so we can't end up with Targets here anymore. Before: <img width="1673" height="117" alt="image" src="https://github.com/user-attachments/assets/22fb4eab-9159-48df-8e2c-f873bdbae4a4" /> After: <img width="1680" height="122" alt="image" src="https://github.com/user-attachments/assets/6e95d767-c4aa-45e2-bfc4-9423fefd41e1" />
1 parent e51f3ae commit d91735d

File tree

2 files changed

+9
-44
lines changed

2 files changed

+9
-44
lines changed

rust/private/rustc.bzl

Lines changed: 8 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -265,42 +265,27 @@ def collect_deps(
265265

266266
crate_deps = []
267267
for dep in deps + proc_macro_deps:
268-
crate_group = None
269-
270-
if type(dep) == "Target" and rust_common.crate_group_info in dep:
271-
crate_group = dep[rust_common.crate_group_info]
272-
elif type(dep) == "struct" and hasattr(dep, "crate_group_info") and dep.crate_group_info != None:
273-
crate_group = dep.crate_group_info
268+
crate_group = getattr(dep, "crate_group_info", None)
269+
if crate_group:
270+
crate_deps.extend(crate_group.dep_variant_infos.to_list())
274271
else:
275272
crate_deps.append(dep)
276273

277-
if crate_group:
278-
for dep_variant_info in crate_group.dep_variant_infos.to_list():
279-
crate_deps.append(struct(
280-
crate_info = dep_variant_info.crate_info,
281-
dep_info = dep_variant_info.dep_info,
282-
cc_info = dep_variant_info.cc_info,
283-
))
284-
285274
aliases = {k.label: v for k, v in aliases.items()}
286275
for dep in crate_deps:
287-
(crate_info, dep_info) = _get_crate_and_dep_info(dep)
288-
cc_info = _get_cc_info(dep)
289-
dep_build_info = _get_build_info(dep)
276+
crate_info = dep.crate_info
277+
dep_info = dep.dep_info
278+
cc_info = dep.cc_info
279+
dep_build_info = dep.build_info
290280

291281
if cc_info:
292282
for li in cc_info.linking_context.linker_inputs.to_list():
293283
linkstamps.extend(li.linkstamps)
294284

295285
if crate_info:
296286
# This dependency is a rust_library
297-
298-
# When crate_info.owner is set, we use it. When the dep type is Target we get the
299-
# label from dep.label
300-
owner = getattr(crate_info, "owner", dep.label if type(dep) == "Target" else None)
301-
302287
direct_deps.append(AliasableDepInfo(
303-
name = aliases.get(owner, crate_info.name),
288+
name = aliases.get(crate_info.owner, crate_info.name),
304289
dep = crate_info,
305290
))
306291

@@ -410,27 +395,6 @@ def _collect_libs_from_linker_inputs(linker_inputs, use_pic):
410395
for lib in li.libraries
411396
]
412397

413-
def _get_crate_and_dep_info(dep):
414-
if type(dep) == "Target" and rust_common.crate_info in dep:
415-
return (dep[rust_common.crate_info], dep[rust_common.dep_info])
416-
elif type(dep) == "struct" and hasattr(dep, "crate_info"):
417-
return (dep.crate_info, dep.dep_info)
418-
return (None, None)
419-
420-
def _get_cc_info(dep):
421-
if type(dep) == "Target" and CcInfo in dep:
422-
return dep[CcInfo]
423-
elif type(dep) == "struct" and hasattr(dep, "cc_info"):
424-
return dep.cc_info
425-
return None
426-
427-
def _get_build_info(dep):
428-
if type(dep) == "Target" and BuildInfo in dep:
429-
return dep[BuildInfo]
430-
elif type(dep) == "struct" and hasattr(dep, "build_info"):
431-
return dep.build_info
432-
return None
433-
434398
def get_cc_user_link_flags(ctx):
435399
"""Get the current target's linkopt flags
436400

test/unit/cc_info/cc_info_test.bzl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,7 @@ def _rust_cc_injection_impl(ctx):
182182
cc_info = ctx.attr.cc_dep[CcInfo],
183183
crate_info = None,
184184
dep_info = None,
185+
build_info = None,
185186
)
186187
return [
187188
rust_common.crate_group_info(

0 commit comments

Comments
 (0)