[PATCH v7 02/14] rust: install Rust library sources for 'make rustavailable' support

Harish.Sadineni
2026-03-04T17:44:19Z

From: Harish Sadineni <Harish.Sadineni@windriver.com>

The `make rustavailable` process (1) expects the Rust standard library source files (e.g., `lib.rs`)
to be present in the `library/` directory under `rustlib/src/rust/`.

This patch ensures the required sources are available by:
- Installing the `library/` directory (of size ~50MB) into `${D}${libdir}/rustlib/src/rust` for
making them available during `make rustavailable` for native, target & sdk.
- packaging `${libdir}/rustlib/src/rust` sepearately with `${PN}-src-lib`.

1) See the kernel tree for Documentation/rust/quick-start.rst in the section: Requirements: Building

https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/rust/quick-start.rst#n145

Signed-off-by: Harish Sadineni <Harish.Sadineni@windriver.com>
---
meta/recipes-devtools/rust/rust_1.93.0.bb | 19 ++++++++++++++++++-
1 file changed, 18 insertions(+), 1 deletion(-)

diff --git a/meta/recipes-devtools/rust/rust_1.93.0.bb b/meta/recipes-devtools/rust/rust_1.93.0.bb
index 2be0bd8d89..faafc63c96 100644
--- a/meta/recipes-devtools/rust/rust_1.93.0.bb
+++ b/meta/recipes-devtools/rust/rust_1.93.0.bb
@@ -266,10 +266,11 @@ do_test_compile () {

ALLOW_EMPTY:${PN} = "1"

-PACKAGES =+ "${PN}-rustdoc ${PN}-tools-clippy ${PN}-tools-rustfmt"
+PACKAGES =+ "${PN}-rustdoc ${PN}-tools-clippy ${PN}-tools-rustfmt ${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}-src-lib = "${libdir}/rustlib/src/rust"

RDEPENDS:${PN}-rustdoc = "${PN}"
RDEPENDS:${PN}-tools-clippy = "${PN}"
@@ -286,6 +287,12 @@ rust_do_install() {
rust_runx install
}

+rust_do_install:append:class-native() {
+ install -d ${D}${libdir}/rustlib/src/rust
+ cp -r ${S}/library ${D}${libdir}/rustlib/src/rust
+ find ${D}${libdir}/rustlib/src/rust/ -name "*.sh" -type f -delete
+}
+
rust_do_install:class-nativesdk() {
export PSEUDO_UNLOAD=1
rust_runx install
@@ -316,6 +323,11 @@ rust_do_install:class-nativesdk() {
export CARGO_TARGET_${RUST_HOST_TRIPLE}_RUNNER="\$OECORE_NATIVE_SYSROOT/lib/${SDKLOADER}"
export CC_$RUST_HOST_CC="${CCACHE}${HOST_PREFIX}gcc"
EOF
+
+ install -d ${D}${libdir}/rustlib/src/rust
+ cp -r ${S}/library ${D}${libdir}/rustlib/src/rust
+ find ${D}${libdir}/rustlib/src/rust/ -name "*.sh" -type f -delete
+
}

FILES:${PN} += "${base_prefix}/environment-setup.d"
@@ -336,6 +348,11 @@ rust_do_install:class-target() {

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
+ cp -r ${S}/library ${D}${libdir}/rustlib/src/rust
+ find ${D}${libdir}/rustlib/src/rust -name "*.sh" -type f -delete
+ install -m 0644 ${WORKDIR}/rust-targets/${RUST_HOST_SYS}.json ${D}${libdir}/rustlib/${RUST_HOST_SYS}/${RUST_HOST_SYS}.json
+

chown root:root ${D}/ -R
rm ${D}${libdir}/rustlib/uninstall.sh
--
2.49.0