Skip to contentSkip to conversation

rust: add rust-analyzer support

PATCH Superseded Benhur Tessele 3 participants 9 messages Oct 1 – Oct 2

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover rust: add rust-analyzer support

rust-analyzer is built as part of the Rust tools but was neither installed nor packaged. This series packages it and wires it into the Rust SDK next to clippy and rustfmt.

Patch 1 adds a rust-tools-analyzer package for the target and nativesdk variants. Beyond the frontend binary it also ships the proc-macro server and depends on the standard library sources, both of which are required for rust-analyzer to actually function.

Patch 2 adds it to the cross-canadian toolchain so that an SDK built with SDK_FEATURES = "rust" provides rust-analyzer out of the box.

Testing:
- Patches validated with patchset.
- Built an SDK with SDK_FEATURES = "rust", installed it in a container, and confirmed rust-analyzer resolves the standard library and expands proc-macros end to end: diagnostics/analysis-stats on a crate using a derive macro succeed, with the proc-macro server started from <sysroot>/libexec.
- Built core-image-minimal with rust-tools-analyzer installed, booted it under qemu, and confirmed the rust-analyzer frontend and the rust-analyzer-proc-macro-srv binary are present with their libraries resolving.

Benhur Tessele (2):
rust: package rust-analyzer as rust-tools-analyzer packagegroup-rust-cross-canadian: add rust-analyzer to the SDK

 .../packagegroup-rust-cross-canadian.bb       |  1 +
 meta/recipes-devtools/rust/rust_1.98.1.bb     | 19 ++++++++++++++++---
 2 files changed, 17 insertions(+), 3 deletions(-)
Signature · 1 line
2.43.0
#1 lore raw

PATCH 1/2 rust: package rust-analyzer as rust-tools-analyzer

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}.

---
 meta/recipes-devtools/rust/rust_1.98.1.bb | 19 ++++++++++++++++---
 1 file changed, 16 insertions(+), 3 deletions(-)
meta/recipes-devtools/rust/rust_1.98.1.bb +16 -3
index 1f4ce5ebdb..d446c60651 100644
@@ -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
Signature · 1 line
2.43.0
#2 lore raw

PATCH 2/2 packagegroup-rust-cross-canadian: add rust-analyzer to the SDK

In reply to Benhur Tessele

The Rust cross-canadian toolchain already ships clippy and rustfmt as host tools. Now that rust-analyzer is packaged, add nativesdk-rust-tools-analyzer so an SDK built with SDK_FEATURES = "rust" provides rust-analyzer as well.

The standard library sources it needs are pulled in automatically via the package's RDEPENDS on nativesdk-rust-src-lib.

---
 .../packagegroups/packagegroup-rust-cross-canadian.bb            | 1 +
 1 file changed, 1 insertion(+)
meta/recipes-core/packagegroups/packagegroup-rust-cross-canadian.bb +1 -0
index c73c8d3333..54b39189b4 100644
@@ -17,5 +17,6 @@ RDEPENDS:${PN} = " \
     nativesdk-cargo \
     nativesdk-rust-tools-clippy \
     nativesdk-rust-tools-rustfmt \
+    nativesdk-rust-tools-analyzer \
 "
 
Signature · 1 line
2.43.0
#3 lore raw
In reply to Benhur Tessele
Quoted 24 lines · Benhur T

rust-analyzer is built as part of the Rust tools but was neither installed nor packaged. This series packages it and wires it into the Rust SDK next to clippy and rustfmt.

Patch 1 adds a rust-tools-analyzer package for the target and nativesdk variants. Beyond the frontend binary it also ships the proc-macro server and depends on the standard library sources, both of which are required for rust-analyzer to actually function.

Patch 2 adds it to the cross-canadian toolchain so that an SDK built with SDK_FEATURES = "rust" provides rust-analyzer out of the box.

