Skip to main content

bindgen

Function bindgen 

Source
pub fn bindgen<I, S>(args: I)
where I: IntoIterator<Item = S>, S: AsRef<str>,
Expand description

Generates bindings using command-line-style arguments.

let args = [
    "--out",
    "src/bindings.rs",
    "--filter",
    "GetTickCount",
];

windows_bindgen::bindgen(args);

Supported arguments:

  • --in: Metadata files or directories.
  • --out: Generated Rust file.
  • --filter: Included or excluded APIs.
  • --rustfmt: Comma-separated rustfmt --config options, such as max_width=120.
  • --derive: Extra derives as Type=Trait,OtherTrait, for example SYSTEMTIME=Debug.
  • --modules: Nests items in one module per namespace.
  • --package: Generates a package with one file per namespace.
  • --sys: Generates raw bindings that depend only on windows-link.
  • --extern: Uses extern declarations in any style; the caller supplies import libraries.
  • --full: Adds class wrappers, inherited forwarders, handle wrappers, and implementation traits for interfaces not marked ExclusiveTo.
  • --implement: Implementation traits for dotted interface names or namespace prefixes. Without names, includes every native and WinRT interface in scope. See Bindgen::implement for restrictions on member filters with named selectors.
  • --compose: Selects WinRT class composition targets.
  • --dead-code: Emits pub(crate) items for dead-code analysis.
  • --etc: Reads arguments from command files.
  • --filter-file: Reads filters from text files.

§--out

Defaults to bindings.rs in the runtime OUT_DIR directory. An explicit path is required when OUT_DIR is unset or empty, and always with --package. Bindgen does not emit Cargo dependency-tracking directives.

§--filter

Uses the same syntax as Bindgen::filter, including groups and exclusions:

--filter GetTickCount HWND

--filter Windows.Win32.GetTickCount

--filter Windows::Win32::{GetTickCount, GetTickCount64}

--filter Windows.Foundation

See Bindgen::filter for name resolution, member selection, dependencies, and rule precedence.

§--filter-file and --etc

Use a filter file for longer filter lists:

--filter-file path/to/filter.txt

Filter and command files separate arguments with whitespace. Filter expressions keep {...} groups together across lines and allow trailing commas:

ID2D1RenderTarget::{
    BeginDraw,
    EndDraw,
    Clear, // Reset the surface
}

Lines beginning with // after optional whitespace are comments. Inline comments start with a separate // token, followed by whitespace or the end of the line. This leaves UNC paths such as --in //server/share/input.winmd intact. In command files, grouping applies only to --filter arguments; braces in paths are literal.

The in-repo crates use this convention; see the filter .txt files in crates/tools/bindings/src.