1 // Copyright 2022 The ChromiumOS Authors 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 use std::path::PathBuf; 6 7 use pkg_config::Config; 8 main()9fn main() { 10 // Skip building dependencies when generating documents. 11 if std::env::var("CARGO_DOC").is_ok() { 12 return; 13 } 14 15 // ffmpeg is currently only supported on unix 16 if std::env::var("CARGO_CFG_UNIX").is_err() { 17 return; 18 } 19 20 // Match all ffmpeg 6.0+ versions. 21 Config::new() 22 .atleast_version("60") 23 .probe("libavcodec") 24 .unwrap(); 25 Config::new() 26 .atleast_version("58") 27 .probe("libavutil") 28 .unwrap(); 29 Config::new() 30 .atleast_version("7") 31 .probe("libswscale") 32 .unwrap(); 33 34 let bindings = bindgen::Builder::default() 35 .header("src/bindings.h") 36 .allowlist_function("av_.*") 37 .allowlist_function("avcodec_.*") 38 .allowlist_function("sws_.*") 39 .allowlist_function("av_image_.*") 40 .allowlist_var("FF_PROFILE.*") 41 .allowlist_var("AV_.*") 42 .allowlist_var("AVERROR_.*") 43 // Skip va_list and functions that use it to avoid ABI problems on aarch64. 44 .blocklist_type(".*va_list.*") 45 .blocklist_function("av_log_.*") 46 .blocklist_function("av_vlog") 47 .generate() 48 .expect("failed to generate bindings"); 49 let out_path = PathBuf::from(std::env::var("OUT_DIR").unwrap()); 50 bindings 51 .write_to_file(out_path.join("bindings.rs")) 52 .expect("writing bindings to file failed"); 53 } 54