Struct bindgen::Builder [] [src]

pub struct Builder { /* fields omitted */ }

Configure and generate Rust bindings for a C/C++ header.

This is the main entry point to the library.

use bindgen::builder;

// Configure and generate bindings.
let bindings = try!(builder().header("path/to/input/header")
                             .whitelisted_type("SomeCoolClass")
                             .whitelisted_function("do_some_cool_thing")
                             .generate());

// Write the generated bindings to an output file.
try!(bindings.write_to_file("path/to/output.rs"));

Methods

impl Builder
[src]

Generates the command line flags use for creating Builder.

Add an input C/C++ header to generate bindings for.

This can be used to generate bindings to a single header:

let bindings = bindgen::Builder::default()
    .header("input.h")
    .generate()
    .unwrap();

Or you can invoke it multiple times to generate bindings to multiple headers:

let bindings = bindgen::Builder::default()
    .header("first.h")
    .header("second.h")
    .header("third.h")
    .generate()
    .unwrap();

Add contents as an input C/C++ header named name.

The file name will be added to the clang arguments.

Set the output graphviz file.

Whether the generated bindings should contain documentation comments or not.

This ideally will always be true, but it may need to be false until we implement some processing on comments to work around issues as described in:

https://github.com/servo/rust-bindgen/issues/426

Whether to whitelist types recursively or not. Defaults to true.

This can be used to get bindgen to generate exactly the types you want in your bindings, and then import other types manually via other means (like raw_line).

Generate #[macro_use] extern crate objc; instead of use objc; in the prologue of the files generated from objective-c files

Whether to use the clang-provided name mangling. This is true by default and probably needed for C++ features.

However, some old libclang versions seem to return incorrect results in some cases for non-mangled functions, see 1, so we allow disabling it.

Generate a C/C++ file that includes the header and has dummy uses of every type defined in the header.

Hide the given type from the generated bindings. Regular expressions are supported.

Treat the given type as opaque in the generated bindings. Regular expressions are supported.

Whitelist the given type so that it (and all types that it transitively refers to) appears in the generated bindings. Regular expressions are supported.

Whitelist the given function so that it (and all types that it transitively refers to) appears in the generated bindings. Regular expressions are supported.

Whitelist the given variable so that it (and all types that it transitively refers to) appears in the generated bindings. Regular expressions are supported.

Mark the given enum (or set of enums, if using a pattern) as being bitfield-like. Regular expressions are supported.

This makes bindgen generate a type that isn't a rust enum. Regular expressions are supported.

Mark the given enum (or set of enums, if using a pattern) as being constant.

This makes bindgen generate constants instead of enums. Regular expressions are supported.

Add a string to prepend to the generated bindings. The string is passed through without any modification.

Add an argument to be passed straight through to clang.

Add arguments to be passed straight through to clang.

Make the generated bindings link the given shared library.

Make the generated bindings link the given static library.

Make the generated bindings link the given framework.

Emit bindings for builtin definitions (for example __builtin_va_list) in the generated Rust.

Avoid converting floats to f32/f64 by default.

Set whether layout tests should be generated.

Set whether Debug should be derived by default.

Set whether Default should be derived by default.

Emit Clang AST.

Emit IR.

Enable C++ namespaces.

Disable name auto-namespacing.

By default, bindgen mangles names like foo::bar::Baz to look like foo_bar_Baz instead of just Baz.

This method disables that behavior.

Note that this intentionally does not change the names used for whitelisting and blacklisting, which should still be mangled with the namespaces.

Note, also, that this option may cause bindgen to generate duplicate names.

Treat inline namespaces conservatively.

This is tricky, because in C++ is technically legal to override an item defined in an inline namespace:

inline namespace foo {
    using Bar = int;
}
using Bar = long;

Even though referencing Bar is a compiler error.

We want to support this (arguably esoteric) use case, but we don't want to make the rest of bindgen users pay an usability penalty for that.

To support this, we need to keep all the inline namespaces around, but then bindgen usage is a bit more difficult, because you cannot reference, e.g., std::string (you'd need to use the proper inline namespace).

We could complicate a lot of the logic to detect name collisions, and if not detected generate a pub use inline_ns::* or something like that.

That's probably something we can do if we see this option is needed in a lot of cases, to improve it's usability, but my guess is that this is not going to be too useful.

Whether inline functions should be generated or not.

Note that they will usually not work. However you can use -fkeep-inline-functions or -fno-inline-functions if you are responsible of compiling the library to make them callable.

Ignore functions.

Ignore methods.

Avoid generating any unstable Rust, such as Rust unions, in the generated bindings.

Use core instead of libstd in the generated bindings.

Use the given prefix for the raw types instead of ::std::os::raw.

Allows configuring types in different situations, see the ParseCallbacks documentation.

Choose what to generate using a CodegenConfig.

Prepend the enum name to constant or bitfield variants.

Generate the Rust bindings using the options built up thus far.

Trait Implementations

impl Debug for Builder
[src]

Formats the value using the given formatter.

impl Default for Builder
[src]

Returns the "default value" for a type. Read more