All of lore.kernel.org
 help / color / mirror / Atom feed
From: Tamir Duberstein <tamird@kernel.org>
To: "Jesung Yang" <y.j3ms.n@gmail.com>,
	"Miguel Ojeda" <ojeda@kernel.org>,
	"Boqun Feng" <boqun.feng@gmail.com>,
	"Gary Guo" <gary@garyguo.net>,
	"Björn Roy Baron" <bjorn3_gh@protonmail.com>,
	"Benno Lossin" <lossin@kernel.org>,
	"Andreas Hindborg" <a.hindborg@kernel.org>,
	"Alice Ryhl" <aliceryhl@google.com>,
	"Trevor Gross" <tmgross@umich.edu>,
	"Danilo Krummrich" <dakr@kernel.org>
Cc: rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org,
	 Tamir Duberstein <tamird@kernel.org>,
	 Daniel Almeida <daniel.almeida@collabora.com>
Subject: [PATCH 2/4] scripts: generate_rust_analyzer.py: drop `"is_proc_macro": false`
Date: Thu, 22 Jan 2026 12:30:46 -0500	[thread overview]
Message-ID: <20260122-rust-analyzer-types-v1-2-29cc2e91dcd5@kernel.org> (raw)
In-Reply-To: <20260122-rust-analyzer-types-v1-0-29cc2e91dcd5@kernel.org>

Add a dedicated `append_proc_macro_crate` function to reduce overloading
in `append_crate`. This has the effect of removing `"is_proc_macro":
false` from the output; this field is interpreted as false if absent[1]
so this doesn't change the behavior of rust-analyzer.

Use the `/` operator on `pathlib.Path` rather than directly crafting a
string. This is consistent with all other path manipulation in this
script.

Link: https://github.com/rust-lang/rust-analyzer/blob/8d01570b5e812a49daa1f08404269f6ea5dd73a1/crates/project-model/src/project_json.rs#L372-L373 [1]
Tested-by: Daniel Almeida <daniel.almeida@collabora.com>
Reviewed-by: Daniel Almeida <daniel.almeida@collabora.com>
Reviewed-by: Trevor Gross <tmgross@umich.edu>
Signed-off-by: Tamir Duberstein <tamird@kernel.org>
---
 scripts/generate_rust_analyzer.py | 60 ++++++++++++++++++++++++++++-----------
 1 file changed, 43 insertions(+), 17 deletions(-)

diff --git a/scripts/generate_rust_analyzer.py b/scripts/generate_rust_analyzer.py
index fbf686f0dced..bc79e4d8e8e7 100755
--- a/scripts/generate_rust_analyzer.py
+++ b/scripts/generate_rust_analyzer.py
@@ -42,20 +42,17 @@ def generate_crates(srctree, objtree, sysroot_src, external_src, cfgs, core_edit
         *,
         cfg,
         is_workspace_member,
-        is_proc_macro,
         edition,
     ):
         cfg = cfg if cfg is not None else []
         is_workspace_member = (
             is_workspace_member if is_workspace_member is not None else True
         )
-        is_proc_macro = is_proc_macro if is_proc_macro is not None else False
         edition = edition if edition is not None else "2021"
