mbox series

[RFC,v3,00/11] Enable rust support for linux kernel

Message ID 20251119164804.256364-1-Harish.Sadineni@windriver.com
Headers show
Series Enable rust support for linux kernel | expand

Message

Harish Sadineni Nov. 19, 2025, 4:47 p.m. UTC
From: Harish Sadineni <Harish.Sadineni@windriver.com>

v3:
- Addressed v2 review feedback regarding adding dependencies to a variable and assigning them using (?=).
- Moved staging of Rust libraries for the Linux-Yocto 'make rustavailable' step from linux-yocto.inc
  to kernel-yocto.bbclass.
- Made copying of the Rust library directory into tmp/work-shared optional and performed only when
  building rust-native when rust-kernel is present in DISTRO_FEATURES.
- Split rust.cfg into three separate config fragments: rust.cfg, rust-samples.cfg, and rust-debug.cfg.
- Disabled ccache for Linux-Yocto builds when rust-kernel is present in DISTRO_FEATURES
- Added an oe-selftest case for the Linux Rust sample


Summary of changes:

- Patch 1: Extend 'bindgen-cli' to support 'nativesdk', allowing it to be available in the SDK environment.
- Patch 2: Add required dependencies ('clang-native', 'rust-native', 'bindgen-cli-native') to the kernel to support Rust binding generation.
- Patch 3: Install the Rust standard library source ('library/') into `work-shared` and which will be later copied to
           linux-yocto recipe-sysroot-native.
- Patch 4: Added 'rust-kernel' to DISTRO_FEATURES_FILTER_NATIVE and DISTRO_FEATURES_FILTER_NATIVESDK, the 'rust-kernel' feature automatically
           propagates from target DISTRO_FEATURES to native/nativesdk builds
- Patch 5: Stage the Rust sources into `recipe-sysroot-native` for kernel build compatibility, making them visible during native builds.
- Patch 6: Update `kernel-yocto.bbclass` to invoke `make rustavailable` during 'do_kernel_configme', ensuring Rust readiness.
- Patch 7: Add kernel configuration support for Rust (via 'rust.cfg' and 'rust.scc'), enabling the Rust build options in kernel config.
- Patch 8: Fixed buildpaths errors when rust is enabled for kernel by appending --remap-path-prefix to RUST_DEBUG_REMAP
- Patch 9: Disabling ccache when rust-kernel is enabled for linux-yocto.
- Patch 10: Copy Rust kernel sources into kernel-devsrc build directory which will be required while running 'make prepare' in sdk.
- Patch 11: Added an oe-selftest case for the Linux Rust sample.

Benchmark test-result for x86-64:

For bitbake core-image-minimal
+-------------------------------+------------+-----------+-----------+-----------+
| DISTRO_FEATURES               |   real     |   user    |    sys    |  FS usage |
+-------------------------------+------------+-----------+-----------+-----------+
| rust-kernel (enabled)         | 46m1.720s  | 0m28.864s | 0m3.696s  |   58 GB   |
| rust-kernel (disabled)        | 30m1.053s  | 0m20.091s | 0m2.748s  |   33 GB   |
+-------------------------------+------------+-----------+-----------+-----------+

The increased in time & fs usage is due to kernel rust dependencies in
linux-yocto. These will get solved by using pre-built binaries from
meta-rust-bin (WIP).

WIP:

- I am  working on try to use make use of prebuilt binaries for rust and cargo using meta-rust-bin layer which is having compatability issues
  with oe-core master branch.
- rust-out-of-tree kernel module recipe and selftest is in progress (by Yoann Congal)

Test results:
- tested with oe-selftest case for the Linux Rust sample for  x86_64 and arm64.
- tested with rust-out-of-tree kernel module in sdk for x86_64 and arm64.

If everthing is fine, Can we send this as patch?.

Harish Sadineni (9):
  bindgen-cli: extend BBCLASSEXTEND to include nativesdk
  linux-yocto: add clang-native,rust-native and bindgen-cli-native to
    DEPENDS
  rust: install Rust library sources for 'make rustavailable' support
  bitbake.conf: Include "rust-kernel" in native/nativesdk feature
    filters
  kernel-yocto: stage rustlib sources for linux-yocto 'make
    rustavailable' support
  kernel-yocto: add rust support via "make rustavailable" in
    do_kernel_configme
  linux-yocto: enable Rust support in kernel configuration
  kernel-yocto: Fix for buildpaths errors when rust is enabled for
    kernel
  kernel-devsrc: copying rust-kernel soucre to $kerneldir/build

Yoann Congal (2):
  kernel-yocto.bbclass: Disable ccache when rust-kernel is enabled
  selftest/cases/runtime_test: Add test for Linux Rust sample

 meta/classes-recipe/kernel-yocto.bbclass      | 28 +++++++++++++++++++
 meta/conf/bitbake.conf                        |  4 +--
 meta/lib/oeqa/selftest/cases/runtime_test.py  | 24 ++++++++++++++++
 .../bindgen-cli/bindgen-cli_0.72.1.bb         |  2 +-
 meta/recipes-devtools/rust/rust_1.90.0.bb     | 17 +++++++++++
 .../recipes-kernel/linux/files/rust-debug.cfg |  1 +
 .../recipes-kernel/linux/files/rust-debug.scc |  3 ++
 .../linux/files/rust-samples.cfg              |  4 +++
 .../linux/files/rust-samples.scc              |  3 ++
 meta/recipes-kernel/linux/files/rust.cfg      |  3 ++
 meta/recipes-kernel/linux/files/rust.scc      |  3 ++
 meta/recipes-kernel/linux/kernel-devsrc.bb    |  4 +++
 meta/recipes-kernel/linux/linux-yocto.inc     |  2 ++
 meta/recipes-kernel/linux/linux-yocto_6.16.bb |  2 ++
 meta/recipes-kernel/linux/linux-yocto_6.17.bb |  2 ++
 15 files changed, 99 insertions(+), 3 deletions(-)
 create mode 100644 meta/recipes-kernel/linux/files/rust-debug.cfg
 create mode 100644 meta/recipes-kernel/linux/files/rust-debug.scc
 create mode 100644 meta/recipes-kernel/linux/files/rust-samples.cfg
 create mode 100644 meta/recipes-kernel/linux/files/rust-samples.scc
 create mode 100644 meta/recipes-kernel/linux/files/rust.cfg
 create mode 100644 meta/recipes-kernel/linux/files/rust.scc