Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
24 changes: 2 additions & 22 deletions crates/libs/bindgen/src/config/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,12 @@ use std::io::Write;

impl Config<'_> {
pub fn format(&self, tokens: &str) -> String {
let preamble = if self.no_comment {
String::new()
} else {
let version = std::env!("CARGO_PKG_VERSION");

format!(
r#"// Bindings generated by `windows-bindgen` {version}


"#
)
};

let allow = if self.no_allow {
""
} else {
"#![allow(non_snake_case, non_upper_case_globals, non_camel_case_types, dead_code, clippy::all)]\n\n"
};
let tokens = format!("{preamble}{allow}{tokens}");

let formatted = if let Some(result) = self.rustfmt(&tokens) {
let formatted = if let Some(result) = self.rustfmt(tokens) {
result
} else {
self.warnings
.add("failed to format output with `rustfmt`".to_string());
tokens
tokens.to_string()
};

// `proc_macro2::TokenStream::to_string()` inserts a space between
Expand Down
2 changes: 0 additions & 2 deletions crates/libs/bindgen/src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ pub struct Config<'a> {
pub filter: &'a Filter,
pub output: &'a str,
pub flat: bool,
pub no_allow: bool,
pub no_comment: bool,
pub no_deps: bool,
pub no_toml: bool,
pub package: bool,
Expand Down
42 changes: 0 additions & 42 deletions crates/libs/bindgen/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,6 @@ pub fn builder() -> Bindgen {
/// | `--rustfmt` | Overrides the default Rust formatting. |
/// | `--derive` | Extra traits for types to derive. |
/// | `--flat` | Avoids the default namespace-to-module conversion. |
/// | `--no-allow` | Avoids generating the default `allow` attribute. |
/// | `--no-comment` | Avoids generating the code generation comment. |
/// | `--no-deps` | Avoids dependencies on the various `windows-*` crates. |
/// | `--specific-deps` | Uses specific crate dependencies rather than `windows-core`. |
/// | `--sys` | Generates raw or sys-style Rust bindings. |
Expand Down Expand Up @@ -267,24 +265,6 @@ pub fn builder() -> Bindgen {
/// }
/// ```
///
/// # `--no-allow`
///
/// The bindings also include an allow attribute that covers various common warnings inherent in
/// generated bindings.
///
/// ```rust
/// #![allow(
/// non_snake_case,
/// non_upper_case_globals,
/// non_camel_case_types,
/// dead_code,
/// clippy::all
/// )]
/// ```
///
/// You can prevent this from being generated if you prefer to manage this yourself with the `--no-allow`
/// argument.
///
/// # `--sys`
///
/// The `--sys` argument instruct the `bindgen` function to generate raw, sometimes called sys-style Rust
Expand Down Expand Up @@ -388,12 +368,6 @@ where
"--flat" => {
builder.flat();
}
"--no-allow" => {
builder.no_allow();
}
"--no-comment" => {
builder.no_comment();
}
"--no-deps" => {
builder.no_deps();
}
Expand Down Expand Up @@ -501,8 +475,6 @@ pub struct Bindgen {
rustfmt: String,
link: String,
flat: bool,
no_allow: bool,
no_comment: bool,
no_deps: bool,
no_toml: bool,
package: bool,
Expand Down Expand Up @@ -629,18 +601,6 @@ impl Bindgen {
self
}

/// Avoid generating the default `allow` attribute.
pub fn no_allow(&mut self) -> &mut Self {
self.no_allow = true;
self
}

/// Avoid generating the code generation comment.
pub fn no_comment(&mut self) -> &mut Self {
self.no_comment = true;
self
}

/// Avoid dependencies on the various `windows-*` crates.
pub fn no_deps(&mut self) -> &mut Self {
self.no_deps = true;
Expand Down Expand Up @@ -906,8 +866,6 @@ impl Bindgen {
references: &references,
filter: &filter,
derive: &derive,
no_allow: self.no_allow,
no_comment: self.no_comment,
no_deps: self.no_deps,
no_toml: self.no_toml,
package: self.package,
Expand Down
8 changes: 0 additions & 8 deletions crates/libs/strings/src/bindings.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,3 @@
#![allow(
non_snake_case,
non_upper_case_globals,
non_camel_case_types,
dead_code,
clippy::all
)]

windows_link::link!("kernel32.dll" "system" fn GetProcessHeap() -> HANDLE);
windows_link::link!("kernel32.dll" "system" fn HeapAlloc(hheap : HANDLE, dwflags : HEAP_FLAGS, dwbytes : usize) -> *mut core::ffi::c_void);
windows_link::link!("kernel32.dll" "system" fn HeapFree(hheap : HANDLE, dwflags : HEAP_FLAGS, lpmem : *const core::ffi::c_void) -> BOOL);
Expand Down
7 changes: 7 additions & 0 deletions crates/libs/strings/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,13 @@ mod hstring_header;
use hstring_header::*;

#[cfg(windows)]
#[allow(
non_snake_case,
non_upper_case_globals,
non_camel_case_types,
dead_code,
clippy::all
)]
mod bindings;

mod decode;
Expand Down
10 changes: 0 additions & 10 deletions crates/samples/json/json_validator_winrt/src/bindings.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,3 @@
// Bindings generated by `windows-bindgen` 0.66.0

#![allow(
non_snake_case,
non_upper_case_globals,
non_camel_case_types,
dead_code,
clippy::all
)]

windows_core::imp::define_interface!(
IJsonValidator,
IJsonValidator_Vtbl,
Expand Down
7 changes: 7 additions & 0 deletions crates/samples/json/json_validator_winrt/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
#![cfg(windows)]
#[allow(
non_snake_case,
non_upper_case_globals,
non_camel_case_types,
dead_code,
clippy::all
)]
mod bindings;
use jsonschema::Validator;
use windows::{core::*, Win32::Foundation::*, Win32::System::WinRT::*};
Expand Down
10 changes: 0 additions & 10 deletions crates/samples/json/json_validator_winrt_client/src/bindings.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,3 @@
// Bindings generated by `windows-bindgen` 0.66.0

