bazelbuild / bazelbuild/bazel

Read aspect providers in cquery

Open
#22,528 7 comments 1 reaction 0 assignees View on GitHub
P4 team-Configurability type: feature request
Dominant language
Java
Stars
25.8k
Forks
4.6k
Avg merge
2d 20h
Merged PRs (30d)
72

Description

### Description of the feature request:

Cquery should be able to read providers that were created by an aspect.

I tested, and the aspects already run during cquery (see https://github.com/bazelbuild/bazel/issues/16310#issuecomment-2113976408). So all I'm asking is that we surface that via cquery. I suspect that this will *likely* be a relatively simple change, since the aspects already run, but it depends on how it's implemented.

### Which category does this issue belong to?

Rules API

### What underlying problem are you trying to solve with this feature?

Aspects are very useful for allowing IDEs access to metadata about the build. However, at the moment, IIUC, the way you have to use them is to:
1) run `bazel build --aspects=...`
1) Read from the output file generated by your aspect.

Sometimes, however, you don't need anything other than the providers created by the aspect. In cases like this, cquery should be sufficient. For example, generating `rust-project.json` in rust can be done without building a single target.

The use case that I was trying to do for this is that if I run cquery on the following target:
```
cc_binary(
name = "foo",
deps = ["//path/to:rust_library"],
)
```

Then I want cquery to attach a `RustAnalyzerInfo` object to `:foo`. This can then be picked up on by the rust-analyzer vscode extension. At the moment we use `bazel build` instead of `bazel cquery`, which means that if *any* bazel target fails to build, then we can't run get IDE support for our rust code.

### Which operating system are you running Bazel on?

Linux

### What is the output of `bazel info release`?

7.1.1

### If `bazel info release` returns `development version` or `(@non-git)`, tell us how you built Bazel.

_No response_

### What's the output of `git remote get-url origin; git rev-parse HEAD` ?

_No response_

### Have you found anything relevant by searching the web?

I commented on https://github.com/bazelbuild/bazel/issues/16310#issuecomment-2113976408 last week

### Any other information, logs, or outputs that you want to share?

_No response_

Contributor guide

Open the contributing guide

Research direction

Start with Bazel's cquery and aspect-handling entry points, then review the discussion in issue 16310, especially the linked comment about aspects already running during cquery. Determine how providers created by an aspect could be surfaced on queried targets without building them. Done means cquery exposes the aspect-created providers, including the RustAnalyzerInfo use case.

Written by the indexing model from the issue text.

Assessment

Domain
build-system, cli
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.