diff mbox series

[1/2] rust: package rust-analyzer as rust-tools-analyzer

Message ID 20261001125630.760962-2-benhur.tessele@est.tech
State Changes Requested
Headers show
Series rust: add rust-analyzer support | expand

Commit Message

Benhur T Oct. 1, 2026, 12:56 p.m. UTC
rust-analyzer is built alongside the other Rust tools (clippy, rustfmt)
but was not installed or packaged. Add a rust-tools-analyzer package and
install it for both the target and nativesdk variants.

Two additional pieces are required for rust-analyzer to be usable:

 - The proc-macro server, rust-analyzer-proc-macro-srv, which
   rust-analyzer looks up under <sysroot>/libexec. Install it into
   ${libexecdir}; without it, analysis of any crate using a derive or
   attribute macro fails with "cannot find proc-macro server in sysroot".

 - The standard library sources, which rust-analyzer analyses from source
   rather than from the compiled rlibs. Add an RDEPENDS on ${PN}-src-lib
   so that core/std items such as println! and derive resolve instead of
   being reported as unresolved macros.

Both binaries link against librustc_driver from the main package, so the
package also RDEPENDS on ${PN}.

Signed-off-by: Benhur Tessele <benhur.tessele@est.tech>
---
 meta/recipes-devtools/rust/rust_1.98.1.bb | 19 ++++++++++++++++---
 1 file changed, 16 insertions(+), 3 deletions(-)
diff mbox series

Patch

diff --git a/meta/recipes-devtools/rust/rust_1.98.1.bb b/meta/recipes-devtools/rust/rust_1.98.1.bb
index 1f4ce5ebdb..d446c60651 100644
--- a/meta/recipes-devtools/rust/rust_1.98.1.bb
+++ b/meta/recipes-devtools/rust/rust_1.98.1.bb
@@ -261,18 +261,21 @@  do_test_compile () {
 
 ALLOW_EMPTY:${PN} = "1"
 
-PACKAGES =+ "${PN}-rustdoc ${PN}-tools-clippy ${PN}-tools-rustfmt ${PN}-src-lib"
+PACKAGES =+ "${PN}-rustdoc ${PN}-tools-clippy ${PN}-tools-rustfmt ${PN}-tools-analyzer ${PN}-src-lib"
 FILES:${PN}-rustdoc = "${bindir}/rustdoc"
 FILES:${PN}-tools-clippy = "${bindir}/cargo-clippy ${bindir}/clippy-driver"
 FILES:${PN}-tools-rustfmt = "${bindir}/rustfmt"
+FILES:${PN}-tools-analyzer = "${bindir}/rust-analyzer ${libexecdir}/rust-analyzer-proc-macro-srv"
 FILES:${PN}-src-lib = "${libdir}/rustlib/src/rust"
 
 RDEPENDS:${PN}-rustdoc = "${PN}"
 RDEPENDS:${PN}-tools-clippy = "${PN}"
 RDEPENDS:${PN}-tools-rustfmt = "${PN}"
+RDEPENDS:${PN}-tools-analyzer = "${PN} ${PN}-src-lib"
 
 SUMMARY:${PN}-tools-clippy = "A collection of lints to catch common mistakes and improve your Rust code"
 SUMMARY:${PN}-tools-rustfmt = "A tool for formatting Rust code according to style guidelines"
+SUMMARY:${PN}-tools-analyzer = "A language server providing IDE features for Rust"
 
 do_install () {
     rust_do_install
@@ -294,14 +297,19 @@  rust_do_install:class-nativesdk() {
     rust_runx install
     rust_runx install clippy
     rust_runx install rustfmt
+    rust_runx install rust-analyzer
     unset PSEUDO_UNLOAD
 
     install -d ${D}${bindir}
-    for i in cargo-clippy clippy-driver rustfmt; do
+    for i in cargo-clippy clippy-driver rustfmt rust-analyzer; do
         cp rust-build/${RUST_BUILD_SYS}/stage2-tools/${RUST_HOST_SYS}/release/$i ${D}${bindir}
         patchelf --set-rpath "\$ORIGIN/../lib" ${D}${bindir}/$i
     done
 
+    install -d ${D}${libexecdir}
+    cp rust-build/${RUST_BUILD_SYS}/stage2-tools/${RUST_HOST_SYS}/release/rust-analyzer-proc-macro-srv ${D}${libexecdir}
+    patchelf --set-rpath "\$ORIGIN/../lib" ${D}${libexecdir}/rust-analyzer-proc-macro-srv
+
     chown root:root ${D}/ -R
     rm ${D}${libdir}/rustlib/uninstall.sh
     rm ${D}${libdir}/rustlib/install.log
@@ -329,12 +337,13 @@  rust_do_install:class-nativesdk() {
 
 FILES:${PN} += "${base_prefix}/environment-setup.d"
 
-EXTRA_TOOLS ?= "cargo-clippy clippy-driver rustfmt"
+EXTRA_TOOLS ?= "cargo-clippy clippy-driver rustfmt rust-analyzer"
 rust_do_install:class-target() {
     export PSEUDO_UNLOAD=1
     rust_runx install
     rust_runx install clippy
     rust_runx install rustfmt
+    rust_runx install rust-analyzer
     unset PSEUDO_UNLOAD
 
     install -d ${D}${bindir}
@@ -343,6 +352,10 @@  rust_do_install:class-target() {
         patchelf --set-rpath "\$ORIGIN/../lib" ${D}${bindir}/$i
     done
 
+    install -d ${D}${libexecdir}
+    cp rust-build/${RUST_BUILD_SYS}/stage2-tools/${RUST_HOST_SYS}/release/rust-analyzer-proc-macro-srv ${D}${libexecdir}
+    patchelf --set-rpath "\$ORIGIN/../lib" ${D}${libexecdir}/rust-analyzer-proc-macro-srv
+
     install -d ${D}${libdir}/rustlib/${RUST_HOST_SYS}
     install -m 0644 ${WORKDIR}/rust-targets/${RUST_HOST_SYS}.json ${D}${libdir}/rustlib/${RUST_HOST_SYS}/target.json
     install -d ${D}${libdir}/rustlib/src/rust