#![allow(
non_snake_case,
non_upper_case_globals,
non_camel_case_types,
dead_code,
clippy::all
)]

windows_core::imp::define_interface!(
IJsonValidator,
IJsonValidator_Vtbl,
Expand Down
7 changes: 7 additions & 0 deletions crates/samples/json/json_validator_winrt_client/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
#![cfg(all(test, windows))]

#[allow(
non_snake_case,
non_upper_case_globals,
non_camel_case_types,
dead_code,
clippy::all
)]
mod bindings;
use bindings::*;
use windows::{core::*, Win32::Foundation::*};
Expand Down
10 changes: 0 additions & 10 deletions crates/samples/robot/client/src/bindings.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,3 @@
// Bindings generated by `windows-bindgen` 0.66.0

#![allow(
non_snake_case,
non_upper_case_globals,
non_camel_case_types,
dead_code,
clippy::all
)]

#[inline]
pub unsafe fn CreateRobotFromHandle(
handle: *const core::ffi::c_void,
Expand Down
7 changes: 7 additions & 0 deletions crates/samples/robot/client/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
#![cfg(all(test, windows))]

#[allow(
non_snake_case,
non_upper_case_globals,
non_camel_case_types,
dead_code,
clippy::all
)]
mod bindings;
use bindings::*;
use windows_core::*;
Expand Down
10 changes: 0 additions & 10 deletions crates/samples/robot/component/src/bindings.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,3 @@
// Bindings generated by `windows-bindgen` 0.66.0

#![allow(
non_snake_case,
non_upper_case_globals,
non_camel_case_types,
dead_code,
clippy::all
)]

#[inline]
pub unsafe fn CreateRobotFromHandle(
handle: *const core::ffi::c_void,
Expand Down
7 changes: 7 additions & 0 deletions crates/samples/robot/component/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
#![cfg(windows)]
#[allow(
non_snake_case,
non_upper_case_globals,
non_camel_case_types,
dead_code,
clippy::all
)]
mod bindings;
use windows::{core::*, Win32::Foundation::*, Win32::System::WinRT::*};

Expand Down
10 changes: 0 additions & 10 deletions crates/samples/services/time/src/bindings.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,3 @@
// Bindings generated by `windows-bindgen` 0.66.0

#![allow(
non_snake_case,
non_upper_case_globals,
non_camel_case_types,
dead_code,
clippy::all
)]

windows_link::link!("kernel32.dll" "system" fn FileTimeToLocalFileTime(lpfiletime : *const FILETIME, lplocalfiletime : *mut FILETIME) -> BOOL);
windows_link::link!("kernel32.dll" "system" fn FileTimeToSystemTime(lpfiletime : *const FILETIME, lpsystemtime : *mut SYSTEMTIME) -> BOOL);
pub type BOOL = i32;
Expand Down
7 changes: 7 additions & 0 deletions crates/samples/services/time/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@
fn main() {}

#[cfg(windows)]
#[allow(
non_snake_case,
non_upper_case_globals,
non_camel_case_types,
dead_code,
clippy::all
)]
mod bindings;

