rust-for-linux.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] rust: enable bindgen's `--enable-function-attribute-detection` flag
@ 2024-08-14 16:37 Miguel Ojeda
  2024-08-15  7:56 ` Alice Ryhl
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Miguel Ojeda @ 2024-08-14 16:37 UTC (permalink / raw)
  To: Miguel Ojeda, Alex Gaynor, Wedson Almeida Filho
  Cc: Boqun Feng, Gary Guo, Björn Roy Baron, Benno Lossin,
	Andreas Hindborg, Alice Ryhl, rust-for-linux, linux-kernel,
	patches

`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@mail.gmail.com/
Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
---
If someone notices a major performance difference, please let me know!

 rust/Makefile | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/rust/Makefile b/rust/Makefile
index 1f10f92737f2..c28b81e2a5fa 100644
--- a/rust/Makefile
+++ b/rust/Makefile
@@ -270,7 +270,7 @@ quiet_cmd_bindgen = BINDGEN $@
       cmd_bindgen = \
 	$(BINDGEN) $< $(bindgen_target_flags) \
 		--use-core --with-derive-default --ctypes-prefix core::ffi --no-layout-tests \
-		--no-debug '.*' \
+		--no-debug '.*' --enable-function-attribute-detection \
 		-o $@ -- $(bindgen_c_flags_final) -DMODULE \
 		$(bindgen_target_cflags) $(bindgen_target_extra)


base-commit: de9c2c66ad8e787abec7c9d7eff4f8c3cdd28aed
--
2.46.0

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

* Re: [PATCH] rust: enable bindgen's `--enable-function-attribute-detection` flag
  2024-08-14 16:37 [PATCH] rust: enable bindgen's `--enable-function-attribute-detection` flag Miguel Ojeda
@ 2024-08-15  7:56 ` Alice Ryhl
  2024-08-15 18:24 ` Gary Guo
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Alice Ryhl @ 2024-08-15  7:56 UTC (permalink / raw)
  To: Miguel Ojeda
  Cc: Alex Gaynor, Wedson Almeida Filho, Boqun Feng, Gary Guo,
	Björn Roy Baron, Benno Lossin, Andreas Hindborg,
	rust-for-linux, linux-kernel, patches

On Wed, Aug 14, 2024 at 6:37 PM Miguel Ojeda <ojeda@kernel.org> 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@mail.gmail.com/
> Signed-off-by: Miguel Ojeda <ojeda@kernel.org>

Reviewed-by: Alice Ryhl <aliceryhl@google.com>
Tested-by: Alice Ryhl <aliceryhl@google.com>

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

* Re: [PATCH] rust: enable bindgen's `--enable-function-attribute-detection` flag
  2024-08-14 16:37 [PATCH] rust: enable bindgen's `--enable-function-attribute-detection` flag Miguel Ojeda
  2024-08-15  7:56 ` Alice Ryhl
@ 2024-08-15 18:24 ` Gary Guo
  2024-08-15 18:33 ` Danilo Krummrich
  2024-08-21 22:13 ` Miguel Ojeda
  3 siblings, 0 replies; 5+ messages in thread
From: Gary Guo @ 2024-08-15 18:24 UTC (permalink / raw)
  To: Miguel Ojeda
  Cc: Alex Gaynor, Wedson Almeida Filho, Boqun Feng,
	Björn Roy Baron, Benno Lossin, Andreas Hindborg, Alice Ryhl,
	rust-for-linux, linux-kernel, patches

On Wed, 14 Aug 2024 18:37:22 +0200
Miguel Ojeda <ojeda@kernel.org> 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@mail.gmail.com/
> Signed-off-by: Miguel Ojeda <ojeda@kernel.org>

Reviewed-by: Gary Guo <gary@garyguo.net>

