Re: [PATCH] rust-analyzer: update generate_rust_analyzer to pass cfg to macros crate

From: Andreas Hindborg

Date: Sat May 09 2026 - 04:01:57 EST


Hi Tamir,

"Tamir Duberstein" <tamird@xxxxxxxxxx> writes:

> On Fri, May 8, 2026 at 3:04 AM Malte Wechter <maltewechter@xxxxxxxxx> 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@xxxxxxxxx>
>
> 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