Rust for Linux List
 help / color / mirror / Atom feed
* [PATCH 0/2] rust: kernel: add cfg_select! and use it for config-based selection
@ 2026-06-29  3:51 Nika Krasnova
  2026-06-29  3:51 ` [PATCH 1/2] rust: kernel: add cfg_select! backport " Nika Krasnova
                   ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: Nika Krasnova @ 2026-06-29  3:51 UTC (permalink / raw)
  To: Miguel Ojeda, Boqun Feng, Gary Guo, Björn Roy Baron,
	Benno Lossin, Andreas Hindborg, Alice Ryhl, Trevor Gross,
	Danilo Krummrich
  Cc: Daniel Almeida, Tamir Duberstein, Alexandre Courbot,
	Onur Özkan, Viresh Kumar, Yury Norov, Lorenzo Stoakes,
	Brendan Higgins, David Gow, Rae Moar, rust-for-linux,
	linux-kernel, kunit-dev, linux-kselftest, Nika Krasnova

Conditional compilation in the kernel's Rust code is expressed with
paired #[cfg(CONFIG_FOO)] / #[cfg(not(CONFIG_FOO))] attributes when
selecting between two or more implementations of an item. This is
verbose and easy to get out of sync.

The standard library gained core::cfg_select! for exactly this (stable
since Rust 1.95.0): one macro that emits the first arm whose cfg
predicate holds. The kernel's MSRV is 1.85.0, so it is not yet
available.

Patch 1 adds a macro_rules! backport under the same name and arm syntax,
so call sites can be written today and switch to core::cfg_select!
unchanged once the MSRV reaches 1.95.0. Patch 2 converts the existing
paired #[cfg] selections in the kernel crate to it.

One selection is deliberately left as #[cfg]: a #[macro_export]
macro_rules! referred to by an absolute path ($crate::) cannot be
wrapped in cfg_select! (rust-lang/rust#52234); see patch 2 for details.

Testing:
 - KUnit: rust_kernel_cfg 14/14, rust_doctests_kernel 322/322 (x86_64).
 - clippy (CLIPPY=1) clean; rustfmt clean; checkpatch --strict: no
   errors (only the benign new-file MAINTAINERS warning).
 - Built x86_64 with CONFIG_DEBUG_FS=y and =n to cover both debugfs arms.
 - Other arches / CONFIG_64BIT=n arms not built locally; relying on CI.

Link: https://github.com/Rust-for-Linux/linux/issues/1183
Signed-off-by: Nika Krasnova <nika@nikableh.moe>
---
Nika Krasnova (2):
      rust: kernel: add cfg_select! backport for config-based selection
      rust: kernel: migrate to cfg_select! for config-based selection

 rust/kernel/cfg.rs                   | 297 +++++++++++++++++++++++++++++++++++
 rust/kernel/cpu.rs                   |  21 +--
 rust/kernel/cpumask.rs               |  42 ++---
 rust/kernel/debugfs.rs               | 145 +++++++++--------
 rust/kernel/driver.rs                |  44 +++---
 rust/kernel/drm/device.rs            |  53 ++++---
 rust/kernel/error.rs                 |  47 +++---
 rust/kernel/kunit.rs                 |  54 ++++---
 rust/kernel/lib.rs                   |  78 ++++-----
 rust/kernel/mm.rs                    |  36 +++--
 rust/kernel/prelude.rs               |   1 +
 rust/kernel/sync/atomic.rs           |  54 ++++---
 rust/kernel/sync/atomic/predefine.rs |  35 +++--
 rust/kernel/time.rs                  |  82 +++++-----
 14 files changed, 665 insertions(+), 324 deletions(-)
---
base-commit: dc59e4fea9d83f03bad6bddf3fa2e52491777482
change-id: 20260629-backport-cfg_select-54f5e3d034ed

-- 
Nika Krasnova


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

end of thread, other threads:[~2026-07-01  1:39 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-06-29  3:51 [PATCH 0/2] rust: kernel: add cfg_select! and use it for config-based selection Nika Krasnova
2026-06-29  3:51 ` [PATCH 1/2] rust: kernel: add cfg_select! backport " Nika Krasnova
2026-06-29  3:51 ` [PATCH 2/2] rust: kernel: migrate to cfg_select! " Nika Krasnova
2026-06-29  9:38 ` [PATCH 0/2] rust: kernel: add cfg_select! and use it " Miguel Ojeda
2026-06-29  9:43   ` Miguel Ojeda
2026-06-29 15:34   ` Nika Krasnova
2026-06-29 19:07     ` Miguel Ojeda
2026-07-01  1:39       ` Nika Krasnova

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