Skip to content

Commit

Permalink
Add option to disable generating inner attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
dpaoliello committed Oct 17, 2023
1 parent 4c234b5 commit 430a250
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 2 deletions.
1 change: 1 addition & 0 deletions crates/libs/bindgen/src/rust/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ pub fn from_reader(reader: &metadata::Reader, filter: &metadata::Filter, mut con
writer.sys = writer.std || config.remove("sys").is_some();
writer.implement = config.remove("implement").is_some();
writer.minimal = config.remove("minimal").is_some();
writer.no_inner_attributes = config.remove("no-inner-attributes").is_some();

if writer.package && writer.flatten {
return Err(Error::new("cannot combine `package` and `flatten` configuration values"));
Expand Down
2 changes: 1 addition & 1 deletion crates/libs/bindgen/src/rust/try_format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ pub fn try_format(writer: &super::Writer, tokens: &str) -> String {
};

// Packaging - e.g. windows/windows-sys crates - assumes the crate will allow whatever warnings it deems fit.
let allow = if writer.package { "" } else { "#![allow(non_snake_case, non_upper_case_globals, non_camel_case_types, dead_code, clippy::all)]\n" };
let allow = if writer.package || writer.no_inner_attributes { "" } else { "#![allow(non_snake_case, non_upper_case_globals, non_camel_case_types, dead_code, clippy::all)]\n" };
let tokens = format!("{preamble}{allow}{tokens}");

let Ok(mut child) = std::process::Command::new("rustfmt").stdin(std::process::Stdio::piped()).stdout(std::process::Stdio::piped()).stderr(std::process::Stdio::null()).spawn() else {
Expand Down
3 changes: 2 additions & 1 deletion crates/libs/bindgen/src/rust/writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,12 @@ pub struct Writer<'a> {
pub flatten: bool, // strips out namespaces - implies !package
pub package: bool, // default is single file with no cfg - implies !flatten
pub minimal: bool, // strips out enumerators - in future possibly other helpers as well
pub no_inner_attributes: bool, // skips the inner attributes at the start of the file
}

impl<'a> Writer<'a> {
pub fn new(reader: &'a Reader, filter: &'a metadata::Filter, output: &'a str) -> Self {
Self { reader, filter, output, namespace: "", implement: false, std: false, sys: false, flatten: false, package: false, minimal: false }
Self { reader, filter, output, namespace: "", implement: false, std: false, sys: false, flatten: false, package: false, minimal: false, no_inner_attributes: false }
}

//
Expand Down

0 comments on commit 430a250

Please sign in to comment.