build.rs

 1#[cfg(target_os = "macos")]
 2fn main() {
 3    use std::{env, path::PathBuf, process::Command};
 4
 5    let sdk_path = String::from_utf8(
 6        Command::new("xcrun")
 7            .args(["--sdk", "macosx", "--show-sdk-path"])
 8            .output()
 9            .unwrap()
10            .stdout,
11    )
12    .unwrap();
13    let sdk_path = sdk_path.trim_end();
14
15    println!("cargo:rerun-if-changed=src/bindings.h");
16    let bindings = bindgen::Builder::default()
17        .header("src/bindings.h")
18        .clang_arg(format!("-isysroot{}", sdk_path))
19        .clang_arg("-xobjective-c")
20        .allowlist_type("CMItemIndex")
21        .allowlist_type("CMSampleTimingInfo")
22        .allowlist_type("CMVideoCodecType")
23        .allowlist_type("VTEncodeInfoFlags")
24        .allowlist_function("CMTimeMake")
25        .allowlist_var("kCVPixelFormatType_.*")
26        .allowlist_var("kCVReturn.*")
27        .allowlist_var("VTEncodeInfoFlags_.*")
28        .allowlist_var("kCMVideoCodecType_.*")
29        .allowlist_var("kCMTime.*")
30        .allowlist_var("kCMSampleAttachmentKey_.*")
31        .parse_callbacks(Box::new(bindgen::CargoCallbacks::new()))
32        .layout_tests(false)
33        .generate()
34        .expect("unable to generate bindings");
35
36    let out_path = PathBuf::from(env::var("OUT_DIR").unwrap());
37    bindings
38        .write_to_file(out_path.join("bindings.rs"))
39        .expect("couldn't write dispatch bindings");
40}
41
42#[cfg(not(target_os = "macos"))]
43fn main() {}