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]
fn command_line_flags(&self) -> Vec<String>
Generates the command line flags use for creating Builder
.
fn header<T: Into<String>>(self, header: T) -> 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();
fn header_contents(self, name: &str, contents: &str) -> Builder
Add contents
as an input C/C++ header named name
.
The file name
will be added to the clang arguments.
fn emit_ir_graphviz<T: Into<String>>(self, path: T) -> Builder
Set the output graphviz file.
fn generate_comments(self, doit: bool) -> Self
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/rust-lang-nursery/rust-bindgen/issues/426
fn whitelist_recursively(self, doit: bool) -> Self
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
).
fn objc_extern_crate(self, doit: bool) -> Self
Generate #[macro_use] extern crate objc;
instead of use objc;
in the prologue of the files generated from objective-c files
fn trust_clang_mangling(self, doit: bool) -> Self
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.
fn dummy_uses<T: Into<String>>(self, dummy_uses: T) -> Builder
Generate a C/C++ file that includes the header and has dummy uses of every type defined in the header.
fn hide_type<T: AsRef<str>>(self, arg: T) -> Builder
Hide the given type from the generated bindings. Regular expressions are supported.
fn opaque_type<T: AsRef<str>>(self, arg: T) -> Builder
Treat the given type as opaque in the generated bindings. Regular expressions are supported.
fn whitelisted_type<T: AsRef<str>>(self, arg: T) -> Builder
Whitelist the given type so that it (and all types that it transitively refers to) appears in the generated bindings. Regular expressions are supported.
fn whitelisted_function<T: AsRef<str>>(self, arg: T) -> Builder
Whitelist the given function so that it (and all types that it transitively refers to) appears in the generated bindings. Regular expressions are supported.
fn whitelisted_var<T: AsRef<str>>(self, arg: T) -> Builder
Whitelist the given variable so that it (and all types that it transitively refers to) appears in the generated bindings. Regular expressions are supported.
fn bitfield_enum<T: AsRef<str>>(self, arg: T) -> Builder
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.
fn constified_enum<T: AsRef<str>>(self, arg: T) -> Builder
Mark the given enum (or set of enums, if using a pattern) as a set of constants.
This makes bindgen generate constants instead of enums. Regular expressions are supported.
fn constified_enum_module<T: AsRef<str>>(self, arg: T) -> Builder
Mark the given enum (or set of enums, if using a pattern) as a set of constants that should be put into a module.
This makes bindgen generate a modules containing constants instead of enums. Regular expressions are supported.
fn raw_line<T: Into<String>>(self, arg: T) -> Builder
Add a string to prepend to the generated bindings. The string is passed through without any modification.
fn clang_arg<T: Into<String>>(self, arg: T) -> Builder
Add an argument to be passed straight through to clang.
fn clang_args<I>(self, iter: I) -> Builder where
I: IntoIterator,
I::Item: AsRef<str>,
I: IntoIterator,
I::Item: AsRef<str>,
Add arguments to be passed straight through to clang.
fn link<T: Into<String>>(self, library: T) -> Builder
Make the generated bindings link the given shared library.
fn link_static<T: Into<String>>(self, library: T) -> Builder
Make the generated bindings link the given static library.
fn link_framework<T: Into<String>>(self, library: T) -> Builder
Make the generated bindings link the given framework.
fn emit_builtins(self) -> Builder
Emit bindings for builtin definitions (for example __builtin_va_list
)
in the generated Rust.
fn no_convert_floats(self) -> Self
Avoid converting floats to f32
/f64
by default.
fn layout_tests(self, doit: bool) -> Self
Set whether layout tests should be generated.
fn derive_debug(self, doit: bool) -> Self
Set whether Debug
should be derived by default.
fn derive_default(self, doit: bool) -> Self
Set whether Default
should be derived by default.
fn emit_clang_ast(self) -> Builder
Emit Clang AST.
fn emit_ir(self) -> Builder
Emit IR.
fn enable_cxx_namespaces(self) -> Builder
Enable C++ namespaces.
fn disable_name_namespacing(self) -> Builder
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.
fn conservative_inline_namespaces(self) -> Builder
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.
fn generate_inline_functions(self, doit: bool) -> Self
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.
fn ignore_functions(self) -> Builder
Ignore functions.
fn ignore_methods(self) -> Builder
Ignore methods.
fn unstable_rust(self, doit: bool) -> Self
Avoid generating any unstable Rust, such as Rust unions, in the generated bindings.
fn use_core(self) -> Builder
Use core instead of libstd in the generated bindings.
fn ctypes_prefix<T: Into<String>>(self, prefix: T) -> Builder
Use the given prefix for the raw types instead of ::std::os::raw
.
fn parse_callbacks(self, cb: Box<ParseCallbacks>) -> Self
Allows configuring types in different situations, see the
ParseCallbacks
documentation.
fn with_codegen_config(self, config: CodegenConfig) -> Self
Choose what to generate using a
CodegenConfig
.
fn prepend_enum_name(self, doit: bool) -> Self
Prepend the enum name to constant or bitfield variants.
fn generate<'ctx>(self) -> Result<Bindings<'ctx>, ()>
Generate the Rust bindings using the options built up thus far.
fn dump_preprocessed_input(&self) -> Result<()>
Preprocess and dump the input header files to disk.
This is useful when debugging bindgen, using C-Reduce, or when filing
issues. The resulting file will be named something like __bindgen.i
or
__bindgen.ii