Problems setting up code coverage tools

I'm trying to generate some code coverage reports following the guide here: Instrumentation-based Code Coverage - The rustc book

I ran
$ RUSTFLAGS="-C instrument-coverage" cargo test
and got a .profraw file.
I tried to install the required tools by installing
$ cargo install cargo-binutils
However when I try to run
$ llvm-profdata merge -sparse <whatever.profraw -o .profdata
Command 'llvm-profdata' not found, but can be installed with:

sudo apt install llvm

So cargo-binutils doesn't contain all the necessary component.

I'm running on an Ubuntu 20.04 machine and apt wants to install llvm10 but
$ rustc --verbose --version
rustc 1.65.0 (897e37553 2022-11-02
binary: rustc
commit-hash: 897e37553bba8b42751c67658967889d11ecd120
commit-date: 2022-11-02
host: x86_64-unknown-linux-gnu
release: 1.65.0
LLVM version: 15.0.0

so rustc is using v15.

Can I downgrade rustc to one that uses v10 of llvm or can I install v15 on my Ubuntu machine or is there some other rustup/cargo command that will install the necessary components?


You can use rustup to get the appropriate llvm tools, and I think that includes the appropriate llvm-profdata. However, these aren't added to PATH by default (to avoid clashing with the system), so you have to know where they're put to use them.

cargo-llvm-cov is a nice wrapper around the process that doesn't require knowing where rustup puts the llvm-tools.

1 Like

Well, that woks for modern(-ish) systems, Ubuntu 20.04 and Devuan chimera but I tried this on an old Centos7 system and the install went fine but I get an error when running. I can post the details but I doubt anyone is going to look into it. I'll mark as solved.

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.