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: Rust formatter override.
  • --derive: Extra derived traits.
  • --flat: Omits namespace modules.
  • --sys: Generates raw bindings that depend only on windows-link.
  • --extern: Uses extern declarations with --sys.
  • --minimal: Omits class wrappers, inherited forwarders, and handle wrappers.
  • --implement: Emits implementation traits for selected WinRT interfaces.
  • --compose: Selects minimal-mode 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

Exactly one --out argument is required.

§--filter

Filters select APIs to include. Prefix a filter with ! to exclude it.

--filter Windows.Win32.Storage.FileSystem.GetFullPathNameW

--filter Windows.Win32.Storage.FileSystem.GetFullPathNameW
         !Windows.Win32.Storage.FileSystem.WIN32_FIND_DATAW

--filter Windows.Win32.Storage.FileSystem

--filter Windows.Win32.Storage.FileSystem
         !Windows.Win32.Storage.FileSystem.WIN32_FIND_DATAW

Use a filter file for longer filter lists:

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

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

§Method-level filtering

Filters can target methods, properties, and events with Namespace.Type::Member. Property.Name and Event.Name select accessor pairs.

A bare type projects the full type. Type::{} emits a name-only shell, while Type::Member and Type::{a, b} select members.

--filter Windows.UI.Xaml.Controls.Button
         Windows.UI.Xaml.Controls.TextBlock::put_Text
         Windows.UI.Xaml.Controls.TextBlock::Property.FontSize
         Windows.UI.Xaml.UIElement::Event.PointerPressed