Skip to content

Commit

Permalink
lib: add features to generate 32-bit or 64-bit bindings
Browse files Browse the repository at this point in the history
This is useful for crates that rely on a specific representation no
matter what the host is, e.g. virtio-media.
  • Loading branch information
Gnurou committed Oct 22, 2024
1 parent d870e30 commit 2752985
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
6 changes: 6 additions & 0 deletions lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ license = "MIT"

readme.workspace = true

[features]
# Generate the bindings for 64-bit even if the host is 32-bit.
arch64 = []
# Generate the bindings for 32-bit even if the host is 64-bit.
arch32 = []

[dependencies]
nix = { version = "0.28", features = ["ioctl", "mman", "poll", "fs", "event"] }
bitflags = "2.4"
Expand Down
10 changes: 9 additions & 1 deletion lib/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,17 @@ fn main() {
println!("cargo::rerun-if-changed={}", videodev2_h.display());
println!("cargo::rerun-if-changed={}", WRAPPER_H);

let clang_args = [
format!("-I{}", videodev2_h_path),
#[cfg(all(feature = "arch64", not(feature = "arch32")))]
"--target=x86_64-linux-gnu".into(),
#[cfg(all(feature = "arch32", not(feature = "arch64")))]
"--target=i686-linux-gnu".into(),
];

let bindings = v4l2r_bindgen_builder(bindgen::Builder::default())
.header(WRAPPER_H)
.clang_args([format!("-I{}", videodev2_h_path)])
.clang_args(clang_args)
.generate()
.expect("unable to generate bindings");

Expand Down

0 comments on commit 2752985

Please sign in to comment.