mbox series

[RFC,0/7] Enable rust support for linux kernel

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

Message

Harish Sadineni Oct. 23, 2025, 11:25 a.m. UTC
From: Harish Sadineni <Harish.Sadineni@windriver.com>

This patch series introduces Rust support into the linux-yocto kernel recipe
and related build infrastructure in the Yocto Project. The goal is to enable
building the Linux kernel with Rust components and provide support for
building kernel module which is written in rust inside sdk. 

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', '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: Stage the Rust sources into `recipe-sysroot-native` for kernel build compatibility, making them visible during native builds.
- Patch 5: Update `kernel-yocto.bbclass` to invoke `make rustavailable` during 'do_kernel_configme', ensuring Rust readiness.
- Patch 6: Add kernel configuration support for Rust (via 'rust.cfg' and 'rust.scc'), enabling the Rust build options in kernel config.
- patch 7: Copy Rust kernel sources into kernel-devsrc build directory which will be required while runnig 'make prepare' in sdk.

WIP - need inputs:
1. In patch-3, rust sources are copied from ${RUSTSRC} to ${TMPDIR}/work-shared, which is redundant and improving it in
 more optimized way by extracting rust directly into ${TMPDIR}/work-shared and then use it for both rust & linux-yocto recipes.
 
2. In patch-6, We've suppressed a few build path QA issues with INSANE_SKIP.
We have tried fixing those using DEBUG_PREFIX_MAP & --remap-path-prefix but unable to resolve it.
Are there any flags for kernel or any other inputs?
 
3. If rust.cfg & rust.scc changes are ok, we will send kernel configuration fragment to yocto-kernel-cache.

With above considerations, We did a successful build of Enabling rust in linux kernel and 
Tested a rust-out-of-tree kernel module in sdk for x86-64 & arm64 architectures.

Harish Sadineni (7):
  bindgen-cli: extend BBCLASSEXTEND to include nativesdk
  linux-yocto: add clang-native and bindgen-cli-native to DEPENDS
  rust: install Rust standard library sources for make rustavailable
    support
  rust: 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-devsrc: copying rust-kernel soucre  to $kerneldir/build

 meta/classes-recipe/kernel-yocto.bbclass      |  4 ++++
 .../bindgen-cli/bindgen-cli_0.72.1.bb         |  2 +-
 meta/recipes-devtools/rust/rust_1.90.0.bb     | 13 +++++++++++-
 meta/recipes-kernel/linux/files/rust.cfg      | 20 +++++++++++++++++++
 meta/recipes-kernel/linux/files/rust.scc      |  1 +
 meta/recipes-kernel/linux/kernel-devsrc.bb    |  1 +
 meta/recipes-kernel/linux/linux-yocto.inc     |  7 +++++++
 meta/recipes-kernel/linux/linux-yocto_6.16.bb |  4 ++++
 8 files changed, 50 insertions(+), 2 deletions(-)
 create mode 100644 meta/recipes-kernel/linux/files/rust.cfg
 create mode 100644 meta/recipes-kernel/linux/files/rust.scc

Comments

Bruce Ashfield Oct. 23, 2025, 1 p.m. UTC | #1
On Thu, Oct 23, 2025 at 7:27 AM Sadineni, Harish via lists.openembedded.org
<Harish.Sadineni=windriver.com@lists.openembedded.org> wrote:

> From: Harish Sadineni <Harish.Sadineni@windriver.com>
>
> This patch series introduces Rust support into the linux-yocto kernel
> recipe
> and related build infrastructure in the Yocto Project. The goal is to
> enable
> building the Linux kernel with Rust components and provide support for
> building kernel module which is written in rust inside sdk.
>
> 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',
> '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: Stage the Rust sources into `recipe-sysroot-native` for kernel
> build compatibility, making them visible during native builds.
> - Patch 5: Update `kernel-yocto.bbclass` to invoke `make rustavailable`
> during 'do_kernel_configme', ensuring Rust readiness.
> - Patch 6: Add kernel configuration support for Rust (via 'rust.cfg' and
> 'rust.scc'), enabling the Rust build options in kernel config.
> - patch 7: Copy Rust kernel sources into kernel-devsrc build directory
> which will be required while runnig 'make prepare' in sdk.
>
>
On my first pass through, things look to be in reasonable shape with
respect to patch
splitting, and clarity.

