Building a Rust kernel module needs three things most guides skip: a bindgen that matches the kernel’s minimum, the rust-src component for your exact compiler, and a kernel new enough that your architecture is supported at all. On Linux 6.6 only x86 can build Rust; on 6.12 arm64 can, but there is no driver abstraction to use yet. This part gets the toolchain accepted by make rustavailable, explains why CONFIG_RUST is missing from your menuconfig, and ends with a built module and its metadata.
This series builds up to writing a device driver in Rust, one step at a time, using the kernel’s own samples as the worked example. It does not argue about whether you should use Rust in the first place: we covered when Rust makes sense in kernel and embedded stacks separately, and this series assumes you have decided to try it. Part 1 is the step that stops most people before they write a line of code: getting a toolchain the kernel will accept, and getting a Rust kernel module to compile.
What you need before you start
A Linux host, a kernel source tree, and the ordinary build prerequisites. The commands below were run against the Linux 7.3 tree on x86_64 with flex, bison, libelf-dev, libssl-dev and bc installed; without flex the build fails in scripts/kconfig long before Rust is involved, which is a confusing first failure to debug. Every command below runs inside the kernel source tree, except the two toolchain installs.
You also need Clang and LLVM. Rust in the kernel uses LLVM for code generation and bindgen needs libclang, so this is not optional. The host used here had Clang 18.1.3 against a 7.3 minimum of LLVM 17.0.1.
Which kernels can build a Rust kernel module at all
Check this before anything else, because it decides whether the rest is possible. Rust support is not uniform across the kernels in service, and the gap is wider than the coverage suggests. Reading the arch Kconfig files and scripts/min-tool-version.sh at each tag gives this:
Series arches selecting HAVE_RUST rustc min bindgen min
6.6.162 x86 only 1.73.0 0.65.1
6.12.117 x86, arm64, riscv, loongarch 1.78.0 0.65.1
6.18.63 x86, arm64, arm, riscv, loongarch 1.78.0 0.65.1
7.3 + powerpc, s390, um 1.85.0 0.71.1Two things there matter more than the version numbers. On 6.6, arm64 cannot build Rust at all — x86 is the only architecture that selects HAVE_RUST. And on 6.12, arm64 works but there is nothing to write a driver with: the only sample is rust_minimal. The misc device, platform driver, debugfs and DMA abstractions arrive in 6.18. If your product ships 6.12, a Rust kernel module can print and allocate, and that is the honest limit.
Two traps in that table. The 7.3 rustc minimum is per-architecture, not global: min-tool-version.sh returns 1.85.0 generally, but 1.95.0 on powerpc and 1.96.0 on s390. And on 6.12 the arm64 entry reads select HAVE_RUST if RUSTC_SUPPORTS_ARM64, so with an older compiler the option does not appear and nothing tells you why.
One documentation gap worth knowing: at 7.3 arch/powerpc/Kconfig selects HAVE_RUST for PPC32 and for little-endian PPC64, but powerpc does not appear in the table in Documentation/rust/arch-support.rst at all. Trust the Kconfig. That same document is still the place to read the constraints it does list: arm is ARMv7 little-endian only, arm64 is little-endian only, riscv is riscv64 and LLVM/Clang only, x86 is x86_64 only.
Asking the kernel whether your toolchain will do
The kernel ships its own check, and it is the first command to run. There is no need to guess at versions:
raghu@techveda.org:~$ make rustavailable
***
*** Rust bindings generator 'bindgen' could not be found.
***
***
*** Please see Documentation/rust/quick-start.rst for details
*** on how to set up the Rust support.
***
make[1]: *** [Makefile:2018: rustavailable] Error 1That is the real output on a host that already had rustc and Clang, and it is the usual first result when building a Rust kernel module. The script checks each requirement in turn and stops at the first one that fails, so expect to run it several times rather than once. It is worth understanding what it is wired to: CONFIG_RUST_IS_AVAILABLE is declared as def_bool $(success,$(srctree)/scripts/rust_is_available.sh), so the same script that answers this command also decides whether Kconfig believes Rust is possible.
Installing the two pieces people miss
Almost everyone has rustc already. The two that are missing are bindgen and the compiler’s source component. Install bindgen pinned to the minimum your tree asks for rather than taking the latest, because this is one of the few places the kernel is strict in both directions:
raghu@techveda.org:~$ cargo install --locked bindgen-cli --version 0.71.1
Finished `release` profile [optimized] target(s) in 1m 08s
Installing /root/.cargo/bin/bindgen
Installed package `bindgen-cli v0.71.1` (executable `bindgen`)Then the source component. The kernel compiles its own core for the target, so it needs the Rust standard library sources, not just the compiler:
raghu@techveda.org:~$ rustup component add rust-src
info: downloading component 'rust-src'
info: installing component 'rust-src'Note that rust-src is installed per toolchain, so upgrading rustc later means adding it again. If you are not using rustup, this is what RUST_LIB_SRC exists to point at. With both in place the check passes:
raghu@techveda.org:~$ make rustavailable
Rust is available!Why CONFIG_RUST is not in your menuconfig
Here is where people lose an afternoon. A working toolchain does not put the option in front of you. On a plain x86_64 defconfig with the toolchain above already accepted:
raghu@techveda.org:~$ make LLVM=1 defconfig
raghu@techveda.org:~$ grep -E 'RUST' .config
CONFIG_RUST_IS_AVAILABLE=y
# CONFIG_RUST is not set
CONFIG_HAVE_RUST=yAvailable, supported by the architecture, and switched off. That is the normal state: Rust is opt-in, and it is not in any defconfig. Worse, the option can be absent rather than merely unset, because of what it depends on:
config RUST
bool "Rust support"
depends on HAVE_RUST
depends on RUST_IS_AVAILABLE
select EXTENDED_MODVERSIONS if MODVERSIONS
depends on !MODVERSIONS || GENDWARFKSYMS
depends on !GCC_PLUGIN_RANDSTRUCT
depends on !RANDSTRUCT
depends on !DEBUG_INFO_BTF || (PAHOLE_HAS_LANG_EXCLUDE && !LTO)
depends on !CFI || HAVE_CFI_ICALL_NORMALIZE_INTEGERS_RUSTC
depends on !KASAN || CC_IS_CLANG
depends on !KASAN_SW_TAGS || RUSTC_VERSION >= 109600Read that as a checklist of things to turn off. Any one of RANDSTRUCT, MODVERSIONS without GENDWARFKSYMS, DEBUG_INFO_BTF without a pahole new enough to exclude Rust, or KASAN under GCC will hide CONFIG_RUST completely. A vendor BSP defconfig is far more likely to trip one of these than a mainline defconfig is, so if the option is missing on your tree, go down that list before suspecting your toolchain.
Turning it on and building
To get a Rust kernel module out of the tree, enable Rust, the samples menu, and the minimal sample as a loadable module:
raghu@techveda.org:~$ ./scripts/config --enable RUST --enable SAMPLES --enable SAMPLES_RUST --module SAMPLE_RUST_MINIMAL
raghu@techveda.org:~$ make LLVM=1 olddefconfig
raghu@techveda.org:~$ grep -E '^CONFIG_(RUST|SAMPLES_RUST|SAMPLE_RUST_MINIMAL)=' .config
CONFIG_RUST=y
CONFIG_SAMPLES_RUST=y
CONFIG_SAMPLE_RUST_MINIMAL=mThen build. The Rust-specific steps are visible in the log and are worth watching once, because they show what the kernel crate actually is:
HOSTRUSTC scripts/generate_rust_target
RUSTC L rust/core.o
BINDGEN rust/bindings/bindings_generated.rs
BINDGEN rust/bindings/bindings_helpers_generated.rs
BINDGEN rust/uapi/uapi_generated.rs
RUSTC L rust/ffi.o
RUSTC L rust/kernel.o
EXPORTS rust/exports_kernel_generated.h
RUSTC [M] samples/rust/rust_minimal.oThree BINDGEN lines generate Rust declarations from the kernel’s own C headers, which is why libclang was required. rust/core.o is the Rust standard library’s core compiled for this kernel’s target, which is why rust-src was required. Only then is the sample itself compiled.
The trap: building the module on its own
The obvious shortcut does not work. Asking for just the module gives a compile that succeeds and a link that fails:
raghu@techveda.org:~$ make LLVM=1 samples/rust/rust_minimal.ko
RUSTC [M] samples/rust/rust_minimal.o
MODPOST modules-only.symvers
WARNING: vmlinux.o is missing.
Modules may not have dependencies or modversions.
ERROR: modpost: samples/rust/rust_minimal.ko: symbol '_RNvNtCs3R38tTcvFoT_6kernel5print11call_printk' undefined!
ERROR: modpost: samples/rust/rust_minimal.ko: symbol 'rust_helper_atomic_read_acquire' undefined!Those mangled names are the kernel crate’s own symbols. In a Rust kernel module the abstractions are not a library you link against; they are built into vmlinux and exported from it, so modpost cannot resolve them until the kernel itself has been built. Build the kernel first, then the module comes with it. This also explains why an out-of-tree Rust module needs a configured and built tree rather than just headers.
Reading what you built
A successful build leaves the Rust kernel module next to its source, and its metadata is the first payoff, because every field came from Rust rather than from a C macro:
raghu@techveda.org:~$ modinfo samples/rust/rust_minimal.ko
author: Rust for Linux Contributors
description: Rust minimal sample
license: GPL
name: rust_minimal
intree: Y
vermagic: 7.3.0 SMP preempt mod_unload
parm: test_bool_parameter:This boolean parameter defaults to false (bool)
parm: test_parameter:This parameter has a default of 1 (i64)Compare that against the top of samples/rust/rust_minimal.rs and the mapping is exact: the module! invocation’s authors, description, license and name became those fields, and its params block became the two parm: lines, with i64 and bool carried through as real types.
On 6.12 the same sample differs in two ways, both of which will bite if you copy a 7.3 example onto an older tree. The field is author: "...", singular with a plain string, rather than authors: ["..."]. And the params block does not exist, so a 6.12 build of this sample produces no parm: lines at all. Everything else in the file — the Module trait, init, Drop, pr_info!, KVec and the GFP_KERNEL allocation — is identical at 6.12, 6.18 and 7.3.
Loading it is insmod samples/rust/rust_minimal.ko on a machine running this kernel, and the three pr_info! calls in the sample’s init are what reaches dmesg. If you want to work through this on real hardware with guidance, our training tracks cover kernel and driver development hands-on.
Limits, and what was not verified
Run as shown on an x86_64 host against the Linux 7.3 tree: both make rustavailable results, the bindgen and rust-src installs, the defconfig grep, the olddefconfig result, the single-target modpost failure, the full build, and the modinfo output. The module built is 18,992 bytes.
Not run: insmod and the resulting dmesg lines, because the build host was not running the kernel that was built. The version table was read from the Kconfig files and min-tool-version.sh at each tag named, not from a build on each one. The toolchain here was rustc 1.97.0 and Clang 18.1.3, both well above the 7.3 minimums, so this run does not demonstrate that the stated minimums are sufficient — only that they are what the tree asks for.
Key takeaways
make rustavailableis the first command to run, and it reports one failure at a time. The same script backsCONFIG_RUST_IS_AVAILABLE.- The two missing pieces are almost always
bindgen, pinned to the tree’s minimum, and therust-srccomponent, which is per toolchain and must be re-added after a compiler upgrade. - A working toolchain does not make the option appear.
CONFIG_RUSTis opt-in, in no defconfig, and is hidden entirely byRANDSTRUCT, byMODVERSIONSwithoutGENDWARFKSYMS, byDEBUG_INFO_BTFwithout a suitablepahole, or by KASAN under GCC. - Check your architecture before anything else: on 6.6 only x86 can build a Rust kernel module, and on 6.12 arm64 can but has no driver abstraction to use. powerpc is supported at 7.3 despite being absent from the arch-support document.
- You cannot build a Rust kernel module without building the kernel: the
kernelcrate’s symbols are exported fromvmlinux, so a single-target module build fails atmodpost. modinfois the quickest proof it worked, and every field in it maps directly onto themodule!invocation in the source.
Frequently asked questions
Why does make rustavailable keep reporting a different problem each time?
The script checks requirements in order and stops at the first failure, so each fix reveals the next one. Running it repeatedly until it reports that Rust is available is the expected workflow rather than a sign of trouble.
I have a recent rustc, so why is there no Rust option in menuconfig?
Either your architecture does not select HAVE_RUST on that kernel, or one of CONFIG_RUST‘s negative dependencies is set. Check the architecture first against your kernel version, then check for RANDSTRUCT, MODVERSIONS without GENDWARFKSYMS, DEBUG_INFO_BTF, and KASAN on a GCC build.
Can I build a Rust kernel module against installed kernel headers alone?
No. The kernel crate is compiled as part of the kernel and its symbols are exported from vmlinux, so modpost cannot link a module without a configured and built tree. A single-target build of just the .ko fails with undefined Rust symbols.
Which bindgen version should I install?
The one your tree asks for, which scripts/min-tool-version.sh bindgen prints: 0.71.1 at 7.3 and 0.65.1 on the 6.6, 6.12 and 6.18 series. Install it with cargo install --locked bindgen-cli --version <version> rather than taking the newest release.
Further reading
- Rust Quick Start — Linux kernel documentation
- Rust Arch Support — Linux kernel documentation
- Rust General Information — Linux kernel documentation
- scripts/min-tool-version.sh at v7.3 — the authoritative tool minimums
- scripts/rust_is_available.sh at v7.3 — what
rustavailableactually checks - samples/rust/rust_minimal.rs at v7.3 — the sample built here
- init/Kconfig at v7.3 — the
CONFIG_RUSTdependency list - Active kernel releases — which series are stable and longterm
- Rust for Linux project site




