1 // Copyright 2024 Google LLC 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 #[cfg(feature = "capi")] 16 use std::path::PathBuf; 17 main()18fn main() { 19 println!("cargo:rerun-if-changed=build.rs"); 20 println!("cargo:rerun-if-changed=cbindgen.toml"); 21 #[cfg(feature = "libgav1")] 22 { 23 // libgav1 needs libstdc++ on *nix/windows and libc++ on mac. 24 if cfg!(target_os = "macos") { 25 println!("cargo:rustc-link-arg=-lc++"); 26 } else { 27 println!("cargo:rustc-link-arg=-lstdc++"); 28 } 29 } 30 #[cfg(feature = "capi")] 31 { 32 // Generate the C header. 33 let crate_path = env!("CARGO_MANIFEST_DIR"); 34 let config = cbindgen::Config::from_root_or_default(crate_path); 35 let header_file = PathBuf::from(crate_path).join("include/avif/avif.h"); 36 cbindgen::Builder::new() 37 .with_crate(crate_path) 38 .with_config(config) 39 .generate() 40 .unwrap() 41 .write_to_file(header_file); 42 } 43 } 44