Struct Builder

Source
pub struct Builder<'a, BuilderContext> { /* private fields */ }
Expand description

An object to allow building of bindings from a build.rs file.

It would be unusual to create this directly - see the autocxx_build or autocxx_gen crates.

Once you’ve got one of these objects, you may set some configuration options but then you’re likely to want to call the [build] method.

§Setting C++ version

Ensure you use [extra_clang_args] as well as giving an appropriate option to the cc::Build which you receive from the [build] function.

Implementations§

Source§

impl<CTX: BuilderContext> Builder<'_, CTX>

Source

pub fn new( rs_file: impl AsRef<Path>, autocxx_incs: impl IntoIterator<Item = impl AsRef<OsStr>>, ) -> Self

Create a new Builder object. You’ll need to pass in the Rust file which contains the bindings (typically an include_cpp! macro though autocxx can also handle manually-crafted cxx::bridge bindings), and a list of include directories which should be searched by autocxx as it tries to hunt for the include files specified within the include_cpp! macro.

Usually after this you’d call [build].

Source

pub fn extra_clang_args(self, extra_clang_args: &[&str]) -> Self

Specify extra arguments for clang. These are used when parsing C++ headers. For example, you might want to provide -std=c++17 to specify C++17.

Source

pub fn custom_gendir(self, custom_gendir: PathBuf) -> Self

Where to generate the code.

Source

pub fn cpp_codegen_options<F>(self, modifier: F) -> Self
where F: FnOnce(&mut CppCodegenOptions<'_>),

Update C++ code generation options. See CppCodegenOptions for details.

Source

pub fn auto_allowlist(self, do_it: bool) -> Self

Automatically discover uses of the C++ ffi mod and generate the allowlist from that. This is a highly experimental option, not currently recommended. It doesn’t work in the following cases:

  • Static function calls on types within the FFI mod.
  • Anything inside a macro invocation.
  • You’re using a different name for your ffi mod
  • You’re using multiple FFI mods
  • You’ve got usages scattered across files beyond that with the include_cpp invocation
  • You’re using use statements to rename mods or items. If this

proves to be a promising or helpful direction, autocxx would be happy to accept pull requests to remove some of these limitations.

Source

pub fn suppress_system_headers(self, do_it: bool) -> Self

Whether to suppress inclusion of system headers (memory, string etc.) from generated C++ bindings code. This should not normally be used, but can occasionally be useful if you’re reducing a test case and you have a preprocessed header file which already contains absolutely everything that the bindings could ever need.

Source

pub fn cxx_impl_annotations(self, cxx_impl_annotations: Option<String>) -> Self

An annotation optionally to include on each C++ function. For example to export the symbol from a library.

Source

pub fn build(self) -> Result<BuilderBuild, BuilderError>

Build autocxx C++ files and return a cc::Build you can use to build more from a build.rs file.

The error type returned by this function supports miette::Diagnostic, so if you use the miette crate and its fancy feature, then simply return a miette::Result from your main function, you should get nicely printed diagnostics.

As this is a cc::Build there are lots of options you can apply to the resulting options, but please bear in mind that these only apply to the build process for the generated code - such options will not influence autocxx’s process for parsing header files.

For example, if you wish to set the C++ version to C++17, you might be tempted to use cc::Build::flag_if_supported to add the -std=c++17 flag. However, this won’t affect the header parsing which autocxx does internally (by means of bindgen) so you additionally should call [extra_clang_args] with that same option.

Source

pub fn build_listing_files(self) -> Result<BuilderSuccess, BuilderError>

For use in tests only, this does the build and returns additional information about the files generated which can subsequently be examined for correctness. In production, please use simply [build].

Auto Trait Implementations§

§

impl<'a, BuilderContext> Freeze for Builder<'a, BuilderContext>

§

impl<'a, BuilderContext> !RefUnwindSafe for Builder<'a, BuilderContext>

§

impl<'a, BuilderContext> !Send for Builder<'a, BuilderContext>

§

impl<'a, BuilderContext> !Sync for Builder<'a, BuilderContext>

§

impl<'a, BuilderContext> Unpin for Builder<'a, BuilderContext>
where BuilderContext: Unpin,

§

impl<'a, BuilderContext> !UnwindSafe for Builder<'a, BuilderContext>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.