#[cfg(windows)]
Expand Down
10 changes: 0 additions & 10 deletions crates/samples/windows/webview/src/bindings.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,3 @@
// Bindings generated by `windows-bindgen` 0.66.0

#![allow(
non_snake_case,
non_upper_case_globals,
non_camel_case_types,
dead_code,
clippy::all
)]

#[inline]
pub unsafe fn CompareBrowserVersions(
version1: PCWSTR,
Expand Down
7 changes: 7 additions & 0 deletions crates/samples/windows/webview/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@
fn main() {}

#[cfg(windows)]
#[allow(
non_snake_case,
non_upper_case_globals,
non_camel_case_types,
dead_code,
clippy::all
)]
mod bindings;

#[cfg(windows)]
Expand Down
10 changes: 0 additions & 10 deletions crates/samples/windows/xaml_app/src/bindings.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,3 @@
// Bindings generated by `windows-bindgen` 0.66.0

#![allow(
non_snake_case,
non_upper_case_globals,
non_camel_case_types,
dead_code,
clippy::all
)]

#[repr(transparent)]
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct Application(windows_core::IUnknown);
Expand Down
1 change: 1 addition & 0 deletions crates/samples/windows/xaml_app/src/windows_main.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#[allow(non_snake_case, non_upper_case_globals, non_camel_case_types, dead_code, clippy::all)]
mod bindings;
use bindings::*;

Expand Down
2 changes: 0 additions & 2 deletions crates/tests/libs/bindgen/data/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@ Supported keys:
| `filter` | string | all | namespace filter (default: `"Test"`) |
| `references` | string[] | rdl/clang/bindgen/merge/winmd_to_rdl | extra reader/writer inputs (paths relative to the fixture dir for `winmd_to_rdl`) |
| `winmd_input` | string | winmd_to_rdl | path (relative to the fixture dir) of the prebuilt winmd to filter |
| `no_allow` | bool | bindgen | pass `--no-allow` to bindgen |
| `no_comment` | bool | bindgen | pass `--no-comment` to bindgen |
| `specific_deps` | bool | bindgen | pass `--specific-deps` to bindgen |
| `kind` | string | error | `"reader"` (default), `"reader_no_input"`, `"writer"`, or `"bindgen"` — which stage must fail |
| `arch_inputs` | string[] | merge | per-input arch tagging, e.g. `["input-x86.rdl=X86", "input-x64.rdl=X64"]`. Arches are `X86`/`X64`/`Arm64` or `\|`-joined. |
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
filter = "Test"
no_allow = true
no_comment = true
minimal = true
8 changes: 0 additions & 8 deletions crates/tests/libs/bindgen/data/bindgen/bool/expected.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,3 @@
#![allow(
non_snake_case,
non_upper_case_globals,
non_camel_case_types,
dead_code,
clippy::all
)]

#[inline]
pub unsafe fn EnableMouseInPointer(fenable: bool) -> windows_core::Result<()> {
windows_core::link!("user32.dll" "system" fn EnableMouseInPointer(fenable : windows_core::BOOL) -> windows_core::BOOL);
Expand Down
2 changes: 1 addition & 1 deletion crates/tests/libs/bindgen/data/bindgen/bool/fixture.toml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
args = "--no-comment --in default --flat --filter EnableMouseInPointer"
args = "--in default --flat --filter EnableMouseInPointer"
8 changes: 0 additions & 8 deletions crates/tests/libs/bindgen/data/bindgen/bool_event/expected.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,3 @@
#![allow(
non_snake_case,
non_upper_case_globals,
non_camel_case_types,
dead_code,
clippy::all
)]

#[inline]
pub unsafe fn CreateEventW<P3>(
lpeventattributes: Option<*const windows::Win32::Security::SECURITY_ATTRIBUTES>,
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
args = "--no-comment --in default --flat --filter CreateEventW SetEvent NtWaitForSingleObject WaitForSingleObjectEx --reference windows,skip-root,Windows"
args = "--in default --flat --filter CreateEventW SetEvent NtWaitForSingleObject WaitForSingleObjectEx --reference windows,skip-root,Windows"
Original file line number Diff line number Diff line change
@@ -1,11 +1,3 @@
#![allow(
non_snake_case,
non_upper_case_globals,
non_camel_case_types,
dead_code,
clippy::all
)]

#[inline]
pub unsafe fn CreateEventW<P3>(
lpeventattributes: Option<*const SECURITY_ATTRIBUTES>,
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
args = "--no-comment --in default --flat --filter CreateEventW SetEvent NtWaitForSingleObject WaitForSingleObjectEx"
args = "--in default --flat --filter CreateEventW SetEvent NtWaitForSingleObject WaitForSingleObjectEx"
Loading
Loading