Skip to content

Commit b03bbcc

Browse files
committed
Add utility to work around bindgen bug 753
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
1 parent fa26302 commit b03bbcc

File tree

8 files changed

+9653
-2539
lines changed

8 files changed

+9653
-2539
lines changed

Cargo.lock

Lines changed: 203 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@
22
members = [
33
"lib",
44
"ffi",
5+
"lib/src/bindings/runbindgen",
56
]

lib/Cargo.toml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,11 @@ utils = { path = "../utils" }
2626
# For convenience we are building the bindings manually and integrating them with
2727
# the crate. They are generated as follows:
2828
# bindgen /usr/include/linux/videodev2.h --output src/bindings/videodev2_64.rs
29-
# bindgen /usr/include/linux/videodev2.h --output src/bindings/videodev2_32.rs -- --target=i686-unknown-linux-gnu
29+
# bindgen /usr/include/linux/videodev2.h --output src/bindings/videodev2_32.rs -- --target=i686-unknown-linux-gnu
30+
#
31+
# In case we want to use locally installed headers (make headers_install in kernel source directory) we need to pass clang args:
32+
# bindgen usr/include/linux/videodev2.h --output videodev2_64.rs -- -Iusr/include
33+
# otherwise clang will mix up system-wide headers with locally installed ones resulting in inconsistent output.
34+
#
35+
# For 32-bit headers you might need to install libc6-dev-i386-cross or a similar package, and then
36+
# bindgen usr/include/linux/videodev2.h --output videodev2_32.rs -- --sysroot=/usr/i686-linux-gnu/ --target=i686-linux-gnu -Iusr/include
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
[package]
2+
name = "runbindgen"
3+
version = "0.1.0"
4+
edition = "2021"
5+
6+
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
7+
8+
[dependencies]
9+
bindgen = "0.63.0"
10+
clap = { version = "4.0", features = ["derive"]}

lib/src/bindings/runbindgen/fix753.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#undef V4L2_FWHT_FL_COMPONENTS_NUM_MSK
2+
#undef V4L2_FWHT_FL_PIXENC_MSK
3+
4+
MARK_FIX_753(V4L2_FWHT_FL_IS_INTERLACED);
5+
MARK_FIX_753(V4L2_FWHT_FL_IS_BOTTOM_FIRST);
6+
MARK_FIX_753(V4L2_FWHT_FL_IS_ALTERNATE);
7+
MARK_FIX_753(V4L2_FWHT_FL_IS_BOTTOM_FIELD);
8+
MARK_FIX_753(V4L2_FWHT_FL_LUMA_IS_UNCOMPRESSED);
9+
MARK_FIX_753(V4L2_FWHT_FL_CB_IS_UNCOMPRESSED);
10+
MARK_FIX_753(V4L2_FWHT_FL_CR_IS_UNCOMPRESSED);
11+
MARK_FIX_753(V4L2_FWHT_FL_CHROMA_FULL_HEIGHT);
12+
MARK_FIX_753(V4L2_FWHT_FL_CHROMA_FULL_WIDTH);
13+
MARK_FIX_753(V4L2_FWHT_FL_ALPHA_IS_UNCOMPRESSED);
14+
MARK_FIX_753(V4L2_FWHT_FL_I_FRAME);
15+
16+
#define V4L2_FWHT_FL_COMPONENTS_NUM_MSK (7 << V4L2_FWHT_FL_COMPONENTS_NUM_OFFSET)
17+
#define V4L2_FWHT_FL_PIXENC_MSK (3 << V4L2_FWHT_FL_PIXENC_OFFSET)

0 commit comments

Comments
 (0)