Cross-language code coverage

Has anyone built code coverage infrastructure for a crate that also includes C++ code?

I'm using the new (as of 1.60) Rust-based code coverage instrumentation, which I'm generally liking very well. What I'd like to do is to also observe coverage for the C++ code that acts as an FFI for an underlying C++ library.

My attempt at that was here: Generate code coverage for ffi.cpp by scouten-adobe · Pull Request #64 · adobe/xmp-toolkit-rs · GitHub, but did not achieve the desired results. (No coverage info was generated for the ffi.cpp file.)

Any suggestions? Is this even possible?

It looks to me like you're using gcov instrumentation on the C++ side (notice that CI fails to link because of missing gcov related symbols). While it's probably possible to mix gcov instrumentation on the C++ side with source based code coverage on the Rust side, I suspect the easiest thing to do would be to also use source based code coverage via Clang on the C++ side.

That will require changing your C++ compiler to Clang, if it isn't already, and then passing -fprofile-instr-generate -fcoverage-mapping when compiling.

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.