[PATCH] rust: rust-analyzer: add proc_macro for macros crate
From: Fiona Behrens
Date: Thu Dec 05 2024 - 06:55:12 EST
Add the proc_macro crate from the rust sysroot to the
rust-project.json file used by rust-analyzer. This allows
rust-analyzer to autocomplete items from the proc_macro crate inside
the macros crate.
This also adds std and alloc only to be used by proc_macro and
macros. This does not add the dependencies of those crates as this is
sufficent for rust-analyzer to have a basic autocompletion support
without having to worry about all the dependencies std usually needs.
alloc is added, as e.g. std::vec just reexports from alloc, so that
macros can use autocompletion for Vec and similar.
Signed-off-by: Fiona Behrens <me@xxxxxxxxxx>
---
scripts/generate_rust_analyzer.py | 26 +++++++++++++++++++++++++-
1 file changed, 25 insertions(+), 1 deletion(-)
diff --git a/scripts/generate_rust_analyzer.py b/scripts/generate_rust_analyzer.py
index 09e1d166d8d2..747b5ed6c857 100755
--- a/scripts/generate_rust_analyzer.py
+++ b/scripts/generate_rust_analyzer.py
@@ -64,10 +64,34 @@ def generate_crates(srctree, objtree, sysroot_src, external_src, cfgs):
[],
)
+ # alloc only for std/proc_macros/macros
+ append_crate(
+ "alloc",
+ sysroot_src / "alloc" / "src" / "lib.rs",
+ ["core"],
+ is_workspace_member=False,
+ )
+
+ # std only for proc_macros/macros
+ append_crate(
+ "std",
+ sysroot_src / "std" / "src" / "lib.rs",
+ ["core", "alloc"],
+ is_workspace_member=False,
+ )
+
+ # proc_macro for macros crate
+ append_crate(
+ "proc_macro",
+ sysroot_src / "proc_macro" / "src" / "lib.rs",
+ ["std", "core"],
+ is_workspace_member=False,
+ )
+
append_crate(
"macros",
srctree / "rust" / "macros" / "lib.rs",
- [],
+ ["std", "proc_macro"],
is_proc_macro=True,
)
crates[-1]["proc_macro_dylib_path"] = f"{objtree}/rust/libmacros.so"
--
2.47.0