From 01d88aa09ba10a1d408df621a3f7cd0becaa85d2 Mon Sep 17 00:00:00 2001 From: Ryan Hunt <rhunt@eqrion.net> Date: Tue, 20 Jun 2017 01:48:34 -0400 Subject: [PATCH] Allow excluding specific crates from being parsed --- src/bindgen/config.rs | 3 +++ src/bindgen/library.rs | 1 + src/bindgen/rust_lib.rs | 6 +++++- 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/bindgen/config.rs b/src/bindgen/config.rs index 9f85360..e4a54d9 100644 --- a/src/bindgen/config.rs +++ b/src/bindgen/config.rs @@ -267,6 +267,8 @@ pub struct Config { pub tab_width: usize, /// The language to output bindings for pub language: Language, + /// The names of crates to not parse + pub exclude: Vec<String>, /// The names of crates to parse with `rustc --pretty=expanded` pub expand: Vec<String>, /// The configuration options for functions @@ -292,6 +294,7 @@ impl Default for Config { line_length: 100, tab_width: 2, language: Language::Cxx, + exclude: Vec::new(), expand: Vec::new(), function: FunctionConfig::default(), structure: StructConfig::default(), diff --git a/src/bindgen/library.rs b/src/bindgen/library.rs index 1794286..3f16195 100644 --- a/src/bindgen/library.rs +++ b/src/bindgen/library.rs @@ -128,6 +128,7 @@ impl<'a> Library<'a> { rust_lib::parse_lib(crate_dir, bindings_crate_name, + &config.exclude, &config.expand, &mut |crate_name, items| { library.load_from_crate_mod(&crate_name, items); diff --git a/src/bindgen/rust_lib.rs b/src/bindgen/rust_lib.rs index 1dfb94b..daa2002 100644 --- a/src/bindgen/rust_lib.rs +++ b/src/bindgen/rust_lib.rs @@ -44,6 +44,7 @@ pub fn parse_src<F>(src_file: &Path, /// command to find the location of dependencies. pub fn parse_lib<F>(crate_path: &Path, binding_crate_name: &str, + exclude: &[String], expand: &[String], items_callback: &mut F) -> ParseResult where F: FnMut(&str, &Vec<syn::Item>) @@ -60,6 +61,7 @@ pub fn parse_lib<F>(crate_path: &Path, let mut context = ParseLibContext { manifest_path: manifest_path, metadata: metadata, + exclude: exclude.to_owned(), expand: expand.to_owned(), cache_src: HashMap::new(), cache_expanded_crate: HashMap::new(), @@ -74,6 +76,7 @@ struct ParseLibContext<F> { manifest_path: PathBuf, metadata: cargo_metadata::Metadata, + exclude: Vec<String>, expand: Vec<String>, cache_src: HashMap<PathBuf, Vec<syn::Item>>, cache_expanded_crate: HashMap<String, Vec<syn::Item>>, @@ -103,7 +106,8 @@ impl<F> ParseLibContext<F> fn parse_crate<F>(crate_name: &str, context: &mut ParseLibContext<F>) -> ParseResult where F: FnMut(&str, &Vec<syn::Item>) { - if STD_CRATES.contains(&crate_name) { + if STD_CRATES.contains(&crate_name) || + context.exclude.contains(&crate_name.to_owned()) { return Ok(()); } -- GitLab