Skip to content

Commit

Permalink
Avoid libv4l2 pkg-config dependency added by mistake
Browse files Browse the repository at this point in the history
User API header file required to generate bindings in `v4l2-sys` is not
part of `libv4l2`.

Instead directly check if UAPI header file is present on FreeBSD and
extend compiler's include paths. Or guide user towards necessary package
if header file is missing.
  • Loading branch information
vladmovchan committed Aug 12, 2024
1 parent 8953d41 commit 6bef448
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
1 change: 0 additions & 1 deletion v4l2-sys/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,3 @@ build = "build.rs"

[build-dependencies]
bindgen = "0.69.1"
pkg-config = "0.3.30"
23 changes: 13 additions & 10 deletions v4l2-sys/build.rs
Original file line number Diff line number Diff line change
@@ -1,21 +1,24 @@
extern crate bindgen;

use std::env;
use std::path::PathBuf;
use std::path::{Path, PathBuf};

fn main() {
let pkg_conf = pkg_config::Config::new()
.probe("libv4l2")
.expect("pkg-config has failed to find `libv4l2`");
let extra_include_paths = if cfg!(target_os = "freebsd") {
assert!(
Path::new("/usr/local/include/linux/videodev2.h").exists(),
"Video4Linux `videodev2.h` UAPI header is required to generate bindings \
against `libv4l2` and the header file is missing.\n\
Consider installing `multimedia/v4l_compat` FreeBSD package."
);
vec!["-I/usr/local/include"]
} else {
vec![]
};

let bindings = bindgen::Builder::default()
.header("wrapper.h")
.clang_args(
pkg_conf
.include_paths
.into_iter()
.map(|path| format!("-I{}", path.to_string_lossy())),
)
.clang_args(extra_include_paths)
.generate()
.expect("Failed to generate bindings");

Expand Down

0 comments on commit 6bef448

Please sign in to comment.