]> git.sesse.net Git - bcachefs-tools-debian/commitdiff
fix(bindgen): expand the Fix753 workaround for any type and document it
authorRaito Bezarius <masterancpp@gmail.com>
Sat, 27 Jan 2024 01:34:50 +0000 (02:34 +0100)
committerKent Overstreet <kent.overstreet@linux.dev>
Sat, 27 Jan 2024 01:39:08 +0000 (20:39 -0500)
Offer documentation to the poor people who stumble on this and look for a macro generation mechanism
on the Rust side.

bch_bindgen/build.rs
bch_bindgen/src/libbcachefs_wrapper.h

index 0a99bedf5da7dbe494d1a7eb760c5d138b1fbccb..70f03076afbd5444d2e3f57dce02ecb319b0d3d0 100644 (file)
@@ -64,7 +64,7 @@ fn main() {
         .blocklist_type("srcu_struct")
         .allowlist_var("BCH_.*")
         .allowlist_var("KEY_SPEC_.*")
-        .allowlist_var("Fix753_FMODE_.*")
+        .allowlist_var("Fix753_.*")
         .allowlist_var("bch.*")
         .allowlist_var("__bch2.*")
         .allowlist_var("__BTREE_ITER.*")
index 141b083590389f71ca8e2d77fa5d6b70792810cc..5dac92bc7ccd33db68e048653777f0453ecadd01 100644 (file)
 #include "cmds.h"
 #include "raid/raid.h"
 
+/* Fix753 is a workaround for https://github.com/rust-lang/rust-bindgen/issues/753
+ * Functional macro are not expanded with bindgen, e.g. ioctl are automatically ignored
+ * from the generation
+ *
+ * To avoid this, use `MARK_FIX_753` to force the synthesis of your macro constant.
+ * It will appear in Rust with its proper name and not Fix753_{name}.
+ */
 
-#define MARK_FIX_753(req_name) const blk_mode_t Fix753_##req_name = req_name;
+/* MARK_FIX_753: force generate a macro constant in Rust
+ *
+ * @type_name   - a type for this constant
+ * @req_name    - a name for this constant which will be used inside of Rust
+ */
+#define MARK_FIX_753(type_name, req_name) const type_name Fix753_##req_name = req_name;
+
+MARK_FIX_753(blk_mode_t, BLK_OPEN_READ);
+MARK_FIX_753(blk_mode_t, BLK_OPEN_WRITE);
+MARK_FIX_753(blk_mode_t, BLK_OPEN_EXCL);
 
-MARK_FIX_753(BLK_OPEN_READ);
-MARK_FIX_753(BLK_OPEN_WRITE);
-MARK_FIX_753(BLK_OPEN_EXCL);