Zngur
Zngur (/zængɑr/) is a C++/Rust interop tool. It tries to expose arbitrary Rust types, methods and functions, while preserving its semantics and ergonomics as much as possible. Using Zngur, you can use arbitrary Rust crates in your C++ code as easily as using it in normal Rust code, and you can write idiomatic Rusty APIs for your C++ library inside C++. See the documentation for more info.
Demo
// Rust values are available in the `::rust` namespace from their absolute path
// in Rust
using Vec = rust::std::vec::Vec<T>;
using Option = rust::std::option::Option<T>;
using BoxDyn = rust::Box<rust::Dyn<T>>;
// You can implement Rust traits for your classes
;
int
Output:
17
s[2] = 7
thread '<unnamed>' panicked at 'called `Option::unwrap()` on a `None` value', examples/simple/src/generated.rs:186:39
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
s[4] = Rust panic happened
hello 2 2
hello 5 7
hello 7 14
hello 3 17
34 17
vector iterator has been destructed
[main.cpp:71] t = [
10,
20,
60,
]
See the examples/simple if you want to build and run it.
Installation
The zngur CLI tool can be installed with cargo:
cargo install zngur-cli
Contributing
Because our examples require invoking a built zngur binary, we use xtask to orchestrate the build process and validate correctness across all examples.
-
Install mise: This project uses
misefor tool management. Install it from mise.jdx.dev or via your package manager. -
Install dependencies: Run
mise installto install the required tools. Seemise.tomlfor the list of installed tools. -
Run the CI locally: The official command to run our CI is:
CXX=clang++You can use any of the C++ compilers mentioned in our CI workflow:
clang++org++. Other compilers may work, but are not guaranteed to by our CI testing.
Formatting
You may run cargo xtask format-book to run mdformat on the /book directory.