How to generate test library?

I am working on a Rust+Cpp hybrid project and using FFI extensively.

The Rust part is built to a static library and I am using the GCC toolchain to link the Rust static library and C/C++ static library.

The question is how to generate a standalone rust test library that contains the "tests" code to let me link it with the C/C++ static library.

cargo test does not work here due to the FFI part: it needs to link some C/C++ library to produce any runnable binary.

Any idea? Thanks in advance!

Rustc's test framework as used by cargo test can only produce executables. Maybe you could combine something like linkme's distributed slice with a proc macro as alternative for #[test]. Basically you did have a distributed slice with all tests, a proc macro attribute that would add a test to this slice and then write a test harness iterating over the list of tests which you can then call from C/C++.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.