But the number one item is: this cannot be default, it must be opt-in and
controlled via
a distro feature.

When we get to the point that the kernel cannot be built and functional
without rust,
then of course we'll revisit. But we aren't to that point now.

Before we inflict the overhead and dependencies of rust and related tools
on the kernel,
we have to have binary / prebuilt components available.

Cheers,

Bruce



> WIP - need inputs:
> 1. In patch-3, rust sources are copied from ${RUSTSRC} to
> ${TMPDIR}/work-shared, which is redundant and improving it in
>  more optimized way by extracting rust directly into ${TMPDIR}/work-shared
> and then use it for both rust & linux-yocto recipes.
>
> 2. In patch-6, We've suppressed a few build path QA issues with
> INSANE_SKIP.
> We have tried fixing those using DEBUG_PREFIX_MAP & --remap-path-prefix
> but unable to resolve it.
> Are there any flags for kernel or any other inputs?
>
> 3. If rust.cfg & rust.scc changes are ok, we will send kernel
> configuration fragment to yocto-kernel-cache.
>
> With above considerations, We did a successful build of Enabling rust in
> linux kernel and
> Tested a rust-out-of-tree kernel module in sdk for x86-64 & arm64
> architectures.
>
> Harish Sadineni (7):
>   bindgen-cli: extend BBCLASSEXTEND to include nativesdk
>   linux-yocto: add clang-native and bindgen-cli-native to DEPENDS
>   rust: install Rust standard library sources for make rustavailable
>     support
>   rust: 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-devsrc: copying rust-kernel soucre  to $kerneldir/build
>
>  meta/classes-recipe/kernel-yocto.bbclass      |  4 ++++
>  .../bindgen-cli/bindgen-cli_0.72.1.bb         |  2 +-
>  meta/recipes-devtools/rust/rust_1.90.0.bb     | 13 +++++++++++-
>  meta/recipes-kernel/linux/files/rust.cfg      | 20 +++++++++++++++++++
>  meta/recipes-kernel/linux/files/rust.scc      |  1 +
>  meta/recipes-kernel/linux/kernel-devsrc.bb    |  1 +
>  meta/recipes-kernel/linux/linux-yocto.inc     |  7 +++++++
>  meta/recipes-kernel/linux/linux-yocto_6.16.bb |  4 ++++
>  8 files changed, 50 insertions(+), 2 deletions(-)
>  create mode 100644 meta/recipes-kernel/linux/files/rust.cfg
>  create mode 100644 meta/recipes-kernel/linux/files/rust.scc
>
> --
> 2.49.0
>
>
> -=-=-=-=-=-=-=-=-=-=-=-
> Links: You receive all messages sent to this group.
> View/Reply Online (#225236):
> https://lists.openembedded.org/g/openembedded-core/message/225236
> Mute This Topic: https://lists.openembedded.org/mt/115908706/1050810
> Group Owner: openembedded-core+owner@lists.openembedded.org
> Unsubscribe: https://lists.openembedded.org/g/openembedded-core/unsub [
> bruce.ashfield@gmail.com]
> -=-=-=-=-=-=-=-=-=-=-=-
>
>
El Mehdi YOUNES Oct. 23, 2025, 2:57 p.m. UTC | #2
Hi Harish, Hi All,

Sorry this message was first sent in private by mistake.

Le 23/10/2025 à 13:25, Harish.Sadineni@windriver.com a écrit :
> From: Harish Sadineni<Harish.Sadineni@windriver.com>
>
> This patch series introduces Rust support into the linux-yocto kernel recipe
> and related build infrastructure in the Yocto Project. The goal is to enable
> building the Linux kernel with Rust components and provide support for
> building kernel module which is written in rust inside sdk.

