1 mod target {
2 use std::env;
3 use std::fs::File;
4 use std::io::Write;
5 use std::path::{Path, PathBuf};
6
main()7 pub fn main() {
8 let out_dir = PathBuf::from(env::var("OUT_DIR").unwrap());
9
10 let mut dst =
11 File::create(Path::new(&out_dir).join("host-target.txt")).unwrap();
12 dst.write_all(env::var("TARGET").unwrap().as_bytes())
13 .unwrap();
14 }
15 }
16
17 mod testgen {
18 use std::char;
19 use std::env;
20 use std::ffi::OsStr;
21 use std::fs::{self, File};
22 use std::io::Write;
23 use std::path::{Path, PathBuf};
24
main()25 pub fn main() {
26 let out_dir = PathBuf::from(env::var("OUT_DIR").unwrap());
27 let mut dst =
28 File::create(Path::new(&out_dir).join("tests.rs")).unwrap();
29
30 let manifest_dir =
31 PathBuf::from(env::var("CARGO_MANIFEST_DIR").unwrap());
32 let headers_dir = manifest_dir.join("tests").join("headers");
33
34 let headers = match fs::read_dir(headers_dir) {
35 Ok(dir) => dir,
36 // We may not have headers directory after packaging.
37 Err(..) => return,
38 };
39
40 let entries =
41 headers.map(|result| result.expect("Couldn't read header file"));
42
43 println!("cargo:rerun-if-changed=tests/headers");
44
45 for entry in entries {
46 match entry.path().extension().and_then(OsStr::to_str) {
47 Some("h") | Some("hpp") => {
48 let func = entry
49 .file_name()
50 .to_str()
51 .unwrap()
52 .replace(|c| !char::is_alphanumeric(c), "_")
53 .replace("__", "_")
54 .to_lowercase();
55 writeln!(
56 dst,
57 "test_header!(header_{}, {:?});",
58 func,
59 entry.path(),
60 )
61 .unwrap();
62 }
63 _ => {}
64 }
65 }
66
67 dst.flush().unwrap();
68 }
69 }
70
main()71 fn main() {
72 target::main();
73 testgen::main();
74
75 // On behalf of clang_sys, rebuild ourselves if important configuration
76 // variables change, to ensure that bindings get rebuilt if the
77 // underlying libclang changes.
78 println!("cargo:rerun-if-env-changed=LLVM_CONFIG_PATH");
79 println!("cargo:rerun-if-env-changed=LIBCLANG_PATH");
80 println!("cargo:rerun-if-env-changed=LIBCLANG_STATIC_PATH");
81 println!("cargo:rerun-if-env-changed=BINDGEN_EXTRA_CLANG_ARGS");
82 }
83