Skip to contentSkip to conversation

rust-analyzer: update generate_rust_analyzer to pass cfg to macros crate

PATCH Superseded Malte Wechter 2 participants 2 messages May 20 – Jun 3

Subsystems (2)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 rust-analyzer: update generate_rust_analyzer to pass cfg to macros crate

The configuration passed to rust-analyzer for the macros create is different from the configuration used to build the crate. Update rust-analyzer configuration for the macros crate to reflect the settings used to compile the crate. Without this change, rust-analyzer does not understand conditional compilation gated by configuration redicates based on the CONFIG_*configuration values in the macros crate.

---
We are currently moving the 'configfs_attrs' macro to a procedual implementation,
with this we wanted to gate the macro on CONFIG_CONFIGFS_FS, since the macros crate is
build with these configurations since 36174d16 ("rust: kunit: support KUnit-mapped assert! macros in #[test]s"). It compiles but rust-analyzer does not reflect this as adding:

    #[cfg(CONFIG_CONFIGFS_FS)]
    mod configfs_attrs;

will _never_ mark configfs_attrs module as included since the cfg's are not passed to the macros crate.

Changes in v2:
- Update commit message
- Link to v1: https://lore.kernel.org/r/[email protected]

---
 scripts/generate_rust_analyzer.py | 1 +
 1 file changed, 1 insertion(+)
scripts/generate_rust_analyzer.py +1 -0
index d5f9a0ca742c..69990a96522e 100755
@@ -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,

Signature · 1 line
Malte Wechter <[email protected]>
maintainer
#1 lore raw
Quoted 9 lines · Malte Wechter

The configuration passed to rust-analyzer for the macros create is different from the configuration used to build the crate. Update rust-analyzer configuration for the macros crate to reflect the settings used to compile the crate. Without this change, rust-analyzer does not understand conditional compilation gated by configuration redicates based on the CONFIG_*configuration values in the macros crate.

Quoted 6 lines

---
We are currently moving the 'configfs_attrs' macro to a procedual implementation,
with this we wanted to gate the macro on CONFIG_CONFIGFS_FS, since the macros crate is
build with these configurations since 36174d16 ("rust: kunit: support KUnit-mapped assert! macros in #[test]s"). It compiles but rust-analyzer does not reflect this as adding:

Should this patch have a Fixes tag mentioning 36174d16?