build.rs

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