The Linux Kernel Mailing List
 help / color / mirror / Atom feed
* [PATCH] rust-analyzer: update generate_rust_analyzer to pass cfg to macros crate
@ 2026-05-08  7:04 Malte Wechter
  2026-05-08 13:05 ` Tamir Duberstein
  0 siblings, 1 reply; 5+ messages in thread
From: Malte Wechter @ 2026-05-08  7:04 UTC (permalink / raw)
  To: Miguel Ojeda, Boqun Feng, Gary Guo, Björn Roy Baron,
	Benno Lossin, Andreas Hindborg, Alice Ryhl, Trevor Gross,
	Danilo Krummrich, Tamir Duberstein, Jesung Yang
  Cc: rust-for-linux, linux-kernel, Malte Wechter

pass kernel configurations to the macros crate to prevent rust-analyzer
from marking conditionally included macros as 'never included'.
Add the generated configurations to the macros cfg list
so rust-analyzer correctly hints inclusion and exclusion.

Signed-off-by: Malte Wechter <maltewechter@gmail.com>
---
 scripts/generate_rust_analyzer.py | 1 +
 1 file changed, 1 insertion(+)

diff --git a/scripts/generate_rust_analyzer.py b/scripts/generate_rust_analyzer.py
index d5f9a0ca742c..69990a96522e 100755
--- a/scripts/generate_rust_analyzer.py
+++ b/scripts/generate_rust_analyzer.py
@@ -238,6 +238,7 @@ def generate_crates(
         "macros",
         srctree / "rust" / "macros" / "lib.rs",
         [std, proc_macro, proc_macro2, quote, syn],
+        cfg=generated_cfg,
     )
 
     build_error = append_crate(

---
base-commit: 254f49634ee16a731174d2ae34bc50bd5f45e731
change-id: 20260506-rust-analyzer-macro-22f387f8eff4

Best regards,
-- 
Malte Wechter <maltewechter@gmail.com>


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] rust-analyzer: update generate_rust_analyzer to pass cfg to macros crate
  2026-05-08  7:04 [PATCH] rust-analyzer: update generate_rust_analyzer to pass cfg to macros crate Malte Wechter
@ 2026-05-08 13:05 ` Tamir Duberstein
  2026-05-09  8:01   ` Andreas Hindborg
  0 siblings, 1 reply; 5+ messages in thread
From: Tamir Duberstein @ 2026-05-08 13:05 UTC (permalink / raw)
  To: Malte Wechter
  Cc: Miguel Ojeda, Boqun Feng, Gary Guo, Björn Roy Baron,
	Benno Lossin, Andreas Hindborg, Alice Ryhl, Trevor Gross,
	Danilo Krummrich, Jesung Yang, rust-for-linux, linux-kernel

On Fri, May 8, 2026 at 3:04 AM Malte Wechter <maltewechter@gmail.com> wrote:
>
> pass kernel configurations to the macros crate to prevent rust-analyzer
> from marking conditionally included macros as 'never included'.
> Add the generated configurations to the macros cfg list
> so rust-analyzer correctly hints inclusion and exclusion.
>
> Signed-off-by: Malte Wechter <maltewechter@gmail.com>

Hi Malte, thanks for your patch. I haven't seen this issue. Could you
please help me reproduce what you're seeing?

Directionally I think this patch is incorrect because the macros crate
is a host-side crate and generated_cfg is for target-side cfgs.

Tamir

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] rust-analyzer: update generate_rust_analyzer to pass cfg to macros crate
  2026-05-08 13:05 ` Tamir Duberstein
@ 2026-05-09  8:01   ` Andreas Hindborg
  2026-05-11  5:00     ` Andreas Hindborg
  0 siblings, 1 reply; 5+ messages in thread
From: Andreas Hindborg @ 2026-05-09  8:01 UTC (permalink / raw)
  To: Tamir Duberstein, Malte Wechter
  Cc: Miguel Ojeda, Boqun Feng, Gary Guo, Björn Roy Baron,
	Benno Lossin, Alice Ryhl, Trevor Gross, Danilo Krummrich,
	Jesung Yang, rust-for-linux, linux-kernel

Hi Tamir,

"Tamir Duberstein" <tamird@kernel.org> writes:

> On Fri, May 8, 2026 at 3:04 AM Malte Wechter <maltewechter@gmail.com> wrote:
>>
>> pass kernel configurations to the macros crate to prevent rust-analyzer
>> from marking conditionally included macros as 'never included'.
>> Add the generated configurations to the macros cfg list
>> so rust-analyzer correctly hints inclusion and exclusion.
>>
>> Signed-off-by: Malte Wechter <maltewechter@gmail.com>
>
> Hi Malte, thanks for your patch. I haven't seen this issue. Could you
> please help me reproduce what you're seeing?

