[<prev] [next>] [day] [month] [year] [list]
Message-ID: <20241205115438.234221-1-me@kloenk.dev>
Date: Thu, 5 Dec 2024 12:54:36 +0100
From: Fiona Behrens <me@...enk.dev>
To: Miguel Ojeda <ojeda@...nel.org>,
Alex Gaynor <alex.gaynor@...il.com>,
Boqun Feng <boqun.feng@...il.com>,
Gary Guo <gary@...yguo.net>,
Björn Roy Baron <bjorn3_gh@...tonmail.com>,
Benno Lossin <benno.lossin@...ton.me>,
Andreas Hindborg <a.hindborg@...nel.org>,
Alice Ryhl <aliceryhl@...gle.com>,
Trevor Gross <tmgross@...ch.edu>
Cc: Fiona Behrens <me@...enk.dev>,
rust-for-linux@...r.kernel.org,
linux-kernel@...r.kernel.org
Subject: [PATCH] rust: rust-analyzer: add proc_macro for macros crate
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@...enk.dev>
---
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
Powered by blists - more mailing lists