public inbox for openembedded-core@lists.openembedded.org
 help / color / mirror / Atom feed
* [PATCH v2 00/15] Enable rust support for linux kernel
@ 2025-12-30 14:15 Harish.Sadineni
  2025-12-30 14:15 ` [PATCH v2 01/15] bindgen-cli: extend BBCLASSEXTEND to include nativesdk Harish.Sadineni
                   ` (14 more replies)
  0 siblings, 15 replies; 33+ messages in thread
From: Harish.Sadineni @ 2025-12-30 14:15 UTC (permalink / raw)
  To: openembedded-core
  Cc: Randy.MacLeod, Sundeep.Kokkonda, bruce.ashfield, yoann.congal,
	elmehdi.younes

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

v2:
- combined [PATCH 05/16][0] & [PATCH 06/16][1] from v1.
- updated commit message and added in code comments for patch "[PATCH 09/15] kernel-devsrc: copying 
  rust-kernel source to $kerneldir/build"

[0] https://lists.openembedded.org/g/openembedded-core/message/228559
[1] https://lists.openembedded.org/g/openembedded-core/message/228560

v1:
The previous series was RFC v4, "Enable Rust support for Linux kernel"
(https://lists.openembedded.org/g/openembedded-core/message/226623).

In addition, Yoann Congal posted RFC v2, "Kernel Rust out-of-tree module support"
(https://lists.openembedded.org/g/openembedded-core/message/227281), which builds on top of RFC v4.

The current patch series is a unified version that combines both efforts.
Compared to the earlier series, the main changes are:

-Kernel configuration fragments have been moved to yocto-kernel-cache.
-The kernel fragments have been removed from SRC_URI and from the files directory previously stored under
 recipes-kernel/linux/files.
-Updated the "[PATCH 11/16] selftest/cases/runtime_test: Add test for Linux Rust sample" by appending 
 KERNEL_EXTRA_FEATURES:append = ' features/kernel-sample/kernel-rust-sample.scc' instead of adding this
 directly in the linux-yocto recipe.


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 and also provide support to build
rust kernel modules in sdk. 

And this series adds test for Linux Rust sample and also added support for out-of-tree kernel 
module written in Rust as well as associated test.

Summary of patches:

- Patch 01: Extend 'bindgen-cli' to support 'nativesdk', allowing it to be available in the SDK environment.
- Patch 02: Add required dependencies ('clang-native', 'rust-native', 'bindgen-cli-native') to the kernel to support Rust binding generation.
- Patch 03: Install the Rust standard library source ('library/') into `work-shared` and which will be later copied to
           linux-yocto recipe-sysroot-native.
- Patch 04: 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 05: Stage the Rust sources into `recipe-sysroot-native` for kernel build compatibility, making them visible during native builds
            and Updated `kernel-yocto.bbclass` to invoke `make rustavailable` during 'do_kernel_configme', ensuring Rust readiness.
- Patch 06: Add kernel configuration support for Rust (via 'kernel-rust.scc'), enabling the Rust build options in kernel config.
- Patch 07: Fixed buildpaths errors when rust is enabled for kernel by appending --remap-path-prefix to RUST_DEBUG_REMAP
- Patch 08: Disabling ccache when rust-kernel is enabled for linux-yocto.
- Patch 09: Copy Rust kernel sources into kernel-devsrc build directory which will be required while running 'make prepare' in sdk.
- Patch 10: Added oe-selftest case for the Linux Rust sample.
- patch 11: Copying include/config/auto.conf in STAGING_KERNEL_BUILDDIR
- patch 12: Export artifacts needed for out-of-tree Rust compilation
- patch 13: Prepare out-of-tree rust module compilation
- patch 14: Added rust-out-of-tree-module recipe in meta-skeleton layer
- patch 15: Added rust-out-of-tree selftest

Patches have been build-tested successfully on:
- qemuarm64
- qemux86-64

Benchmark test-result for x86-64:
+-------------------------------+------------+-----------+-----------+-----------+
| 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 is due to kernel rust dependencies in
linux-yocto.

Harish Sadineni (8):
  bindgen-cli: extend BBCLASSEXTEND to include nativesdk
  linux-yocto: conditionally add clang/rust/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: enable Rust kernel support via rustavailable and staged
    rustlib sources
  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 source to $kerneldir/build

Yoann Congal (7):
  kernel-yocto.bbclass: Disable ccache when rust-kernel is enabled
  selftest/cases/runtime_test: Add test for Linux Rust sample
  kernel.bbclass: Copy include/config/auto.conf in
    STAGING_KERNEL_BUILDDIR
  kernel.bbclass: Export artifacts needed for out-of-tree Rust
    compilation
  module.bbclass: Prepare out-of-tree rust module compilation
  meta-skeleton: Add rust-out-of-tree-module recipe
  runtime_test: Add rust-out-of-tree selftest

 .../rust-out-of-tree-module_git.bb            | 18 ++++++++++
 meta/classes-recipe/kernel-yocto.bbclass      | 28 +++++++++++++++
 meta/classes-recipe/kernel.bbclass            | 19 ++++++++++
 meta/classes-recipe/module.bbclass            |  8 +++++
 meta/conf/bitbake.conf                        |  4 +--
 meta/lib/oeqa/selftest/cases/runtime_test.py  | 35 +++++++++++++++++++
 .../bindgen-cli/bindgen-cli_0.72.1.bb         |  2 +-
 meta/recipes-devtools/rust/rust_1.91.1.bb     | 17 +++++++++
 meta/recipes-kernel/linux/kernel-devsrc.bb    |  9 +++++
 meta/recipes-kernel/linux/linux-yocto.inc     |  2 ++
 meta/recipes-kernel/linux/linux-yocto_6.16.bb |  1 +
 meta/recipes-kernel/linux/linux-yocto_6.18.bb |  1 +
 12 files changed, 141 insertions(+), 3 deletions(-)
 create mode 100644 meta-skeleton/recipes-kernel/rust-out-of-tree-module/rust-out-of-tree-module_git.bb

-- 
2.49.0



^ permalink raw reply	[flat|nested] 33+ messages in thread
* Re: [PATCH v2 08/15] kernel-yocto.bbclass: Disable ccache when rust-kernel is enabled
@ 2026-01-14 14:57 Alban MOIZAN
  2026-01-14 15:40 ` Bruce Ashfield
  0 siblings, 1 reply; 33+ messages in thread
From: Alban MOIZAN @ 2026-01-14 14:57 UTC (permalink / raw)
  To: harish.sadineni
  Cc: Randy.MacLeod, Sundeep.Kokkonda, bruce.ashfield, El mehdi YOUNES,
	openembedded-core, Yoann Congal

[-- Attachment #1: Type: text/plain, Size: 3761 bytes --]

Hi everyone,

I've been investigating the issue when enabling `ccache` for kernel builds
that involve Rust.

First of all, as documented in the `ccache` issue tracker [1], `ccache` is
not directly compatible with Rust.
Therefore the current goal is to keep `ccache` enabled for the C portions
of the kernel while bypassing it for Rust.
While an alternative like `sccache` [2], compatible with both C and Rust
exists, you will see below that the underlying issue is the same, so just
replacing `ccache` by `sccache` will change nothing here.

The issue (commit 235e6d49e5888ad04416219e10b6df91a738661a + this patch):

When `ccache` is enabled, `${CC}` to `${CCACHE}{CC}`, ex: `gcc` to `ccache
gcc`

Then, when compiling the kernel, `scripts/Makefile.host` will give it to
`rustc` with `-Clinker=$(HOSTCC)` [3], but the shell expands `$(HOSTCC)` to
two words, therefore `rustc` takes `gcc` as another parameters, and it
errors out.

I attempted to resolve it by modifying the incriminated Makefile in the
following ways:

Trial 1: Quoting HOSTCC in Kernel Makefile
Modify `scripts/Makefile.host` to wrap `HOSTCC` in quotes to ensure it is
passed as a single string parameter:
Replace `-Clinker=$(HOSTCC)` to `-Clinker='$(HOSTCC)'`
Result: Failure, `rustc` looks for a binary path literally named `ccache
gcc`, which does not exist, indeed, `-Clinker` argument value is treated by
`rustc` as a real path, and not a command [4].

Trial 2: Splitting HOSTCC into Linker and Pre-link Args
Modified `scripts/Makefile.host` to force the linker to the first word of
`HOSTCC` and pass subsequent words to `-Zpre-link-args`:
Replace `-Clinker=$(HOSTCC)` by `-Clinker=$(firstword $(HOSTCC))
-Zpre-link-args='$(wordlist 2,$(words $(HOSTCC)),$(HOSTCC))'`
Result: Failure, `rustc` executes the command as: "ccache" "-m64" "gcc" ....
This is invalid because in `rustc`, the target-specific pre-link arguments
(from `compiler/rustc_target/src/spec/targets/x86_64_unknown_linux_gnu.rs`)
are added before our custom args, placing `-m64` before the `gcc`
executable [5] .

Proposed Solutions
1. Kernel + Rust Patch (A): Patch the kernel Makefile (like the Trial 1)
and patch `rustc` to accept a command string (with arguments) for
`-Clinker` instead of a strict Path.
2. Kernel + Rust Patch (B): Patch the kernel Makefile (like the Trial 2)
and patch `rustc` to use `post_link_args` instead of `pre_link_args` for
target-specific values, ensuring the executable stays at the end of the
command.
3. Shell Wrappers: Implement shell wrappers for CC, CXX, etc. This would
allow `rustc` to call a single wrapper script, hiding `ccache` from it.
4. Kernel only: Patch the kernel Makefile to filter out `ccache` from CC
(works in practice but not generic for a possible other wrapper in the
future).
5. Leave as-is: disable `ccache` when rust is enabled .

Risks and Considerations
- Upstreamability: Patching rust and the kernel at the same time could take
time.
- Maintainability: While the shell wrapper approach is more flexible and
solves the issue for other tools with similar limitations, it might make
debugging in Yocto more difficult and requires significant changes.

I'm leaning towards the 1st or the 3rd approach, but I'd appreciate the
maintainers' thoughts on which path fits the OE architecture best.

[1] https://github.com/ccache/ccache/issues/364
[2] https://github.com/mozilla/sccache
[3]
https://git.yoctoproject.org/linux-yocto/tree/scripts/Makefile.host?h=v6.18.1#n94
[4]
https://github.com/rust-lang/rust/blob/4931e09e3ac3182d2a00f38cccfdf68e8e385e1c/compiler/rustc_codegen_ssa/src/back/link.rs#L1419
[5]
https://github.com/rust-lang/rust/blob/4931e09e3ac3182d2a00f38cccfdf68e8e385e1c/compiler/rustc_codegen_ssa/src/back/link.rs#L1870

Best regards,

Alban Moizan

[-- Attachment #2: Type: text/html, Size: 4543 bytes --]

^ permalink raw reply	[flat|nested] 33+ messages in thread

end of thread, other threads:[~2026-01-15  8:58 UTC | newest]

Thread overview: 33+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-12-30 14:15 [PATCH v2 00/15] Enable rust support for linux kernel Harish.Sadineni
2025-12-30 14:15 ` [PATCH v2 01/15] bindgen-cli: extend BBCLASSEXTEND to include nativesdk Harish.Sadineni
2026-01-12  0:10   ` [OE-core] " Alistair Francis
2025-12-30 14:15 ` [PATCH v2 02/15] linux-yocto: conditionally add clang/rust/bindgen-cli-native to DEPENDS Harish.Sadineni
2026-01-12  0:12   ` [OE-core] " Alistair Francis
2025-12-30 14:15 ` [PATCH v2 03/15] rust: install Rust library sources for 'make rustavailable' support Harish.Sadineni
2025-12-30 15:58   ` [OE-core] " Richard Purdie
2026-01-05 16:24     ` Harish Sadineni
2026-01-06 18:59       ` Randy MacLeod
2026-01-07 16:34         ` Harish Sadineni
2026-01-07 18:21           ` Randy MacLeod
2026-01-07 19:03             ` Richard Purdie
2026-01-12  0:42             ` Alistair Francis
2026-01-13 12:14               ` Harish Sadineni
2025-12-30 14:15 ` [PATCH v2 04/15] bitbake.conf: Include "rust-kernel" in native/nativesdk feature filters Harish.Sadineni
2025-12-30 14:15 ` [PATCH v2 05/15] kernel-yocto: enable Rust kernel support via rustavailable and staged rustlib sources Harish.Sadineni
2025-12-30 14:15 ` [PATCH v2 06/15] linux-yocto: enable Rust support in kernel configuration Harish.Sadineni
2025-12-30 14:15 ` [PATCH v2 07/15] kernel-yocto: Fix for buildpaths errors when rust is enabled for kernel Harish.Sadineni
2025-12-30 14:15 ` [PATCH v2 08/15] kernel-yocto.bbclass: Disable ccache when rust-kernel is enabled Harish.Sadineni
2026-01-14 15:41   ` alban.moizan
2025-12-30 14:15 ` [PATCH v2 09/15] kernel-devsrc: copying rust-kernel source to $kerneldir/build Harish.Sadineni
2025-12-30 14:15 ` [PATCH v2 10/15] selftest/cases/runtime_test: Add test for Linux Rust sample Harish.Sadineni
2026-01-05  9:32   ` [OE-core] " Mathieu Dubois-Briand
2026-01-08  9:39     ` Yoann Congal
2025-12-30 14:15 ` [PATCH v2 11/15] kernel.bbclass: Copy include/config/auto.conf in STAGING_KERNEL_BUILDDIR Harish.Sadineni
2025-12-30 14:15 ` [PATCH v2 12/15] kernel.bbclass: Export artifacts needed for out-of-tree Rust compilation Harish.Sadineni
2025-12-30 14:15 ` [PATCH v2 13/15] module.bbclass: Prepare out-of-tree rust module compilation Harish.Sadineni
2025-12-30 14:15 ` [PATCH v2 14/15] meta-skeleton: Add rust-out-of-tree-module recipe Harish.Sadineni
2025-12-30 14:15 ` [PATCH v2 15/15] runtime_test: Add rust-out-of-tree selftest Harish.Sadineni
  -- strict thread matches above, loose matches on Subject: below --
2026-01-14 14:57 [PATCH v2 08/15] kernel-yocto.bbclass: Disable ccache when rust-kernel is enabled Alban MOIZAN
2026-01-14 15:40 ` Bruce Ashfield
2026-01-14 17:05   ` Alban MOIZAN
2026-01-15  8:58     ` El Mehdi YOUNES

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox