diff options
author | Kent Fredric <kentnl@gentoo.org> | 2020-02-23 21:23:28 +1300 |
---|---|---|
committer | Emilio Cobos Álvarez <emilio@crisal.io> | 2020-02-24 12:31:37 +0100 |
commit | 4b5fe8e6011bd6dfd9fb73da403099aa395052ff (patch) | |
tree | 8acf3d642548eb5e1a7fe8adfabc83eee60c71e2 | |
parent | d65100ebbaffabcc91e81ba3e88160de7cb2d5ff (diff) |
Delay invoking clang version checks until a functional path is taken
This allows avoiding large numbers of system calls to dynaload clang
to determine its version, when no action is performed, for example:
- When calling --version / -V
- When calling --help
This improves the raw responsivity from:
Before:
time bindgen --help # 0.593s
strace -cf bindgen --help # 83k syscalls, 64k to statx
After:
time bindgen --help # 0.004s
strace -cf bindgen --help # 90 syscalls
However, it does mean that you can no longer obtain the discovered
clang version with:
RUST_LOG=info bindgen -V
But this may be remedied in a future commit.
Closes: https://github.com/rust-lang/rust-bindgen/issues/1736
-rw-r--r-- | src/main.rs | 15 |
1 files changed, 9 insertions, 6 deletions
diff --git a/src/main.rs b/src/main.rs index ad0915e4..9cf03069 100644 --- a/src/main.rs +++ b/src/main.rs @@ -17,12 +17,7 @@ mod log_stubs; mod options; use options::builder_from_flags; -pub fn main() { - #[cfg(feature = "logging")] - env_logger::init(); - - let bind_args: Vec<_> = env::args().collect(); - +fn clang_version_check() { let version = clang_version(); let expected_version = if cfg!(feature = "testing_only_libclang_9") { Some((9, 0)) @@ -46,9 +41,17 @@ pub fn main() { if expected_version.is_some() { assert_eq!(version.parsed, version.parsed); } +} + +pub fn main() { + #[cfg(feature = "logging")] + env_logger::init(); + + let bind_args: Vec<_> = env::args().collect(); match builder_from_flags(bind_args.into_iter()) { Ok((builder, output, verbose)) => { + clang_version_check(); let builder_result = panic::catch_unwind(|| { builder.generate().expect("Unable to generate bindings") }); |