[][src]Struct cxx::Build

#[must_use]
pub struct Build { /* fields omitted */ }

The CXX code generator for constructing and compiling C++ code.

This is intended to be used from Cargo build scripts to execute CXX's C++ code generator, set up any additional compiler flags depending on the use case, and make the C++ compiler invocation.


Example

Example of a canonical Cargo build script that builds a CXX bridge:

// build.rs

fn main() {
    cxx::Build::new()
        .bridge("src/main.rs")
        .file("../demo-cxx/demo.cc")
        .flag("-std=c++11")
        .compile("cxxbridge-demo");

    println!("cargo:rerun-if-changed=src/main.rs");
    println!("cargo:rerun-if-changed=../demo-cxx/demo.h");
    println!("cargo:rerun-if-changed=../demo-cxx/demo.cc");
}

A runnable working setup with this build script is shown in the demo-rs and demo-cxx directories of https://github.com/dtolnay/cxx.


Alternatives

For use in non-Cargo builds like Bazel or Buck, CXX provides an alternate way of invoking the C++ code generator as a standalone command line tool. The tool is packaged as the cxxbridge-cmd crate.

$ cargo install cxxbridge-cmd  # or build it from the repo

$ cxxbridge src/main.rs --header > path/to/mybridge.h
$ cxxbridge src/main.rs > path/to/mybridge.cc

Methods

impl Build[src]

pub fn new() -> Self[src]

Begin with a cc::Build in its default configuration.

#[must_use] pub fn bridge(&self, rust_source_file: impl AsRef<Path>) -> Build[src]

This returns a cc::Build on which you should continue to set up any additional source files or compiler flags, and lastly call its compile method to execute the C++ build.

Auto Trait Implementations

impl RefUnwindSafe for Build

impl Send for Build

impl Sync for Build

impl Unpin for Build

impl UnwindSafe for Build

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.