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 // https://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 use bindgen; 16 use std::env; 17 use std::path::PathBuf; 18 main()19pub fn main() { 20 println!("cargo:rerun-if-changed=bindings/wrapper.h"); 21 println!("cargo:rerun-if-changed=build.rs"); 22 23 let bindings = bindgen::Builder::default() 24 .header("bindings/wrapper.h") 25 .generate() 26 .expect("Unable to generate bindings"); 27 28 let target_os = env::var("CARGO_CFG_TARGET_OS").unwrap(); 29 let out_dir = PathBuf::from(env::var("CARGO_MANIFEST_DIR").unwrap()) 30 .join("src") 31 .join("libslirp_sys") 32 .join(target_os); 33 34 std::fs::create_dir_all(&out_dir).expect("Failed to create output directory"); 35 36 let out_path = out_dir.join("bindings.rs"); 37 bindings.write_to_file(out_path).expect("Couldn't write bindings!"); 38 } 39