rust: fix rust-analyzer configuration for generated files
Subsystems (2)
cover rust: fix rust-analyzer configuration for generated files
The individual patches should be descriptive on their own. They are included in a single series because the second patch uses a function introduced in the first.
I've confirmed this allows me to navigate to symbols defined in generated files as well as to the generated files themselves. I am using an out-of-source build.
---
Tamir Duberstein (2):
scripts: generate_rust_analyzer.py: add missing include_dirs
scripts: generate_rust_analyzer.py: add uapi crate
scripts/generate_rust_analyzer.py | 41 ++++++++++++++++++++------------------- 1 file changed, 21 insertions(+), 20 deletions(-)
---
base-commit: a64dcfb451e254085a7daee5fe51bf22959d52d3
change-id: 20250210-rust-analyzer-bindings-include-531e9dacec8d
Best regards,
Signature · 1 line
Tamir Duberstein <[email protected]>
PATCH 1/2 scripts: generate_rust_analyzer.py: add missing include_dirs
Commit 8c4555ccc55c ("scripts: add generate_rust_analyzer.py") specified OBJTREE for the bindings crate, and source.include_dirs for the kernel crate, likely in an attempt to support out-of-source builds for those crates where the generated files reside in objtree rather than srctree. This was insufficient because both bits of configuration are required for each crate; the result is that rust-analyzer is unable to resolve generated files for either crate in an out-of-source build.
Add the missing bits to improve the developer experience.
--- scripts/generate_rust_analyzer.py | 40 +++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-)
scripts/generate_rust_analyzer.py +20 -20
@@ -85,27 +85,27 @@ def generate_crates(srctree, objtree, sysroot_src, external_src, cfgs): ["core", "compiler_builtins"], ) - append_crate( - "bindings", - srctree / "rust"/ "bindings" / "lib.rs", - ["core"], - cfg=cfg, - ) - crates[-1]["env"]["OBJTREE"] = str(objtree.resolve(True)) + def append_crate_with_generated( + display_name, + deps, + ): + append_crate( + display_name, + srctree / "rust"/ display_name / "lib.rs", + deps, + cfg=cfg, + ) + crates[-1]["env"]["OBJTREE"] = str(objtree.resolve(True)) + crates[-1]["source"] = { + "include_dirs": [ + str(srctree / "rust" / display_name), + str(objtree / "rust") + ], + "exclude_dirs": [], + } - append_crate( - "kernel", - srctree / "rust" / "kernel" / "lib.rs", - ["core", "macros", "build_error", "bindings"], - cfg=cfg, - ) - crates[-1]["source"] = { - "include_dirs": [ - str(srctree / "rust" / "kernel"), - str(objtree / "rust") - ], - "exclude_dirs": [], - } + append_crate_with_generated("bindings", ["core"]) + append_crate_with_generated("kernel", ["core", "macros", "build_error", "bindings"]) def is_root_crate(build_file, target): try:
Signature · 1 line
2.48.1
PATCH 2/2 scripts: generate_rust_analyzer.py: add uapi crate
In reply to Tamir DubersteinCommit 4e1746656839 ("rust: uapi: Add UAPI crate") did not update rust-analyzer to include the new crate.
Add the missing definition to improve the developer experience.
--- scripts/generate_rust_analyzer.py | 1 + 1 file changed, 1 insertion(+)
scripts/generate_rust_analyzer.py +1 -0
@@ -105,6 +105,7 @@ def generate_crates(srctree, objtree, sysroot_src, external_src, cfgs): } append_crate_with_generated("bindings", ["core"]) + append_crate_with_generated("uapi", ["core"]) append_crate_with_generated("kernel", ["core", "macros", "build_error", "bindings"]) def is_root_crate(build_file, target):
Signature · 1 line
2.48.1
Re: [PATCH 2/2] scripts: generate_rust_analyzer.py: add uapi crate
Quoted 26 lines · Tamir Duberstein
Commit
4e1746656839("rust: uapi: Add UAPI crate") did not update rust-analyzer to include the new crate.Add the missing definition to improve the developer experience.
Fixes 4e1746656839 ("rust: uapi: Add UAPI crate")Signed-off-by Tamir Duberstein <[email protected]>--- scripts/generate_rust_analyzer.py | 1 + 1 file changed, 1 insertion(+)scripts/generate_rust_analyzer.py +1
-1@@ -105,6 +105,7 @@ def generate_crates(srctree, objtree, sysroot_src, external_src, cfgs): } append_crate_with_generated("bindings", ["core"]) + append_crate_with_generated("uapi", ["core"]) append_crate_with_generated("kernel", ["core", "macros", "build_error", "bindings"]) def is_root_crate(build_file, target): --
Quoted 2 lines
2.48.1
Oops, missing core dependency on uapi.
Miguel Ojeda
AppliedQuoted 10 lines · Tamir Duberstein
The individual patches should be descriptive on their own. They are included in a single series because the second patch uses a function introduced in the first.
I've confirmed this allows me to navigate to symbols defined in generated files as well as to the generated files themselves. I am using an out-of-source build.
Signed-off-by Tamir Duberstein <[email protected]>
Applied to rust-fixes -- thanks everyone!
[ Originally we were not using OBJTREE in the kernel crate, but
we did pass the variable anyway, so conceptually it could have been there since then.
Regarding include_dirs, it started in kernel before being in mainline because we included the bindings directly there (i.e. there was no bindings crate). However, when that crate got created, we moved the OBJTREE there but not the include_dirs. Nowadays, though, we happen to need the include_dirs also in the kernel crate for generated_arch_static_branch_asm.rs which was not there back then -- Tamir confirms it is indeed required for that reason. - Miguel ]
[ Slightly reworded title. - Miguel ]
[ Slightly reworded title. - Miguel ]
Cheers,
Miguel
Quoted 2 lines · Miguel Ojeda
Applied to
rust-fixes-- thanks everyone!
Sorry, this was intended to be sent to v2 -- resending there.
Cheers,
Miguel