> ---
> If someone notices a major performance difference, please let me know!
> 
>  rust/Makefile | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/rust/Makefile b/rust/Makefile
> index 1f10f92737f2..c28b81e2a5fa 100644
> --- a/rust/Makefile
> +++ b/rust/Makefile
> @@ -270,7 +270,7 @@ quiet_cmd_bindgen = BINDGEN $@
>        cmd_bindgen = \
>  	$(BINDGEN) $< $(bindgen_target_flags) \
>  		--use-core --with-derive-default --ctypes-prefix core::ffi --no-layout-tests \
> -		--no-debug '.*' \
> +		--no-debug '.*' --enable-function-attribute-detection \
>  		-o $@ -- $(bindgen_c_flags_final) -DMODULE \
>  		$(bindgen_target_cflags) $(bindgen_target_extra)
> 
> 
> base-commit: de9c2c66ad8e787abec7c9d7eff4f8c3cdd28aed
> --
> 2.46.0


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

* Re: [PATCH] rust: enable bindgen's `--enable-function-attribute-detection` flag
  2024-08-14 16:37 [PATCH] rust: enable bindgen's `--enable-function-attribute-detection` flag Miguel Ojeda
  2024-08-15  7:56 ` Alice Ryhl
  2024-08-15 18:24 ` Gary Guo
@ 2024-08-15 18:33 ` Danilo Krummrich
  2024-08-21 22:13 ` Miguel Ojeda
  3 siblings, 0 replies; 5+ messages in thread
From: Danilo Krummrich @ 2024-08-15 18:33 UTC (permalink / raw)
  To: Miguel Ojeda
  Cc: Alex Gaynor, Wedson Almeida Filho, Boqun Feng, Gary Guo,
	Björn Roy Baron, Benno Lossin, Andreas Hindborg, Alice Ryhl,
	rust-for-linux, linux-kernel, patches

On 8/14/24 6:37 PM, Miguel Ojeda 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@mail.gmail.com/
> Signed-off-by: Miguel Ojeda <ojeda@kernel.org>

Thanks for looking into this,

Acked-by: Danilo Krummrich <dakr@kernel.org>

> ---
> If someone notices a major performance difference, please let me know!
> 
>   rust/Makefile | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/rust/Makefile b/rust/Makefile
> index 1f10f92737f2..c28b81e2a5fa 100644
> --- a/rust/Makefile
> +++ b/rust/Makefile
> @@ -270,7 +270,7 @@ quiet_cmd_bindgen = BINDGEN $@
>         cmd_bindgen = \
>   	$(BINDGEN) $< $(bindgen_target_flags) \
>   		--use-core --with-derive-default --ctypes-prefix core::ffi --no-layout-tests \
> -		--no-debug '.*' \
> +		--no-debug '.*' --enable-function-attribute-detection \
>   		-o $@ -- $(bindgen_c_flags_final) -DMODULE \
>   		$(bindgen_target_cflags) $(bindgen_target_extra)
> 
> 
> base-commit: de9c2c66ad8e787abec7c9d7eff4f8c3cdd28aed
> --
> 2.46.0
> 

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

* Re: [PATCH] rust: enable bindgen's `--enable-function-attribute-detection` flag
  2024-08-14 16:37 [PATCH] rust: enable bindgen's `--enable-function-attribute-detection` flag Miguel Ojeda
                   ` (2 preceding siblings ...)
  2024-08-15 18:33 ` Danilo Krummrich
@ 2024-08-21 22:13 ` Miguel Ojeda
  3 siblings, 0 replies; 5+ messages in thread
From: Miguel Ojeda @ 2024-08-21 22:13 UTC (permalink / raw)
  To: Miguel Ojeda
  Cc: Alex Gaynor, Wedson Almeida Filho, Boqun Feng, Gary Guo,
	Björn Roy Baron, Benno Lossin, Andreas Hindborg, Alice Ryhl,
	rust-for-linux, linux-kernel, patches

On Wed, Aug 14, 2024 at 6:37 PM Miguel Ojeda <ojeda@kernel.org> 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@mail.gmail.com/
> Signed-off-by: Miguel Ojeda <ojeda@kernel.org>

Applied to `rust-next` -- thanks everyone!

Cheers,
Miguel

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

end of thread, other threads:[~2024-08-21 22:13 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-08-14 16:37 [PATCH] rust: enable bindgen's `--enable-function-attribute-detection` flag Miguel Ojeda
2024-08-15  7:56 ` Alice Ryhl
2024-08-15 18:24 ` Gary Guo
2024-08-15 18:33 ` Danilo Krummrich
2024-08-21 22:13 ` Miguel Ojeda

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).