use std::{fs::File, io::Write};
#[cfg(feature = "__bindgen")]
use bindgen::callbacks::{EnumVariantValue, ParseCallbacks};
#[cfg(feature = "__bindgen")]
extern crate bindgen;
fn main() {
#[cfg(feature = "__bindgen")]
{
std::process::Command::new("clang")
.args(["-lavutil", "-lavcodec", "src/codec.c"])
.output()
.unwrap();
let out = std::process::Command::new("./a.out")
.output()
.unwrap()
.stdout;
let mut f = File::options()
.write(true)
.create(true)
.truncate(true)
.open("src/gen.rs")
.unwrap();
f.write_all(out.as_slice()).unwrap();
const VALID_ENUMS: &'static [&'static str] =
&["AVMediaType", "AVPixelFormat", "AVClassCategory"];
let mut b = bindgen::builder()
.use_core()
.generate_cstr(true)
.dynamic_link_require_all(true)
.sort_semantically(true)
.enable_function_attribute_detection()
.blocklist_item("FP_.*")
.rustified_enum(".*")
.newtype_enum("AVPixelFormat")
.translate_enum_integer_types(true);
{
#[cfg(feature = "avformat")]
{
b = b.clang_arg("-D__FFERRIS_ENABLE_AVFORMAT");
}
#[cfg(feature = "avcodec")]
{
b = b.clang_arg("-D__FFERRIS_ENABLE_AVCODEC");
}
#[cfg(feature = "avfilter")]
{
b = b.clang_arg("-D__FFERRIS_ENABLE_AVFILTER");
}
#[cfg(feature = "avdevice")]
{
b = b.clang_arg("-D__FFERRIS_ENABLE_AVDEVICE");
}
}
b
.clang_arg("-fretain-comments-from-system-headers")
.clang_arg("-fparse-all-comments")
.header("src/include.h")
.generate()
.unwrap()
.write_to_file("src/bindings.rs")
.unwrap();
}
for f in ["src/include.h", "src/gen.c"] {
println!("cargo::rerun-if-changed={f}");
}
println!("cargo::rustc-link-search=/usr/lib");
println!("cargo::rustc-link-lib=avutil");
#[cfg(feature = "avformat")]
println!("cargo::rustc-link-lib=avformat");
#[cfg(feature = "avcodec")]
println!("cargo::rustc-link-lib=avcodec");
#[cfg(feature = "avfilter")]
println!("cargo::rustc-link-lib=avfilter");
#[cfg(feature = "avdevice")]
println!("cargo::rustc-link-lib=avdevice");
}