Apply source-based-code-coverage only to my own code (rust+c)

I am currently trying to measure our code coverage using the
source-based-code-coverage in a project with rust and c source code.

If I add the sources argument to "cargo cov -- show", I only get the covered c files (no rust files shown at all). This might be a bug in llvm-cov (?).

edit: the above was not true, but the behaviour is very odd. e.g. I cannot just filter by the common parent directory. And if I just filter by the sub directory with the rust code, I also get dependencies and stuff outside of this directory.

I guess, I can adapt the to only instrument my own c code (That would solve the problem for the c dependencies).

Can I pass the -Zinstrument-coverage only to my own code somehow?
If I add it to the RUSTFLAGS or the [build]-section, it gets applied to all rust sources (including the dependencies, that I do not want to check).

Thanks for your help.

I could adapt my to add the flags for my own c-files based on some environment variable:

fn coverage_flags(&mut self) -> &mut Self {
        match std::env::var_os("COVERAGE") {
            Some(_) => self.flag("-fprofile-instr-generate")
            None => self,

Ok, I should also check the content of the env variable, but this is the idea for the solution. Now I only need to fix this for the rust-dependencies. I can use cargo rustc, but then I do not check the coverage of my own dependencies, b/c using cargo rustc I can only pass parameters to one package.

After adding --ignore-filename-regex='/.cargo/registry' the report looks good. I think, it would be a cleaner solution to not instrument the rust dependencies in the first place, but this works for me. I do not know yet, how big the profile will be after running our full test suite (or how much this impacts performance).

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.