[PATCH 4/5] bootlinux: generate rust-project.json for rust-analyzer

Daniel Gomez <[email protected]> Fri, 12 Jun 2026 14:18:41 +0200
Newsgroups dev.linux.lists.kdevops
Message-ID <20260612-b4-bootlinux-direct-boot-followups-v1-4-c72537a65d08@samsung.com>
From: Daniel Gomez <[email protected]>

`make rust-analyzer` writes rust-project.json into the build dir;
rust-analyzer LSP looks for it at the source-tree root, so copy it
across after the make step. Lets helix, neovim, and VSCode index
the Rust source the same way clangd indexes C through
compile_commands.json.

Generated-by: Claude AI
Signed-off-by: Daniel Gomez <[email protected]>
---
 .../roles/bootlinux/tasks/build/direct-boot.yml    | 27 ++++++++++++++++++++++
 workflows/linux/Kconfig                            | 10 ++++++++
 2 files changed, 37 insertions(+)

diff --git a/playbooks/roles/bootlinux/tasks/build/direct-boot.yml b/playbooks/roles/bootlinux/tasks/build/direct-boot.yml
index 104def13..938beb33 100644
--- a/playbooks/roles/bootlinux/tasks/build/direct-boot.yml
+++ b/playbooks/roles/bootlinux/tasks/build/direct-boot.yml
@@ -176,6 +176,33 @@
   delegate_to: localhost
   tags: [build-linux]
 
+# `make rust-analyzer` writes rust-project.json to the build dir;
+# rust-analyzer LSP expects it at the source root, so copy it there.
+- name: Generate rust-project.json in the build directory
+  community.general.make:
+    chdir: "{{ bootlinux_direct_boot_tree_path }}"
+    target: rust-analyzer
+    jobs: "{{ bootlinux_direct_boot_nproc.stdout }}"
+    params: "{{ bootlinux_make_params | combine({'O': bootlinux_direct_boot_builddir}) }}"
+  environment: "{{ bootlinux_direct_boot_build_environment }}"
+  when:
+    - bootlinux_direct_boot_rust_analyzer | default(true) | bool
+  run_once: true
+  delegate_to: localhost
+  tags: [build-linux]
+
+- name: Copy rust-project.json into the kernel source tree
+  ansible.builtin.copy:
+    src: "{{ bootlinux_direct_boot_builddir }}/rust-project.json"
+    dest: "{{ bootlinux_direct_boot_tree_path }}/rust-project.json"
+    mode: "0644"
+    remote_src: true
+  when:
+    - bootlinux_direct_boot_rust_analyzer | default(false) | bool
+  run_once: true
+  delegate_to: localhost
+  tags: [build-linux]
+
 # `make install` runs /sbin/installkernel against the controller's
 # /boot and may need root. Copy the image into the destdir by hand.
 - name: Resolve the built kernel image path
diff --git a/workflows/linux/Kconfig b/workflows/linux/Kconfig
index d5d322d0..8c36b3e3 100644
--- a/workflows/linux/Kconfig
+++ b/workflows/linux/Kconfig
@@ -193,6 +193,16 @@ config BOOTLINUX_DIRECT_BOOT_SCRIPTS_GDB
 	  scripts are installed into a distro package, not whether
 	  the build can produce them.
 
+config BOOTLINUX_DIRECT_BOOT_RUST_ANALYZER
+	bool "Generate rust-project.json into the kernel source tree"
+	output yaml
+	default n
+	help
+	  After the kernel build, run `make rust-analyzer` against
+	  the out-of-tree build directory and copy the resulting
+	  rust-project.json to the kernel source tree root for
+	  LSPs to pick up.
+
 endif # BOOTLINUX_DIRECT_BOOT
 
 if BOOTLINUX_9P

-- 
2.54.0