Skip to content
Merged
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: 1 addition & 0 deletions docs/flatten.md
Original file line number Diff line number Diff line change
Expand Up @@ -1721,6 +1721,7 @@ Annotates rust rules with RustAnalyzerInfo later used to build a rust-project.js
| :------------- | :------------- |
| deps| String |
| proc_macro_deps| String |
| crate| String |


**ATTRIBUTES**
Expand Down
1 change: 1 addition & 0 deletions docs/rust_analyzer.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ Annotates rust rules with RustAnalyzerInfo later used to build a rust-project.js
| :------------- | :------------- |
| deps| String |
| proc_macro_deps| String |
| crate| String |


**ATTRIBUTES**
Expand Down
5 changes: 4 additions & 1 deletion rust/private/rust_analyzer.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ def _rust_analyzer_aspect_impl(target, ctx):
dep_infos = [dep[RustAnalyzerInfo] for dep in ctx.rule.attr.deps if RustAnalyzerInfo in dep]
if hasattr(ctx.rule.attr, "proc_macro_deps"):
dep_infos += [dep[RustAnalyzerInfo] for dep in ctx.rule.attr.proc_macro_deps if RustAnalyzerInfo in dep]
if hasattr(ctx.rule.attr, "crate"):
dep_infos.append(ctx.rule.attr.crate[RustAnalyzerInfo])

transitive_deps = depset(direct = dep_infos, order = "postorder", transitive = [dep.transitive_deps for dep in dep_infos])

crate_info = target[rust_common.crate_info]
Expand Down Expand Up @@ -102,7 +105,7 @@ def find_proc_macro_dylib_path(toolchain, target):
return None

rust_analyzer_aspect = aspect(
attr_aspects = ["deps", "proc_macro_deps"],
attr_aspects = ["deps", "proc_macro_deps", "crate"],
implementation = _rust_analyzer_aspect_impl,
toolchains = [str(Label("//rust:toolchain"))],
incompatible_use_toolchain_transition = True,
Expand Down
50 changes: 50 additions & 0 deletions test/rust_analyzer/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
load("//rust:defs.bzl", "rust_analyzer", "rust_library", "rust_proc_macro", "rust_test")

rust_library(
name = "mylib",
srcs = ["mylib.rs"],
proc_macro_deps = [":proc_macro_dep"],
deps = [":lib_dep"],
)

rust_library(
name = "lib_dep",
srcs = ["lib_dep.rs"],
)

rust_proc_macro(
name = "proc_macro_dep",
srcs = ["proc_macro_dep.rs"],
)

rust_test(
name = "mylib_test",
crate = ":mylib",
proc_macro_deps = [":extra_proc_macro_dep"],
deps = [":extra_test_dep"],
)

rust_library(
name = "extra_test_dep",
srcs = ["extra_test_dep.rs"],
)

rust_proc_macro(
name = "extra_proc_macro_dep",
srcs = ["extra_proc_macro_dep.rs"],
)

rust_analyzer(
name = "rust_analyzer",
testonly = True,
targets = [":mylib_test"],
)

rust_test(
name = "rust_project_json_test",
srcs = ["rust_project_json_test.rs"],
data = [":rust-project.json"],
edition = "2018",
use_libtest_harness = False,
deps = ["//tools/runfiles"],
)
1 change: 1 addition & 0 deletions test/rust_analyzer/extra_proc_macro_dep.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

1 change: 1 addition & 0 deletions test/rust_analyzer/extra_test_dep.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

1 change: 1 addition & 0 deletions test/rust_analyzer/lib_dep.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

1 change: 1 addition & 0 deletions test/rust_analyzer/mylib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

1 change: 1 addition & 0 deletions test/rust_analyzer/proc_macro_dep.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

20 changes: 20 additions & 0 deletions test/rust_analyzer/rust_project_json_test.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
use runfiles::Runfiles;

fn main() {
let r = Runfiles::create().unwrap();
let rust_project_path = r.rlocation("rules_rust/test/rust_analyzer/rust-project.json");

let content = std::fs::read_to_string(&rust_project_path)
.expect(&format!("couldn't open {:?}", &rust_project_path));

for dep in &[
"lib_dep",
"extra_test_dep",
"proc_macro_dep",
"extra_proc_macro_dep",
] {
if !content.contains(dep) {
panic!("expected rust-project.json to contain {}.", dep);
}
}
}