Testing:
- Patches validated with patchset.
- Built an SDK with SDK_FEATURES = "rust", installed it in a container, and confirmed rust-analyzer resolves the standard library and expands proc-macros end to end: diagnostics/analysis-stats on a crate using a derive macro succeed, with the proc-macro server started from <sysroot>/libexec.
- Built core-image-minimal with rust-tools-analyzer installed, booted it under qemu, and confirmed the rust-analyzer frontend and the rust-analyzer-proc-macro-srv binary are present with their libraries resolving.

Quoted 7 lines

Benhur Tessele (2):
rust: package rust-analyzer as rust-tools-analyzer packagegroup-rust-cross-canadian: add rust-analyzer to the SDK

 .../packagegroup-rust-cross-canadian.bb       |  1 +
 meta/recipes-devtools/rust/rust_1.98.1.bb     | 19 ++++++++++++++++---
 2 files changed, 17 insertions(+), 3 deletions(-)

Hi Benhur,

Thanks for your patch.

I believe this is breaking build on some platforms. Maybe all ARM 32 bits?

ERROR: rust-1.98.1-r0 do_install: Execution of '/srv/pokybuild/yocto-worker/beaglebone-alt/build/build/tmp/work/cortexa8t2hf-neon-poky-linux-gnueabi/rust/1.98.1/temp/run.do_install.3194208' failed with exit code 1
...

| error[E0658]: use of unstable library feature `stdarch_arm_neon_intrinsics`
|   --> /rust/deps/simd-adler32-0.3.9/src/imp/neon.rs:23:7
|    |
| 23 |   use core::arch::arm::*;
|    |       ^^^^^^^^^^^^^^^
|    |
|    = note: see issue #111800 <https://github.com/rust-lang/rust/issues/111800> for more information
|    = help: add `#![feature(stdarch_arm_neon_intrinsics)]` to the crate attributes to enable
|    = note: this compiler was built on 2026-09-01; consider upgrading it if it is out of date
...
| -------------
| error: could not compile `simd-adler32` (lib) due to 67 previous errors
| warning: build failed, waiting for other jobs to finish...

...

https://autobuilder.yoctoproject.org/valkyrie/#/builders/10/builds/4734
https://autobuilder.yoctoproject.org/valkyrie/#/builders/74/builds/4706

Can you have a look at the issue?

Thanks,
Mathieu

Signature · 3 lines
Mathieu Dubois-Briand, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
#4 lore raw
Quoted 55 lines · Mathieu Dubois-Briand
Quoted 24 lines · Benhur T

rust-analyzer is built as part of the Rust tools but was neither installed nor packaged. This series packages it and wires it into the Rust SDK next to clippy and rustfmt.

Patch 1 adds a rust-tools-analyzer package for the target and nativesdk variants. Beyond the frontend binary it also ships the proc-macro server and depends on the standard library sources, both of which are required for rust-analyzer to actually function.

Patch 2 adds it to the cross-canadian toolchain so that an SDK built with SDK_FEATURES = "rust" provides rust-analyzer out of the box.

Testing:
- Patches validated with patchset.
- Built an SDK with SDK_FEATURES = "rust", installed it in a container, and confirmed rust-analyzer resolves the standard library and expands proc-macros end to end: diagnostics/analysis-stats on a crate using a derive macro succeed, with the proc-macro server started from <sysroot>/libexec.
- Built core-image-minimal with rust-tools-analyzer installed, booted it under qemu, and confirmed the rust-analyzer frontend and the rust-analyzer-proc-macro-srv binary are present with their libraries resolving.

Quoted 7 lines

Benhur Tessele (2):
rust: package rust-analyzer as rust-tools-analyzer packagegroup-rust-cross-canadian: add rust-analyzer to the SDK

 .../packagegroup-rust-cross-canadian.bb       |  1 +
 meta/recipes-devtools/rust/rust_1.98.1.bb     | 19 ++++++++++++++++---
 2 files changed, 17 insertions(+), 3 deletions(-)

Hi Benhur,

