Re: [TECH TOPIC] Rust for Linux

Miguel Ojeda
2021-07-19T17:37:49Z

On Mon, Jul 19, 2021 at 4:02 PM Arnd Bergmann <arnd@arndb.de> wrote:
>
> - What is the mechanism behind power::Operations that replaces the
> #ifdef CONFIG_PM of the C version? Will the rust compiler just drop
> the dead code when CONFIG_PM is disabled?

We support conditional compilation with the kernel configuration, e.g.:

#[cfg(CONFIG_X)] // `CONFIG_X` is enabled (`y` or `m`)
#[cfg(CONFIG_X="y")] // `CONFIG_X` is enabled as a built-in (`y`)
#[cfg(CONFIG_X="m")] // `CONFIG_X` is enabled as a module (`m`)
#[cfg(not(CONFIG_X))] // `CONFIG_X` is disabled

One can use it, like in C, to fully remove any item as a user, to make
an implementation a noop (so that callers do not need to care), etc.

Cheers,
Miguel