Skip to content

Commit d1f9280

Browse files
tamirdojeda
authored andcommitted
scripts: generate_rust_analyzer: add missing include_dirs
Commit 8c4555c ("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. [ 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 ] Add the missing bits to improve the developer experience. Fixes: 8c4555c ("scripts: add `generate_rust_analyzer.py`") Signed-off-by: Tamir Duberstein <tamird@gmail.com> Tested-by: Andreas Hindborg <a.hindborg@kernel.org> Link: https://lore.kernel.org/r/20250210-rust-analyzer-bindings-include-v2-1-23dff845edc3@gmail.com [ Slightly reworded title. - Miguel ] Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
1 parent 2e0f91a commit d1f9280

File tree

1 file changed

+20
-20
lines changed

1 file changed

+20
-20
lines changed

scripts/generate_rust_analyzer.py

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -97,27 +97,27 @@ def append_sysroot_crate(
9797
["core", "compiler_builtins"],
9898
)
9999

100-
append_crate(
101-
"bindings",
102-
srctree / "rust"/ "bindings" / "lib.rs",
103-
["core"],
104-
cfg=cfg,
105-
)
106-
crates[-1]["env"]["OBJTREE"] = str(objtree.resolve(True))
100+
def append_crate_with_generated(
101+
display_name,
102+
deps,
103+
):
104+
append_crate(
105+
display_name,
106+
srctree / "rust"/ display_name / "lib.rs",
107+
deps,
108+
cfg=cfg,
109+
)
110+
crates[-1]["env"]["OBJTREE"] = str(objtree.resolve(True))
111+
crates[-1]["source"] = {
112+
"include_dirs": [
113+
str(srctree / "rust" / display_name),
114+
str(objtree / "rust")
115+
],
116+
"exclude_dirs": [],
117+
}
107118

108-
append_crate(
109-
"kernel",
110-
srctree / "rust" / "kernel" / "lib.rs",
111-
["core", "macros", "build_error", "bindings"],
112-
cfg=cfg,
113-
)
114-
crates[-1]["source"] = {
115-
"include_dirs": [
116-
str(srctree / "rust" / "kernel"),
117-
str(objtree / "rust")
118-
],
119-
"exclude_dirs": [],
120-
}
119+
append_crate_with_generated("bindings", ["core"])
120+
append_crate_with_generated("kernel", ["core", "macros", "build_error", "bindings"])
121121

122122
def is_root_crate(build_file, target):
123123
try:

0 commit comments

Comments
 (0)