From 3f646e12d1f67605eedfad5ae33eab7ff8bbb3ac Mon Sep 17 00:00:00 2001 From: Tim Schumacher Date: Thu, 27 Feb 2025 23:47:20 +0100 Subject: [PATCH] linux/common-config: Spell out the current set of supported Rust targets This keeps us from accidentally running into platforms where Rust is not supported by the Linux kernel itself (for that particular platform). --- pkgs/os-specific/linux/kernel/common-config.nix | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/pkgs/os-specific/linux/kernel/common-config.nix b/pkgs/os-specific/linux/kernel/common-config.nix index 4bbebf2cc3b4..019be333e89b 100644 --- a/pkgs/os-specific/linux/kernel/common-config.nix +++ b/pkgs/os-specific/linux/kernel/common-config.nix @@ -43,17 +43,24 @@ let ); forceRust = features.rust or false; - kernelSupportsRust = lib.versionAtLeast version "6.7" - # Known to be broken: https://lore.kernel.org/lkml/31885EDD-EF6D-4EF1-94CA-276BA7A340B7@kernel.org/T/ - && !(stdenv.hostPlatform.isRiscV && stdenv.cc.isGNU); - + # Architecture support collected from HAVE_RUST Kconfig definitions and the following table: + # https://web.git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/rust/arch-support.rst + kernelSupportsRust = ( + lib.versionAtLeast version "6.12" + && ( + stdenv.hostPlatform.isx86_64 + || stdenv.hostPlatform.isLoongArch64 + || stdenv.hostPlatform.isAarch64 + || (stdenv.hostPlatform.isRiscV64 && !stdenv.cc.isGNU) + ) + ); # Currently only enabling Rust by default on kernel 6.12+, # which actually has features that use Rust that we want. defaultRust = lib.versionAtLeast version "6.12" && rustAvailable; withRust = assert lib.assertMsg (!(forceRust && !kernelSupportsRust)) '' - Kernels below 6.7 (the kernel being built is ${version}) don't support Rust. + Kernel ${version} is not declared as supporting Rust on this host platform and compiler. ''; (forceRust || defaultRust) && kernelSupportsRust;