Make a Rust-Library available in C++.
- The Rust library integrates seamlessly into a C++ project
- Minimal leakage of Rust types to C++
- The Rust library exposes C++ ergonomics for interaction with the library
- The Rust library is easy to integrate into CMake build
personis a pure Rust library- No FFI-Code
- easy to re-use in pure Rust context
person-cpptakes care of the bindings between C++ and Rust- A C++ header file is exposed with the declaration of a wrapper class
- Configure
cmake -S . -B build - Configure for release
cmake -S . -B build -DCMAKE_BUILD_TYPE=Release - Build
cmake --build build- Run Unit Tests
cmake --build build --target person-test-rs
- Run Unit Tests
Cross compilation can be a tricky endeavour. Follwow this guide to cross compile this project for a Raspberry Pi 3 running Debian "Bullseye"
Gather information of the target system. Run this on your target platform.
cat /etc/os-releaseto get OS informationuname -srmto get Kernel and CPU architecture informationldd --versionto find the version of GLIBC
A sensible way to get a cross build toolchain is using crosstool-NG. It offers a lot of configuration options to match your target system well.
Install crosstool-NG following the instructions
Configuring the Toolchain (based on a sample)
ct-ng list-samplesand pick your sample (hereaarch64-unknown-linux-gnu)ct-ng aarch64-unknown-linux-gnuto build base configurationct-ng menuconfigto adapt compiler, GLIBC version, etc. This is important, the base config gives the latest compiler, libraries, etc.ct-ng buildto build the toolchain. It is likely placed in${HOME}/x-tools/aarch64-rpi3-linux-gnu/- add the toolchain to your path
PATH=$PATH:~/x-tools/aarch64-rpi4-linux-gnu/bin(to.bashrcto make it persistent)
- add the toolchain to your path
Install the right rust cross compiler with rustup target add aarch64-unknown-linux-gnu
- Pass the toolchain file for manual configuration:
cmake -S . -B build_target -DCMAKE_TOOLCHAIN_FILE=aarch64-unknown-linux-gnu.cmake - Build
cmake --build build_target
-
Copy the binary to a running Raspberry Pi using scp:
scp <binary> pi@<IP>:/home/pi -
SSH into target and run the binary
-
sudo apt-get install gcc-arm-linux-gnueabihf g++-arm-linux-gnueabihf crossbuild-essential-armhf -
rustup target add armv7-unknown-linux-gnueabihf
