Skip to content

Commit

Permalink
Add utility to work around bindgen bug 753
Browse files Browse the repository at this point in the history
rust-lang/rust-bindgen#753

As a result all V4L2_FWHT_FL_* macros have no bindings generated for them.
The github issue describes a suggested workaround, which is applied in
this patch which adds a dedicated "runbindgen" utility, and is centered
around using a wrapper C header file for the problematic header and
defining a custom parse callback.

This works for _BITUL(), but unfortunately not for GENMASK() found in
v4l2-controls.h, which is included from videodev2.h. However, there are
just 2 invocations of GENMASK, so in the fix753.h wrapper we can #undef
the 2 masks and define them manually.

To generate bindings - inside runbindgen directory:

cargo run -- -o ../videodev2_64.rs  -I /path/to/kerneldir/usr/include/
cargo run -- -o ../videodev2_32.rs  -I /path/to/kerneldir/usr/include/ -s /usr/i686-linux-gnu/ -t i686-linux-gnu
  • Loading branch information
andrzejtp committed Feb 8, 2023
1 parent fa26302 commit b03bbcc
Show file tree
Hide file tree
Showing 8 changed files with 9,653 additions and 2,539 deletions.
210 changes: 203 additions & 7 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
members = [
"lib",
"ffi",
"lib/src/bindings/runbindgen",
]
9 changes: 8 additions & 1 deletion lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,11 @@ utils = { path = "../utils" }
# For convenience we are building the bindings manually and integrating them with
# the crate. They are generated as follows:
# bindgen /usr/include/linux/videodev2.h --output src/bindings/videodev2_64.rs
# bindgen /usr/include/linux/videodev2.h --output src/bindings/videodev2_32.rs -- --target=i686-unknown-linux-gnu
# bindgen /usr/include/linux/videodev2.h --output src/bindings/videodev2_32.rs -- --target=i686-unknown-linux-gnu
#
# In case we want to use locally installed headers (make headers_install in kernel source directory) we need to pass clang args:
# bindgen usr/include/linux/videodev2.h --output videodev2_64.rs -- -Iusr/include
# otherwise clang will mix up system-wide headers with locally installed ones resulting in inconsistent output.
#
# For 32-bit headers you might need to install libc6-dev-i386-cross or a similar package, and then
# bindgen usr/include/linux/videodev2.h --output videodev2_32.rs -- --sysroot=/usr/i686-linux-gnu/ --target=i686-linux-gnu -Iusr/include
10 changes: 10 additions & 0 deletions lib/src/bindings/runbindgen/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[package]
name = "runbindgen"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
bindgen = "0.63.0"
clap = { version = "4.0", features = ["derive"]}
17 changes: 17 additions & 0 deletions lib/src/bindings/runbindgen/fix753.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#undef V4L2_FWHT_FL_COMPONENTS_NUM_MSK
#undef V4L2_FWHT_FL_PIXENC_MSK

MARK_FIX_753(V4L2_FWHT_FL_IS_INTERLACED);
MARK_FIX_753(V4L2_FWHT_FL_IS_BOTTOM_FIRST);
MARK_FIX_753(V4L2_FWHT_FL_IS_ALTERNATE);
MARK_FIX_753(V4L2_FWHT_FL_IS_BOTTOM_FIELD);
MARK_FIX_753(V4L2_FWHT_FL_LUMA_IS_UNCOMPRESSED);
MARK_FIX_753(V4L2_FWHT_FL_CB_IS_UNCOMPRESSED);
MARK_FIX_753(V4L2_FWHT_FL_CR_IS_UNCOMPRESSED);
MARK_FIX_753(V4L2_FWHT_FL_CHROMA_FULL_HEIGHT);
MARK_FIX_753(V4L2_FWHT_FL_CHROMA_FULL_WIDTH);
MARK_FIX_753(V4L2_FWHT_FL_ALPHA_IS_UNCOMPRESSED);
MARK_FIX_753(V4L2_FWHT_FL_I_FRAME);

#define V4L2_FWHT_FL_COMPONENTS_NUM_MSK (7 << V4L2_FWHT_FL_COMPONENTS_NUM_OFFSET)
#define V4L2_FWHT_FL_PIXENC_MSK (3 << V4L2_FWHT_FL_PIXENC_OFFSET)
Loading

0 comments on commit b03bbcc

Please sign in to comment.