Re: [PATCH] rust: enable bindgen's `--enable-function-attribute-detection` flag
From: Alice Ryhl
Date: Thu Aug 15 2024 - 03:57:27 EST
On Wed, Aug 14, 2024 at 6:37 PM Miguel Ojeda <ojeda@xxxxxxxxxx> wrote:
>
> `bindgen` is able to detect certain function attributes and annotate
> functions correspondingly in its output for the Rust side, when the
> `--enable-function-attribute-detection` is passed.
>
> In particular, it is currently able to use `__must_check` in C
> (`#[must_use]` in Rust), which give us a bunch of annotations that are
> nice to have to prevent possible issues in Rust abstractions, e.g.:
>
> extern "C" {
> + #[must_use]
> pub fn kobject_add(
> kobj: *mut kobject,
> parent: *mut kobject,
> fmt: *const core::ffi::c_char,
> ...
> ) -> core::ffi::c_int;
> }
>
> Apparently, there are edge cases where this can make generation very slow,
> which is why it is behind a flag [1], but it does not seem to affect us
> in any major way at the moment.
>
> Link: https://github.com/rust-lang/rust-bindgen/issues/1465 [1]
> Link: https://lore.kernel.org/rust-for-linux/CANiq72=u5Nrz_NW3U3_VqywJkD8pECA07q2pFDd1wjtXOWdkAQ@xxxxxxxxxxxxxx/
> Signed-off-by: Miguel Ojeda <ojeda@xxxxxxxxxx>
Reviewed-by: Alice Ryhl <aliceryhl@xxxxxxxxxx>
Tested-by: Alice Ryhl <aliceryhl@xxxxxxxxxx>