mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Eliot Courtney <ecourtney@nvidia.com>
To: "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>,
	"Nathan Chancellor" <nathan@kernel.org>,
	"Nicolas Schier" <nsc@kernel.org>
Cc: rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org,
	 linux-kbuild@vger.kernel.org,
	Eliot Courtney <ecourtney@nvidia.com>
Subject: [PATCH 3/6] scripts: generate_rust_analyzer: plumb crate-attrs
Date: Tue, 20 Jan 2026 17:52:52 +0900	[thread overview]
Message-ID: <20260120-ra-fix-v1-3-829e4e92818c@nvidia.com> (raw)
In-Reply-To: <20260120-ra-fix-v1-0-829e4e92818c@nvidia.com>

Add --crate-attrs argument to pass per-crate attributes.

The crate_attrs field was added to rust-analyzer in v0.3.2727 (~1.94.0)
and is silently ignored by older versions, so it's safe to add it.

Signed-off-by: Eliot Courtney <ecourtney@nvidia.com>
---
 rust/Makefile                     | 5 ++++-
 scripts/generate_rust_analyzer.py | 9 +++++++--
 2 files changed, 11 insertions(+), 3 deletions(-)

diff --git a/rust/Makefile b/rust/Makefile
index 2238b0b69197..e6c5108ab625 100644
--- a/rust/Makefile
+++ b/rust/Makefile
@@ -84,9 +84,11 @@ proc_macro2-cfgs := \
     $(if $(call rustc-min-version,108800),proc_macro_span_file proc_macro_span_location)
 
 # Stable since Rust 1.79.0: `feature(proc_macro_byte_character,proc_macro_c_str_literals)`.
+proc_macro2-crate-attrs := feature(proc_macro_byte_character,proc_macro_c_str_literals)
+
 proc_macro2-flags := \
     --cap-lints=allow \
-    -Zcrate-attr='feature(proc_macro_byte_character,proc_macro_c_str_literals)' \
+    -Zcrate-attr='$(proc_macro2-crate-attrs)' \
     $(call cfgs-to-flags,$(proc_macro2-cfgs))
 
 quote-cfgs := \
@@ -575,6 +577,7 @@ rust-analyzer:
 		--cfgs='syn=$(syn-cfgs)' \
 		--editions='core=$(core-edition)' \
 		--editions='quote=$(quote-edition)' \
+		--crate-attrs='proc_macro2=$(proc_macro2-crate-attrs)' \
 		$(realpath $(srctree)) $(realpath $(objtree)) \
 		$(rustc_sysroot) $(RUST_LIB_SRC) $(if $(KBUILD_EXTMOD),$(srcroot)) \
 		> rust-project.json
diff --git a/scripts/generate_rust_analyzer.py b/scripts/generate_rust_analyzer.py
index 17ed5546504b..e8c50812fb9f 100755
--- a/scripts/generate_rust_analyzer.py
+++ b/scripts/generate_rust_analyzer.py
@@ -11,6 +11,7 @@ import pathlib
 import subprocess
 import sys
 
+
 def args_single(args):
     result = {}
     for arg in args:
@@ -26,7 +27,7 @@ def args_crates_cfgs(cfgs):
 
     return crates_cfgs
 
-def generate_crates(srctree, objtree, sysroot_src, external_src, cfgs, editions):
+def generate_crates(srctree, objtree, sysroot_src, external_src, cfgs, editions, crate_attrs):
     # Generate the configuration list.
     generated_cfg = []
     with open(objtree / "include" / "generated" / "rustc_cfg") as fd:
@@ -42,6 +43,7 @@ def generate_crates(srctree, objtree, sysroot_src, external_src, cfgs, editions)
     crates_indexes = {}
     crates_cfgs = args_crates_cfgs(cfgs)
     crates_editions = args_single(editions)
+    crates_crate_attrs = args_crates_cfgs(crate_attrs)
 
     def append_crate(display_name, root_module, deps, cfg=[], is_workspace_member=True, is_proc_macro=False):
         # Miguel Ojeda writes:
