After watching Alex Gaynor and Geoffrey Thomas their presentation and video about writing Linux kernel modules, I have been trying to keep a close eye on their progress. Especially since I have been playing around with the now archived linux-kernel-module-rust repository, to port over one of my toy Linux kernel modules to fiddle around with physical memory and page tables from C to Rust.
Three years after the presentation we are now looking at initial Rust support being part of the Linux 6.1 kernel. Shortly after that Raphael Nestler wrote some interesting blog posts about building out-of-tree Rust kernel modules on ArchLinux (you can read part one and part two here). These articles got me wondering about whether this is possible on Gentoo. Of course, while we focus on Gentoo here, most of this knowledge is also applicable to other Linux distributions.
As not everyone is familiar with Gentoo, we will first take a look at the various ways of installing a Linux kernel. In fact, many people, including many Gentoo users, do not seem to be aware that Gentoo ships sys-kernel/gentoo-kernel-bin, which is a precompiled binary of the Linux kernel with Gentoo-specific patches which has been available since January 10, 2020.