-        crate = {
+        return {
             "display_name": display_name,
             "root_module": str(root_module),
             "is_workspace_member": is_workspace_member,
-            "is_proc_macro": is_proc_macro,
             "deps": [{"crate": crates_indexes[dep], "name": dep} for dep in deps],
             "cfg": cfg,
             "edition": edition,
@@ -63,13 +60,47 @@ def generate_crates(srctree, objtree, sysroot_src, external_src, cfgs, core_edit
                 "RUST_MODFILE": "This is only for rust-analyzer"
             }
         }
-        if is_proc_macro:
-            proc_macro_dylib_name = subprocess.check_output(
-                [os.environ["RUSTC"], "--print", "file-names", "--crate-name", display_name, "--crate-type", "proc-macro", "-"],
+
+    def append_proc_macro_crate(
+        display_name,
+        root_module,
+        deps,
+        *,
+        cfg=None,
+        is_workspace_member=None,
+        edition=None,
+    ):
+        crate = build_crate(
+            display_name,
+            root_module,
+            deps,
+            cfg=cfg,
+            is_workspace_member=is_workspace_member,
+            edition=edition,
+        )
+        proc_macro_dylib_name = (
+            subprocess.check_output(
+                [
+                    os.environ["RUSTC"],
+                    "--print",
+                    "file-names",
+                    "--crate-name",
+                    display_name,
+                    "--crate-type",
+                    "proc-macro",
+                    "-",
+                ],
                 stdin=subprocess.DEVNULL,
-            ).decode('utf-8').strip()
-            crate["proc_macro_dylib_path"] = f"{objtree}/rust/{proc_macro_dylib_name}"
-        return crate
+            )
+            .decode("utf-8")
+            .strip()
+        )
+        proc_macro_crate = {
+            **crate,
+            "is_proc_macro": True,
+            "proc_macro_dylib_path": str(objtree / "rust" / proc_macro_dylib_name),
+        }
+        return register_crate(proc_macro_crate)
 
     def register_crate(crate):
         crates_indexes[crate["display_name"]] = len(crates)
@@ -82,7 +113,6 @@ def generate_crates(srctree, objtree, sysroot_src, external_src, cfgs, core_edit
         *,
         cfg=None,
         is_workspace_member=None,
-        is_proc_macro=None,
         edition=None,
     ):
         return register_crate(
@@ -92,7 +122,6 @@ def generate_crates(srctree, objtree, sysroot_src, external_src, cfgs, core_edit
                 deps,
                 cfg=cfg,
                 is_workspace_member=is_workspace_member,
-                is_proc_macro=is_proc_macro,
                 edition=edition,
             )
         )
@@ -148,11 +177,10 @@ def generate_crates(srctree, objtree, sysroot_src, external_src, cfgs, core_edit
         cfg=crates_cfgs["syn"],
     )
 
-    append_crate(
+    append_proc_macro_crate(
         "macros",
         srctree / "rust" / "macros" / "lib.rs",
         ["std", "proc_macro", "proc_macro2", "quote", "syn"],
-        is_proc_macro=True,
     )
 
     append_crate(
@@ -161,12 +189,11 @@ def generate_crates(srctree, objtree, sysroot_src, external_src, cfgs, core_edit
         ["core", "compiler_builtins"],
     )
 
-    append_crate(
+    append_proc_macro_crate(
         "pin_init_internal",
         srctree / "rust" / "pin-init" / "internal" / "src" / "lib.rs",
         [],
         cfg=["kernel"],
-        is_proc_macro=True,
     )
 
     append_crate(
@@ -192,7 +219,6 @@ def generate_crates(srctree, objtree, sysroot_src, external_src, cfgs, core_edit
             deps,
             cfg=cfg,
             is_workspace_member=True,
-            is_proc_macro=False,
             edition=None,
         )
         crate["env"]["OBJTREE"] = str(objtree.resolve(True))

-- 
2.52.0


  parent reply	other threads:[~2026-01-22 17:30 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-01-22 17:30 [PATCH 0/4] scripts: generate_rust_analyzer.py: tidy and add type hints Tamir Duberstein
2026-01-22 17:30 ` [PATCH 1/4] scripts: generate_rust_analyzer.py: extract `{build,register}_crate` Tamir Duberstein
2026-01-22 17:30 ` Tamir Duberstein [this message]
2026-01-22 17:30 ` [PATCH 3/4] scripts: generate_rust_analyzer.py: add type hints Tamir Duberstein
2026-01-22 17:30 ` [PATCH 4/4] scripts: generate_rust_analyzer.py: identify crates explicitly Tamir Duberstein
2026-01-28  6:06 ` [PATCH 0/4] scripts: generate_rust_analyzer.py: tidy and add type hints Jesung Yang
2026-01-30 19:56 ` Tamir Duberstein
2026-01-30 20:11   ` Miguel Ojeda
2026-01-30 20:24     ` Tamir Duberstein
2026-01-30 20:31       ` Tamir Duberstein
2026-01-30 20:42         ` Miguel Ojeda
2026-03-02 16:23           ` Tamir Duberstein
2026-01-30 20:32       ` Miguel Ojeda

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260122-rust-analyzer-types-v1-2-29cc2e91dcd5@kernel.org \
    --to=tamird@kernel.org \
    --cc=a.hindborg@kernel.org \
    --cc=aliceryhl@google.com \
    --cc=bjorn3_gh@protonmail.com \
    --cc=boqun.feng@gmail.com \
    --cc=dakr@kernel.org \
    --cc=daniel.almeida@collabora.com \
    --cc=gary@garyguo.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lossin@kernel.org \
    --cc=ojeda@kernel.org \
    --cc=rust-for-linux@vger.kernel.org \
    --cc=tmgross@umich.edu \
    --cc=y.j3ms.n@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.