pub struct IncludeCppEngine { /* private fields */ }
Expand description

Core of the autocxx engine.

The basic idea is this. We will run bindgen which will spit out a ton of Rust code corresponding to all the types and functions defined in C++. We’ll then post-process that bindgen output into a form suitable for ingestion by cxx. (It’s the BridgeConverter mod which does that.) Along the way, the bridge_converter might tell us of additional C++ code which we should generate, e.g. wrappers to move things into and out of UniquePtrs.

flowchart TB s[(C++ headers)] s --> lc rss[(.rs input)] rss --> parser parser --> include_cpp_conf cpp_output[(C++ output)] rs_output[(.rs output)] subgraph autocxx[autocxx_engine] parser[File parser] subgraph bindgen[autocxx_bindgen] lc[libclang parse] bir(bindgen IR) lc --> bir end bgo(bindgen generated bindings) bir --> bgo include_cpp_conf(Config from include_cpp) syn[Parse with syn] bgo --> syn conv[['conversion' mod: see below]] syn --> conv rsgen(Generated .rs TokenStream) conv --> rsgen subgraph cxx_gen cxx_codegen[cxx_gen C++ codegen] end rsgen --> cxx_codegen end conv -- autocxx C++ codegen --> cpp_output rsgen -- autocxx .rs codegen --> rs_output cxx_codegen -- cxx C++ codegen --> cpp_output subgraph rustc [rustc build] subgraph autocxx_macro include_cpp[autocxx include_cpp macro] end subgraph cxx cxxm[cxx procedural macro] end comprs(Fully expanded Rust code) end rs_output-. included .->include_cpp include_cpp --> cxxm cxxm --> comprs rss --> rustc include_cpp_conf -. used to configure .-> bindgen include_cpp_conf --> conv link[linker] cpp_output --> link comprs --> link

Here’s a zoomed-in view of the “conversion” part:

flowchart TB syn[(syn parse)] apis(Unanalyzed APIs) subgraph parse syn ==> parse_bindgen end parse_bindgen ==> apis subgraph analysis typedef[typedef analysis] pod[POD analysis] apis ==> typedef typedef ==> pod podapis(APIs with POD analysis) pod ==> podapis fun[Function materialization analysis] podapis ==> fun funapis(APIs with function analysis) fun ==> funapis gc[Garbage collection] funapis ==> gc ctypes[C int analysis] gc ==> ctypes ctypes ==> finalapis end finalapis(Analyzed APIs) codegenrs(.rs codegen) codegencpp(.cpp codegen) finalapis ==> codegenrs finalapis ==> codegencpp

Implementations§

source§

impl IncludeCppEngine

source

pub fn new_from_syn(mac: Macro, file_contents: Rc<String>) -> Result<Self>

source

pub fn new_for_autodiscover() -> Self

Used if we find that we’re asked to auto-discover extern_rust_type and similar but didn’t have any include_cpp macro at all.

source

pub fn config_mut(&mut self) -> &mut IncludeCppConfig

source

pub fn get_rs_filename(&self) -> String

source

pub fn get_rs_output(&self) -> RsOutput<'_>

Generate the Rust bindings. Call generate first.

source

pub fn get_mod_name(&self) -> String

Returns the name of the mod which this include_cpp! will generate. Can and should be used to ensure multiple mods in a file don’t conflict.

source

pub fn generate( &mut self, inc_dirs: Vec<PathBuf>, extra_clang_args: &[&str], dep_recorder: Option<Box<dyn RebuildDependencyRecorder>>, codegen_options: &CodegenOptions<'_> ) -> Result<()>

Actually examine the headers to find out what needs generating. Most errors occur at this stage as we fail to interpret the C++ headers properly.

See documentation for this type for flow diagrams and more details.

Trait Implementations§

Auto Trait Implementations§

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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 Twhere 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, U> TryFrom<U> for Twhere U: Into<T>,

§

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 Twhere U: TryFrom<T>,

§

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.