Thanks for your patch.

I believe this is breaking build on some platforms. Maybe all ARM 32 bits?

ERROR: rust-1.98.1-r0 do_install: Execution of '/srv/pokybuild/yocto-worker/beaglebone-alt/build/build/tmp/work/cortexa8t2hf-neon-poky-linux-gnueabi/rust/1.98.1/temp/run.do_install.3194208' failed with exit code 1
...

Quoted 9 lines

error[E0658]: use of unstable library feature stdarch_arm_neon_intrinsics
--> /rust/deps/simd-adler32-0.3.9/src/imp/neon.rs:23:7

   |
23 |   use core::arch::arm::*;
   |       ^^^^^^^^^^^^^^^
   |

= note: see issue #111800 <https://github.com/rust-lang/rust/issues/111800> for more information = help: add #![feature(stdarch_arm_neon_intrinsics)] to the crate attributes to enable = note: this compiler was built on 2026-09-01; consider upgrading it if it is out of date

...

Quoted 3 lines

-------------
error: could not compile simd-adler32 (lib) due to 67 previous errors
warning: build failed, waiting for other jobs to finish...

Quoted 6 lines

...

https://autobuilder.yoctoproject.org/valkyrie/#/builders/10/builds/4734
https://autobuilder.yoctoproject.org/valkyrie/#/builders/74/builds/4706

Can you have a look at the issue?

One thing that's concerning here: We're seeing a compiler error message during do_install. That suggests we're missing a build step in do_compile, as things should already be built by the time we get to do_install.

That may be a pre-existing issue for the rust recipe, if it is then we should make sure there is a bug filed for it.

Best regards,

Signature · 1 line
Paul Barker
author
#5 lore raw
Quoted 4 lines

I believe this is breaking build on some platforms. Maybe all ARM 32 bits?

ERROR: rust-1.98.1-r0 do_install: Execution of

'/srv/pokybuild/yocto-worker/beaglebone-alt/build/build/tmp/work/cortexa8t2hf-neon-poky-linux-gnueabi/rust/1.98.1/temp/run.do_install.3194208' failed with exit code 1

Quoted 2 lines

...
| error[E0658]: use of unstable library feature

stdarch_arm_neon_intrinsics

Quoted 6 lines
|   --> /rust/deps/simd-adler32-0.3.9/src/imp/neon.rs:23:7
|    |
| 23 |   use core::arch::arm::*;
|    |       ^^^^^^^^^^^^^^^
|    |
|    = note: see issue #111800

<https://github.com/rust-lang/rust/issues/111800> for more information

Quoted 1 line

| = help: add #![feature(stdarch_arm_neon_intrinsics)] to the

crate attributes to enable

Quoted 1 line

| = note: this compiler was built on 2026-09-01; consider upgrading

it if it is out of date

Quoted 7 lines

...

| -------------
| error: could not compile `simd-adler32` (lib) due to 67 previous errors
| warning: build failed, waiting for other jobs to finish...

...

Can you have a look at the issue?

@Mathieu, thanks for the feedback, yeah I could replicate it when targeting "machine/beaglebone-yocto", seems like rust-analyzer is resolving a newer simd-adler32 (0.3.9) than the rustc/std build (0.3.7) which fails on NEON arm32 during build. It might be that the std/compiler build runs with full unstable-feature access, whereas the analyzer tool does not. Removing the target installation of the tool seemed to fix the problem.

Quoted 7 lines

One thing that's concerning here: We're seeing a compiler error message during do_install. That suggests we're missing a build step in do_compile, as things should already be built by the time we get to do_install.

That may be a pre-existing issue for the rust recipe, if it is then we should make sure there is a bug filed for it.

@Paul, I agree this is pre-existing, the rust recipe has an empty do_compile(), and all building happens in do_install via "rust_runx install", which runs x.py install (build + install in one step).

Quoted 5 lines

We definitely want to take new features that people will use, but we should avoid enabling things just for the sake of it if there is no clear use case.