We are moving some of the configfs macro logic to procedural
implementations, now that we have syn. We are going to gate the macro on
CONFIG_CONFIGFS_FS. Malte noticed that rust-analyzer does not understand
the gating in the macros crate. rust-analyzer does not know that
CONFIG_CONFIGFS_FS is set, so rust-analyzer does not function at all for
our module:

--- a/rust/macros/lib.rs
+++ b/rust/macros/lib.rs
@@ -15,6 +15,8 @@
 #![cfg_attr(not(CONFIG_RUSTC_HAS_SPAN_FILE), feature(proc_macro_span))]

 mod concat_idents;
+#[cfg(CONFIG_CONFIGFS_FS)]
+mod configfs_attrs;
 mod export;

> Directionally I think this patch is incorrect because the macros crate
> is a host-side crate and generated_cfg is for target-side cfgs.

We might want to differentiate macro implementations based on kernel
configuration, or as in our case, skip compilation of certain macros
when they are not used in the kernel build.


Best regards,
Andreas Hindborg



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] rust-analyzer: update generate_rust_analyzer to pass cfg to macros crate
  2026-05-09  8:01   ` Andreas Hindborg
@ 2026-05-11  5:00     ` Andreas Hindborg
  2026-05-11 14:40       ` Tamir Duberstein
  0 siblings, 1 reply; 5+ messages in thread
From: Andreas Hindborg @ 2026-05-11  5:00 UTC (permalink / raw)
  To: Tamir Duberstein, Malte Wechter
  Cc: Miguel Ojeda, Boqun Feng, Gary Guo, Björn Roy Baron,
	Benno Lossin, Alice Ryhl, Trevor Gross, Danilo Krummrich,
	Jesung Yang, rust-for-linux, linux-kernel

Andreas Hindborg <a.hindborg@kernel.org> writes:

<cut>

>> Directionally I think this patch is incorrect because the macros crate
>> is a host-side crate and generated_cfg is for target-side cfgs.
>
> We might want to differentiate macro implementations based on kernel
> configuration, or as in our case, skip compilation of certain macros
> when they are not used in the kernel build.

Also, the `macros` crate is actually built with these configuration
attributes applied. It is only logical that the `rust-analyzer`
configuration reflect how we build the crate.


Best regards,
Andreas Hindborg



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] rust-analyzer: update generate_rust_analyzer to pass cfg to macros crate
  2026-05-11  5:00     ` Andreas Hindborg
@ 2026-05-11 14:40       ` Tamir Duberstein
  0 siblings, 0 replies; 5+ messages in thread
From: Tamir Duberstein @ 2026-05-11 14:40 UTC (permalink / raw)
  To: Andreas Hindborg
  Cc: Malte Wechter, Miguel Ojeda, Boqun Feng, Gary Guo,
	Björn Roy Baron, Benno Lossin, Alice Ryhl, Trevor Gross,
	Danilo Krummrich, Jesung Yang, rust-for-linux, linux-kernel

On Mon, May 11, 2026 at 1:00 AM Andreas Hindborg <a.hindborg@kernel.org> wrote:
>
> Andreas Hindborg <a.hindborg@kernel.org> writes:
>
> <cut>
>
> >> Directionally I think this patch is incorrect because the macros crate
> >> is a host-side crate and generated_cfg is for target-side cfgs.
> >
> > We might want to differentiate macro implementations based on kernel
> > configuration, or as in our case, skip compilation of certain macros
> > when they are not used in the kernel build.
>
> Also, the `macros` crate is actually built with these configuration
> attributes applied. It is only logical that the `rust-analyzer`
> configuration reflect how we build the crate.

Hi Andreas,

These justifications should be in the commit message. I agree that the
`macros` crate is receiving those cfgs, that was added in 36174d16
("rust: kunit: support KUnit-mapped `assert!` macros in `#[test]`s") -
this should also be mentioned in the commit message please.

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2026-05-11 14:41 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-05-08  7:04 [PATCH] rust-analyzer: update generate_rust_analyzer to pass cfg to macros crate Malte Wechter
2026-05-08 13:05 ` Tamir Duberstein
2026-05-09  8:01   ` Andreas Hindborg
2026-05-11  5:00     ` Andreas Hindborg
2026-05-11 14:40       ` Tamir Duberstein

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox