Skip to content

Commit 7d04d0a

Browse files
srv-metameta-codesync[bot]
authored andcommitted
Discover transitioned and labeled sibling targets for rust-analyzer
Summary: When rust-analyzer resolves a Rust source file via path-based discovery (e.g. `arc rust-project develop-json '{"path":"..."}'`), Phase 1 BXL (`resolve_owning_buildfile_impl`) finds the owning target and its sibling targets in the same BUCK file. Previously, sibling discovery only matched `rust_binary|rust_library|rust_test` rule kinds. This caused failures for platform-constrained targets that rely on `transitioned()` wrappers for cross-compilation. The failure mode: 1. Phase 1 finds the owning target (e.g. a `rust_binary` with `compatible_with` device constraints) 2. Phase 1 misses sibling `_transitioned` targets (which apply platform transitions) because they don't match the rust kind filter 3. Phase 2 (`expand_targets`) tries to configure the constrained target, but `ctx.analysis()` drops it as incompatible with the x86_64 host 4. No targets survive → empty target universe → `buck2 cquery` fails This change makes three additions: 1. Sibling target discovery (Phase 1) now also matches `_?transitioned` rule kind, so transition wrapper targets in the same BUCK file are discovered alongside their constrained actual targets. 2. The `--buildfiles` code path gets the same `_?transitioned` kind filter plus `attrfilter("labels", "rust_analyzer_target")` for targets that opt in via label (e.g. those generated by `cli_transition_rules`). 3. Phase 2 `expand_targets` now includes `_?transitioned` in its `cquery().kind()` filter (alongside the existing `alias`), so discovered transition targets enter the configured target set. Since `_transitioned` forwards providers from its `actual` target, `RustAnalyzerInfo` is available and downstream processing works unchanged. The `_?transitioned` regex handles both `transitioned` and `_transitioned` (the actual `buck.type` emitted by the `transitioned()` macro). Reviewed By: dtolnay Differential Revision: D93604237 fbshipit-source-id: fe1ea88bca70981619f154246210b5e019dd8335
1 parent f9d62aa commit 7d04d0a

1 file changed

Lines changed: 7 additions & 4 deletions

File tree

prelude/rust/rust-analyzer/resolve_deps.bxl

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ def expand_targets(
269269
targets: list[TargetLabel],
270270
exclude_workspaces: bool) -> (dict[Label, bxl.AnalysisResult], list[TargetLabel]):
271271
target_universe = ctx.target_universe(targets).target_set()
272-
kind_target_list = ctx.cquery().kind("^(rust_binary|rust_library|rust_test|alias)$", target_universe)
272+
kind_target_list = ctx.cquery().kind("^(rust_binary|rust_library|rust_test|alias|_?transitioned)$", target_universe)
273273

274274
# Allow targets to opt-in to being treated as rust-analyzer-compatible.
275275
# This is used for cross-compilation targets that apply Buck transitions to Rust rules.
@@ -407,7 +407,9 @@ def resolve_owning_buildfile_impl(ctx: bxl.Context) -> None:
407407

408408
# equivalent of `flat_map`ing
409409
targets = [target for sublist in targets for target in sublist]
410-
targets = ctx.uquery().kind("^(rust_binary|rust_library|rust_test)$", targets)
410+
kind_targets = ctx.uquery().kind("^(rust_binary|rust_library|rust_test|_?transitioned)$", targets)
411+
labeled_targets = ctx.uquery().attrfilter("labels", "rust_analyzer_target", targets)
412+
targets = kind_targets + labeled_targets
411413
elif ctx.cli_args.targets:
412414
# equivalent of `flat_map`ing
413415
targets = [target for sublist in ctx.cli_args.targets for target in sublist]
@@ -430,8 +432,9 @@ def resolve_owning_buildfile_impl(ctx: bxl.Context) -> None:
430432
if "third-party/rust/vendor/" in buildfile_path:
431433
continue
432434

433-
extra_targets = ctx.uquery().targets_in_buildfile(buildfile_path)
434-
extra_targets = ctx.uquery().kind("^(rust_binary|rust_library|rust_test)$", extra_targets)
435+
all_buildfile_targets = ctx.uquery().targets_in_buildfile(buildfile_path)
436+
extra_targets = ctx.uquery().kind("^(rust_binary|rust_library|rust_test|_?transitioned)$", all_buildfile_targets)
437+
extra_targets += ctx.uquery().attrfilter("labels", "rust_analyzer_target", all_buildfile_targets)
435438

436439
# Exclude targets with the rustc_do_no_check label from the extra targets. This
437440
# label is used for foo@symbol targets (generated by rust_linkable_symbols), which

0 commit comments

Comments
 (0)