Are you using rust-analyzer from the SDK?

Yes, so based on the conversation above seems like the most reasonable is to install only for class-nativesdk.

#6 lore raw
In reply to Benhur Tessele
Quoted 24 lines · Benhur Tessele

rust-analyzer is built as part of the Rust tools but was neither installed nor packaged. This series packages it and wires it into the Rust SDK next to clippy and rustfmt.

Patch 1 adds a rust-tools-analyzer package for the target and nativesdk variants. Beyond the frontend binary it also ships the proc-macro server and depends on the standard library sources, both of which are required for rust-analyzer to actually function.

Patch 2 adds it to the cross-canadian toolchain so that an SDK built with SDK_FEATURES = "rust" provides rust-analyzer out of the box.

Testing:
- Patches validated with patchset.
- Built an SDK with SDK_FEATURES = "rust", installed it in a container, and confirmed rust-analyzer resolves the standard library and expands proc-macros end to end: diagnostics/analysis-stats on a crate using a derive macro succeed, with the proc-macro server started from <sysroot>/libexec.
- Built core-image-minimal with rust-tools-analyzer installed, booted it under qemu, and confirmed the rust-analyzer frontend and the rust-analyzer-proc-macro-srv binary are present with their libraries resolving.

Quoted 3 lines

Benhur Tessele (2):
rust: package rust-analyzer as rust-tools-analyzer packagegroup-rust-cross-canadian: add rust-analyzer to the SDK

Hi,

Two quick questions here:

1) What's the intended use case for rust-analyzer, particularly on the target? I think we need at least a brief reason why it's worth enabling this.

2) What impact does this have on the build and package creation time for rust?

Best regards,

Signature · 1 line
Paul Barker
author
#7 lore raw
Quoted 6 lines

1) What's the intended use case for rust-analyzer, particularly on the target? I think we need at least a brief reason why it's worth enabling this.

2) What impact does this have on the build and package creation time for rust?

Hi Paul, thanks for the relevant comments.

1) Short answer: I don't know. I agree with you seems odd, but I just followed what's already done for the other tools (clippy, rustfmt). I'm more than happy to remove it from target is that's the right approach.

2) On my build environment (poky/qemux86-64) there's a build time increase.

master
|- do_install: Elapsed time: 524.36 seconds
`- do_package: Elapsed time: 16.49 seconds

with my patches
|- do_install: Elapsed time: 619.82 seconds
`- do_package: Elapsed time: 17.16 seconds

Best regards,
Ben

#8 lore raw
Quoted 11 lines · Benhur T
Quoted 6 lines

1) What's the intended use case for rust-analyzer, particularly on the target? I think we need at least a brief reason why it's worth enabling this.

2) What impact does this have on the build and package creation time for rust?

Hi Paul, thanks for the relevant comments.

1) Short answer: I don't know. I agree with you seems odd, but I just followed what's already done for the other tools (clippy, rustfmt). I'm more than happy to remove it from target is that's the right approach.

I think we need to be careful here. Adding more features is great, but they often also add complexity and maintenance burden. Even simple addition of a new component within an existing recipe is one more thing that can fail, as seen in Mathieu's reply [1].

[1]: https://lore.kernel.org/all/[email protected]/

We definitely want to take new features that people will use, but we should avoid enabling things just for the sake of it if there is no clear use case.

Are you using rust-analyzer from the SDK?

Quoted 10 lines

2) On my build environment (poky/qemux86-64) there's a build time increase.

master

Quoted 1 line

- do_install: Elapsed time: 524.36 seconds

`- do_package: Elapsed time: 16.49 seconds

with my patches

Quoted 1 line

- do_install: Elapsed time: 619.82 seconds

`- do_package: Elapsed time: 17.16 seconds

This is a noticeable jump. We should put this behind a PACKAGECONFIG option which is disabled by default.

Best regards,

Signature · 1 line
Paul Barker