bcachefs-tools/bch_bindgen
Thomas Bertschinger b2824ebac1 bch_bindgen: fix packed and aligned structs on i686, ppc64
This patch addresses build issues with bch_bindgen on architectures
where the natural alignment of u64 is 4 instead of 8, such as i686 and
ppc64. The issue arises from rustc's refusing to compile structs with a
"packed" attribute that have members with an explicit "align(N)"
attribute.

rust-bindgen generally does not place "align(N)" attributes on types
when it is redundant with the type's natural alignment. There are a few
types in bcachefs with "__aligned(8)" in C where the type's natural
alignment is 8 except on architectures like those mentioned above where
it is 4. rust-bindgen places the "align(8)" attribute on these types,
for those architectures. The affected types include:

- bch_csum
- bch_sb_layout
- bch_ioctl_data_progress

bch_ioctl_data_progress, and all types that depend on it, are not used
on the Rust side currently and bindings are only generated for them
because they are covered by `.allowlist_type("bch_.*")` in
bch_bindgen/build.rs. This patch resolves the build failure for this
type by excluding it from bch_bindgen. If/when accessing this type in
Rust is needed, a decision can be made then about how to represent its
layout in Rust.

bch_csum and bch_sb_layout, and types that depend on them, are currently
used in Rust so they can't be excluded. This patch addresses these types
by stripping off the "packed" attribute in Rust on types that embed
these types, since that attribute happens to not be necessary for proper
layout.

Signed-off-by: Thomas Bertschinger <tahbertschinger@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2024-02-17 13:38:09 -05:00
..
src printbuf_to_formatter: Lossy display of non-UTF-8 printbufs 2024-01-29 14:34:24 +01:00
.gitignore move Rust sources to top level, C sources into c_src 2024-01-16 01:47:05 -05:00
build.rs bch_bindgen: fix packed and aligned structs on i686, ppc64 2024-02-17 13:38:09 -05:00
Cargo.toml rust: update bindgen to 0.69.4; remove custom type modifications 2024-02-04 18:26:33 -05:00
rustfmt.toml move Rust sources to top level, C sources into c_src 2024-01-16 01:47:05 -05:00