• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 use std::env;
2 
3 mod options;
4 use crate::options::builder_from_flags;
5 
6 #[cfg(feature = "logging")]
clang_version_check()7 fn clang_version_check() {
8     let version = bindgen::clang_version();
9     let expected_version = if cfg!(feature = "__testing_only_libclang_16") {
10         Some((16, 0))
11     } else if cfg!(feature = "__testing_only_libclang_9") {
12         Some((9, 0))
13     } else {
14         None
15     };
16 
17     log::info!(
18         "Clang Version: {}, parsed: {:?}",
19         version.full,
20         version.parsed
21     );
22 
23     if expected_version.is_some() {
24         // assert_eq!(version.parsed, version.parsed);
25     }
26 }
27 
main()28 pub fn main() {
29     #[cfg(feature = "logging")]
30     env_logger::init();
31 
32     match builder_from_flags(env::args()) {
33         Ok((builder, output, verbose)) => {
34             #[cfg(feature = "logging")]
35             clang_version_check();
36 
37             std::panic::set_hook(Box::new(move |info| {
38                 if verbose {
39                     print_verbose_err()
40                 }
41                 eprintln!("{}", info);
42             }));
43 
44             let bindings =
45                 builder.generate().expect("Unable to generate bindings");
46 
47             let _ = std::panic::take_hook();
48 
49             bindings.write(output).expect("Unable to write output");
50         }
51         Err(error) => {
52             eprintln!("{}", error);
53             std::process::exit(1);
54         }
55     };
56 }
57 
print_verbose_err()58 fn print_verbose_err() {
59     eprintln!("Bindgen unexpectedly panicked");
60     eprintln!(
61         "This may be caused by one of the known-unsupported \
62          things (https://rust-lang.github.io/rust-bindgen/cpp.html), \
63          please modify the bindgen flags to work around it as \
64          described in https://rust-lang.github.io/rust-bindgen/cpp.html"
65     );
66     eprintln!(
67         "Otherwise, please file an issue at \
68          https://github.com/rust-lang/rust-bindgen/issues/new"
69     );
70 }
71