This repo is about how you can call Rust code in C++. CXX generates the needed C++ gluecode for you in a safe way. For more information, have a look at their website.
The rust part itself consists of two crates in a workspace. One crate, the rust_lib
is an ordinary library in rust.
It does not know anything about its dependees.
The cxx_api
crate takes the rust_lib
as dependency and build the C++ glue code as a static library.
The C++ executable main.cpp
consumes the static library
cxx_api
with its C++ glue code.
graph TD
A[main.cpp] --> B[cxx_api] --> C[rust_lib]
The build consists of two steps.
- Building the rust crates:
cargo build (--release)
- Build the C++ executable with cmake
cmake -B <build-dir> . -DCMAKE_BUILD_TYPE=Debug (or Release) cmake --build <build-dir>
cd <build-dir>
./main