Git Product home page Git Product logo

rustcxx's Introduction

rustcxx: Using C++ from Rust made easy

rustcxx is a tool allowing C++ to be used from a Rust project easily. It works by allowing snippets of C++ to be included within a Rust function, and vice-versa.

Example

#![plugin(rustcxx_plugin)]

cxx_inline! {
    #include <stdint.h>
    uint32_t square_it(uint32_t x) {
        return rust![(x: u32) -> u32 {
            println!("Rust: Squaring {}", x);
            x * x
        }];
    }
}

let x: u32 = 5;
let square = unsafe { cxx![(x: u32) -> u32 {
    std::cout << "C++: Squaring " << x << std::endl;
    square_it(x)
}] };

See the provided example for more details.

Usage

rustcxx requires a nightly version of the Rust compiler.

Add to your Cargo.toml:

[package]
build = "build.rs"

[dependencies.rustcxx_plugin]
git = "https://github.com/google/rustcxx"
branch = "unstable"

[build-dependencies.rustcxx_codegen]
git = "https://github.com/google/rustcxx"
branch = "unstable"

and create a build.rs file containing the following:

extern crate rustcxx_codegen;

fn main() {
    rustcxx_codegen::build("src/main.rs");
}

Authors

The main author is Paul Liétar.

Contributions

We gladly accept contributions via GitHub pull requests, as long as the author has signed the Google Contributor License. Please see CONTRIBUTING.md for more details.

Disclaimer

This is not an official Google product (experimental or otherwise), it is just code that happens to be owned by Google.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.