Trying to get Rust support building in the kernel last night was a bit tricky. Despite following the quickstart guide and using the rustavailable target and getting the “Rust is available” message I still couldn’t get the Rust support option to show up in the General setup menu.

After going over it a number of times and verifying I had done everything in the setup correctly I set about trying to answer the question as to why it wasn’t showing up for me. I’ve built the kernel in the past but haven’t done any development and have only tested new kernel functionality in the past and as a result I’m not familiar with all of the mechanisms involved with setup and configuration but it’s also a relatively easy and straightforward system to track down the issue.

The rustavailable target is supposed to use the same functionality as Kconfig to determine RUST_IS_AVAILABLE and that’s true but it’s not the whole picture when you are trying to configure a kernel for Rust support.

So where do we look? With grep in hand we find Rust support (the name of the setting that will set CONFIG_RUST to 1 if we enable it) in the Kconfig file in the init directory.

If we look there we see something like this:

config RUST
	bool "Rust support"
	depends on HAVE_RUST
	depends on RUST_IS_AVAILABLE
	depends on !MODVERSIONS
	depends on !GCC_PLUGINS
	depends on !RANDSTRUCT
	depends on !DEBUG_INFO_BTF || PAHOLE_HAS_LANG_EXCLUDE

Here we can see that while RUST_IS_AVAILABLE is used it’s just one of a number of other things that control whether Rust support shows up in the General setup menu. So what do we do? Well, let’s be dumb and just see if we can eliminate the dependencies until Rust support shows up the General setup menu. First we remove all the dependencies except HAVE_RUST and RUST_IS_AVAILABLE. If we do this and we’ve followed the quick start guide then after we do this then we do indeed get the Rust support option.

Because of a previous test of Rust support in the kernel when it was first introduced I had a feeling that it might be related to the dependency on !MODVERSIONS. I wasn’t entirely sure but I added it back and confirmed it’s what was causing my issue. So what is that?

If we grep through files for MODVERSIONS we eventually find this kernel option in kernel/module/Kconfig.

config MODVERSIONS
	bool "Module versioning support"
	help
	  Usually, you have to use modules compiled with your kernel.
	  Saying Y here makes it sometimes possible to use modules
	  compiled for different kernels, by adding enough information
	  to the modules to (hopefully) spot any changes which would
	  make them incompatible with the kernel you are running.  If
	  unsure, say N.

So if we restore all of the dependencies of config RUST and then we run make menuconfig and go into Enable loadable module support and toggle Module versioning support and then go back into General setup we’ll see that Rust support is now there.