@@ -78,6 +80,8 @@ def generate_crates(srctree, objtree, sysroot_src, external_src, cfgs, editions)
             "deps": [{"crate": crates_indexes[dep], "name": dep} for dep in deps],
             "cfg": cfg,
             "edition": edition,
+            # Crate attributes were introduced in 1.94.0 but older versions will silently ignore this.
+            "crate_attrs": crates_crate_attrs.get(display_name, []),
             "env": {
                 "RUST_MODFILE": "This is only for rust-analyzer"
             }
@@ -233,6 +237,7 @@ def main():
     parser.add_argument('--verbose', '-v', action='store_true')
     parser.add_argument('--cfgs', action='append', default=[])
     parser.add_argument('--editions', action='append', default=[])
+    parser.add_argument('--crate-attrs', action='append', default=[])
     parser.add_argument("srctree", type=pathlib.Path)
     parser.add_argument("objtree", type=pathlib.Path)
     parser.add_argument("sysroot", type=pathlib.Path)
@@ -246,7 +251,7 @@ def main():
     )
 
     rust_project = {
-        "crates": generate_crates(args.srctree, args.objtree, args.sysroot_src, args.exttree, args.cfgs, args.editions),
+        "crates": generate_crates(args.srctree, args.objtree, args.sysroot_src, args.exttree, args.cfgs, args.editions, args.crate_attrs),
         "sysroot": str(args.sysroot),
     }
 

-- 
2.52.0


  parent reply	other threads:[~2026-01-20  8:54 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-01-20  8:52 [PATCH 0/6] scripts: generate_rust_analyzer: improve rust-project.json generation Eliot Courtney
2026-01-20  8:52 ` [PATCH 1/6] scripts: generate_rust_analyzer: rename cfg to generated_cfg Eliot Courtney
2026-01-20 15:28   ` Tamir Duberstein
2026-03-02 17:09     ` Tamir Duberstein
2026-01-20  8:52 ` [PATCH 2/6] scripts: generate_rust_analyzer: plumb editions via command line Eliot Courtney
2026-01-20 13:57   ` Miguel Ojeda
2026-01-20 15:28   ` Tamir Duberstein
2026-01-20  8:52 ` Eliot Courtney [this message]
2026-01-20 15:28   ` [PATCH 3/6] scripts: generate_rust_analyzer: plumb crate-attrs Tamir Duberstein
2026-01-20  8:52 ` [PATCH 4/6] scripts: generate_rust_analyzer: plumb common crate-attrs for non-host crates Eliot Courtney
2026-01-20 15:28   ` Tamir Duberstein
2026-01-20  8:52 ` [PATCH 5/6] scripts: generate_rust_analyzer: add pin_init to driver crate deps Eliot Courtney
2026-01-20 15:28   ` Tamir Duberstein
2026-01-20  8:52 ` [PATCH 6/6] scripts: generate_rust_analyzer: move sysroot crates to sysroot_project Eliot Courtney
2026-01-20 15:34   ` Tamir Duberstein
2026-01-21  0:01     ` Jesung Yang
2026-01-22  9:23       ` Eliot Courtney
2026-01-22 11:06         ` Jesung Yang
2026-01-23  5:45           ` Eliot Courtney
2026-01-23 12:08             ` Miguel Ojeda
2026-01-23 12:23               ` Gary Guo
2026-01-23 12:31                 ` Miguel Ojeda
2026-01-20 13:38 ` [PATCH 0/6] scripts: generate_rust_analyzer: improve rust-project.json generation 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=20260120-ra-fix-v1-3-829e4e92818c@nvidia.com \
    --to=ecourtney@nvidia.com \
    --cc=a.hindborg@kernel.org \
    --cc=aliceryhl@google.com \
    --cc=bjorn3_gh@protonmail.com \
    --cc=boqun.feng@gmail.com \
    --cc=dakr@kernel.org \
    --cc=gary@garyguo.net \
    --cc=linux-kbuild@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lossin@kernel.org \
    --cc=nathan@kernel.org \
    --cc=nsc@kernel.org \
    --cc=ojeda@kernel.org \
    --cc=rust-for-linux@vger.kernel.org \
    --cc=tmgross@umich.edu \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®