Skip to contentSkip to conversation

rust: enable bindgen's `--enable-function-attribute-detection` flag

PATCH Applied Miguel Ojeda 5 participants 5 messages Aug 14, 2024 – Aug 21, 2024 Rust

lore
Share & tools
lore

Miguel Ojeda

author maintainer
#0 lore raw

PATCH 1/1 rust: enable bindgen's `--enable-function-attribute-detection` flag

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.

---
If someone notices a major performance difference, please let me know!

 rust/Makefile | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
rust/Makefile +1 -1
index 1f10f92737f2..c28b81e2a5fa 100644
@@ -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

reviewer Reviewed-by Tested-by on v1 1/1
#1 lore raw
Quoted 19 lines · Miguel Ojeda

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;
     }
Quoted 7 lines

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.

reviewer Reviewed-by on v1 1/1
#2 lore raw
In reply to Miguel Ojeda
Quoted 18 lines · On Wed, 14 Aug 2024 18:37:22 +0200 Miguel Ojeda <[email protected]> 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;
     }
Quoted 7 lines

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.

Quoted 23 lines

---
If someone notices a major performance difference, please let me know!

 rust/Makefile | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
rust/Makefile +1 -1
index 1f10f92737f2..c28b81e2a5fa 100644
@@ -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

Acked-by on v1 1/1
#3 lore raw
In reply to Miguel Ojeda
Quoted 18 lines · Miguel Ojeda

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;
      }
Quoted 7 lines

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.

Thanks for looking into this,

Quoted 24 lines

---
If someone notices a major performance difference, please let me know!

  rust/Makefile | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
rust/Makefile +1 -1
index 1f10f92737f2..c28b81e2a5fa 100644
@@ -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

Applied
#4 lore raw
In reply to Miguel Ojeda
Quoted 19 lines · Miguel Ojeda

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;
     }
Quoted 7 lines

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.

Applied to rust-next -- thanks everyone!

Cheers,
Miguel