Thanks for this patch series and your work on this topic! I've also been 
working
on enabling Rust in the Yocto kernel recently and have some ideas I'd 
like to share.
Overall, your approach seems to be heading in the same direction as mine.
However, my main general comment is that these changes don't appear to
be optional. In my view, all these additions (dependencies, build flags,
source installation) should only take effect if the user explicitly wants
to enable Rust support in the kernel.
To achieve this, I've made all my modifications conditional using
bb.utils.contains('DISTRO_FEATURES', 'rust-kernel', ...) checks in the
relevant recipes and classes. This way, a user only needs to add
DISTRO_FEATURES:append = " rust-kernel" to their configuration, and
everything needed for Rust kernel support is automatically enabled. This
avoids adding unnecessary dependencies or build steps for users who don't
need Rust
>
> 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', '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: Stage the Rust sources into `recipe-sysroot-native` for kernel build compatibility, making them visible during native builds.
> - Patch 5: Update `kernel-yocto.bbclass` to invoke `make rustavailable` during 'do_kernel_configme', ensuring Rust readiness.
> - Patch 6: Add kernel configuration support for Rust (via 'rust.cfg' and 'rust.scc'), enabling the Rust build options in kernel config.
> - patch 7: Copy Rust kernel sources into kernel-devsrc build directory which will be required while runnig 'make prepare' in sdk.
>
> WIP - need inputs:
> 1. In patch-3, rust sources are copied from ${RUSTSRC} to ${TMPDIR}/work-shared, which is redundant and improving it in
>   more optimized way by extracting rust directly into ${TMPDIR}/work-shared and then use it for both rust & linux-yocto recipes.

Regarding WIP point 1 about copying the Rust sources: I agree the 
current mechanism
seems a bit confusing. I'll provide more detailed feedback on the 
specific response after test,
but my initial thought is that we should only need to copy the sources once.
Perhaps we can ensure they are placed in the correct final location and 
then point
the kernel build system to it using the RUST_LIB_SRC variable passed via 
EXTRA_OEMAKE.
>   
> 2. In patch-6, We've suppressed a few build path QA issues with INSANE_SKIP.
> We have tried fixing those using DEBUG_PREFIX_MAP & --remap-path-prefix but unable to resolve it.
> Are there any flags for kernel or any other inputs?

For the 'buildpaths' QA issue, I solved it without INSANE_SKIP by :
- Inherit rust-common in kernel-yocto.bbclass.
- Append --remap-path-prefix for ${S}, ${B}, and ${STAGING_DIR_NATIVE}
   to RUST_DEBUG_REMAP.
- Pass ${RUST_DEBUG_REMAP} via KRUSTFLAGS in EXTRA_OEMAKE.
And of course, all these additions in the recipes/classes are conditional
   on bb.utils.contains('DISTRO_FEATURES', 'rust-kernel', ...)
>   
> 3. If rust.cfg & rust.scc changes are ok, we will send kernel configuration fragment to yocto-kernel-cache.
>
> With above considerations, We did a successful build of Enabling rust in linux kernel and
> Tested a rust-out-of-tree kernel module in sdk for x86-64 & arm64 architectures.

Thanks again for sharing this work! I'll provide more detailed comments 
and ideas
on the individual patches, and potentially more after testing, but this 
is definitely a very good start.
Best regards
El Mehdi
>
> Harish Sadineni (7):
>    bindgen-cli: extend BBCLASSEXTEND to include nativesdk
>    linux-yocto: add clang-native and bindgen-cli-native to DEPENDS
>    rust: install Rust standard library sources for make rustavailable
>      support
>    rust: 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-devsrc: copying rust-kernel soucre  to $kerneldir/build
>
>   meta/classes-recipe/kernel-yocto.bbclass      |  4 ++++
>   .../bindgen-cli/bindgen-cli_0.72.1.bb         |  2 +-
>   meta/recipes-devtools/rust/rust_1.90.0.bb     | 13 +++++++++++-
>   meta/recipes-kernel/linux/files/rust.cfg      | 20 +++++++++++++++++++
>   meta/recipes-kernel/linux/files/rust.scc      |  1 +
>   meta/recipes-kernel/linux/kernel-devsrc.bb    |  1 +
>   meta/recipes-kernel/linux/linux-yocto.inc     |  7 +++++++
>   meta/recipes-kernel/linux/linux-yocto_6.16.bb |  4 ++++
>   8 files changed, 50 insertions(+), 2 deletions(-)
>   create mode 100644 meta/recipes-kernel/linux/files/rust.cfg
>   create mode 100644 meta/recipes-kernel/linux/files/rust.scc