Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v4l2-sys: Replace FreeBSD **host-only** include path override with docs #114

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,3 +94,21 @@ fn main() {
```

Have a look at the provided `examples` for more sample applications.

### Building and cross-compiling

When building on targets like FreeBSD, or cross-compiling for different targets entirely (as identified by their _target triple_), bindgen may not know where to find the headers if they are located in a nonstandard directory like `/usr/local/include`, resulting in an error similar to `wrapper.h:1:10: fatal error: 'linux/videodev2.h' file not found`. In this case, provide the system include directory with the `-I` flag using the [target-specific environment variable][bindgen-env] (note that `-` is typically substituted with `_` to help shells like `bash` parse it successfully):

```console
$ BINDGEN_EXTRA_CLANG_ARGS_x86_64_unknown_freebsd="-I/usr/local/include" cargo build --target x86_64-unknown-freebsd
```

It is also possible to set this environment variable for Rust inside [`.cargo/config.toml`][cargo-config] in your project directory or user home directory:

```toml
[env]
BINDGEN_EXTRA_CLANG_ARGS_x86_64-unknown-freebsd = "-I/usr/local/include"
```

[bindgen-env]: https://github.com/rust-lang/rust-bindgen/blob/main/README.md#environment-variables
[cargo-config]: https://doc.rust-lang.org/cargo/reference/config.html
15 changes: 1 addition & 14 deletions v4l2-sys/build.rs
Original file line number Diff line number Diff line change
@@ -1,24 +1,11 @@
extern crate bindgen;

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

fn main() {
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(extra_include_paths)
.generate()
.expect("Failed to generate bindings");

Expand Down