]> git.sesse.net Git - bcachefs-tools-debian/commitdiff
rust: update bindgen to 0.69.4; remove custom type modifications
authorThomas Bertschinger <tahbertschinger@gmail.com>
Sun, 4 Feb 2024 20:49:23 +0000 (13:49 -0700)
committerKent Overstreet <kent.overstreet@linux.dev>
Sun, 4 Feb 2024 23:26:33 +0000 (18:26 -0500)
This updates rust-bindgen to version 0.69.4 which includes the patch
199bee441ad0: "try to avoid #[repr(packed)] when align is needed". With
this patch, bindgen generates code that is both ABI-correct and can be
compiled by rustc, for 3 bcachefs types:

- bkey
- bch_extent_crc32
- bch_extent_ptr

This allows us to remove the custom treatment for these three types.

Signed-off-by: Thomas Bertschinger <tahbertschinger@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
Cargo.lock
bch_bindgen/Cargo.toml
bch_bindgen/build.rs

index bcbdbc5a4ed7f6374a4e5e48df9e24989783dc34..9987974e937c7c665f4f5cd776b7f4ea5dacd021 100644 (file)
@@ -119,17 +119,17 @@ dependencies = [
 
 [[package]]
 name = "bindgen"
-version = "0.69.2"
+version = "0.69.4"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "a4c69fae65a523209d34240b60abe0c42d33d1045d445c0839d8a4894a736e2d"
+checksum = "a00dc851838a2120612785d195287475a3ac45514741da670b735818822129a0"
 dependencies = [
  "bitflags 2.4.2",
  "cexpr",
  "clang-sys",
+ "itertools",
  "lazy_static",
  "lazycell",
  "log",
- "peeking_take_while",
  "prettyplease",
  "proc-macro2",
  "quote",
@@ -332,6 +332,15 @@ dependencies = [
  "windows-sys 0.52.0",
 ]
 
+[[package]]
+name = "itertools"
+version = "0.12.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "ba291022dbbd398a455acf126c1e341954079855bc60dfdda641363bd6922569"
+dependencies = [
+ "either",
+]
+
 [[package]]
 name = "lazy_static"
 version = "1.4.0"
@@ -425,12 +434,6 @@ version = "1.0.14"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "de3145af08024dea9fa9914f381a17b8fc6034dfb00f3a84013f7ff43f29ed4c"
 
-[[package]]
-name = "peeking_take_while"
-version = "0.1.2"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "19b17cddbe7ec3f8bc800887bab5e717348c95ea2ca0b1bf0837fb964dc67099"
-
 [[package]]
 name = "pkg-config"
 version = "0.3.29"
index fcc4668563ded43fcb0477ad777aeae7f65d87a4..63be4f3dac135fc5fdeec33a1a9868ffc4865aa3 100644 (file)
@@ -19,4 +19,4 @@ paste = "1.0.11"
 
 [build-dependencies]
 pkg-config = "0.3"
-bindgen = "0.69.2"
+bindgen = "0.69.4"
index c9a90fcab25da4cefeb805bbd65a6caedac8abbc..1baa2666b8f878b23ba06ee493d222db27894cc8 100644 (file)
@@ -120,40 +120,15 @@ fn main() {
         .expect("Writing to output file failed for: `keyutils.rs`");
 }
 
-// rustc has a limitation where it does not allow structs to have both a "packed" and "align"
-// attribute. This means that bindgen cannot copy all attributes from some C types, like struct
-// bkey, that are both packed and aligned.
+// rustc has a limitation where it does not allow structs with a "packed" attribute to contain a
+// member with an "align(N)" attribute. There is one type in bcachefs with this issue:
+// struct btree_node.
 //
-// bindgen tries to handle this situation smartly and for many types it will only apply a
-// "packed(N)" attribute if that is good enough. However, there are a few types where bindgen
-// does end up generating both a packed(N) and align(N) attribute. These types can't be compiled
-// by rustc.
-//
-// To work around this, we can remove either the "packed" or "align" attribute. It happens that
-// for all the types with this problem in bcachefs, removing the "packed" attribute and keeping
-// the "align" attribute results in a type with the correct ABI.
-//
-// This function applies that transformation to the following bcachefs types that need it:
-//   - bkey
-//   - bch_extent_crc32
-//   - bch_extent_ptr
-//   - btree_node
+// Luckily, it happens that this type does not need the "packed(N)" attribute in Rust to have the
+// same ABI as C, so we can strip it off the bindgen output.
 fn packed_and_align_fix(bindings: std::string::String) -> std::string::String {
-    bindings
-        .replace(
-            "#[repr(C, packed(8))]\n#[repr(align(8))]\n#[derive(Debug, Default, Copy, Clone)]\npub struct bkey {",
-            "#[repr(C, align(8))]\n#[derive(Debug, Default, Copy, Clone)]\npub struct bkey {",
-        )
-        .replace(
-            "#[repr(C, packed(8))]\n#[repr(align(8))]\n#[derive(Debug, Default, Copy, Clone)]\npub struct bch_extent_crc32 {",
-            "#[repr(C, align(8))]\n#[derive(Debug, Default, Copy, Clone)]\npub struct bch_extent_crc32 {",
-        )
-        .replace(
-            "#[repr(C, packed(8))]\n#[repr(align(8))]\n#[derive(Debug, Default, Copy, Clone)]\npub struct bch_extent_ptr {",
-            "#[repr(C, align(8))]\n#[derive(Debug, Default, Copy, Clone)]\npub struct bch_extent_ptr {",
-        )
-        .replace(
-            "#[repr(C, packed(8))]\npub struct btree_node {",
-            "#[repr(C, align(8))]\npub struct btree_node {",
-        )
+    bindings.replace(
+        "#[repr(C, packed(8))]\npub struct btree_node {",
+        "#[repr(C, align(8))]\npub struct btree_node {",
+    )
 }