Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rust_analyzer: generate more reqired sources #3031

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion extensions/prost/private/prost.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,6 @@ def _rust_prost_aspect_impl(target, ctx):
package_info = package_info_file,
),
rust_analyzer_info,
OutputGroupInfo(rust_generated_srcs = [lib_rs]),
]

rust_prost_aspect = aspect(
Expand Down
1 change: 0 additions & 1 deletion extensions/protobuf/proto.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,6 @@ def _rust_proto_compile(protos, descriptor_sets, imports, crate_name, ctx, is_gr
),
output_hash = output_hash,
)
providers.append(OutputGroupInfo(rust_generated_srcs = srcs))
return providers

def _rust_protogrpc_library_impl(ctx, is_grpc):
Expand Down
14 changes: 13 additions & 1 deletion rust/private/rust_analyzer.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,21 @@ def _rust_analyzer_aspect_impl(target, ctx):
build_info = build_info,
))

# The sources rust-analyzer needs to parse this crate.
# Exposed as an output group so they can be generated if needed.
# Direct-dependencies only trades accuracy for speed - re-evaluate?
required_srcs = depset(
transitive = [crate_info.srcs] + [dep.crate.srcs for dep in dep_infos],
# target.json is also required (in fact rust-analyzer may crash if it's missing)
direct = [toolchain.target_json for toolchain in [toolchain] if toolchain.target_json],
)

return [
rust_analyzer_info,
OutputGroupInfo(rust_analyzer_crate_spec = rust_analyzer_info.crate_specs),
OutputGroupInfo(
rust_analyzer_crate_spec = rust_analyzer_info.crate_specs,
rust_analyzer_srcs = required_srcs,
),
]

def find_proc_macro_dylib_path(toolchain, target):
Expand Down
2 changes: 1 addition & 1 deletion tools/rust_analyzer/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ pub fn generate_crate_info(
"--aspects={}//rust:defs.bzl%rust_analyzer_aspect",
rules_rust.as_ref()
))
.arg("--output_groups=rust_analyzer_crate_spec,rust_generated_srcs")
.arg("--output_groups=rust_analyzer_crate_spec,rust_analyzer_srcs")
.args(targets)
.output()?;

Expand Down