Skip to content


Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?

Latest commit


Git stats


Failed to load latest commit information.
Latest commit message
Commit time
September 20, 2022 08:14
October 31, 2022 16:36

Codecov Rust Example

FOSSA Status

As of July 2, 2016, there is no option to make rustdoc generate a runnable test executable. That means that documentation tests will not show in your coverage data. If you discover a way to run the doctest executable with kcov, please open an Issue and we will add that to these instructions.


Travis Setup

Add to your .travis.yml file.

NOTE: You should change examplerust in for file in target/debug/examplerust-* ... (under after_success) to match your package name. For example, if your package name is minigrep, then the lines should be changed to for file in target/debug/minigrep-* .... If you are not sure what your package name is, it can also be found in Cargo.toml and it is usually the same name as when you had initialised the project.

language: rust

sudo: required

  - stable
  - beta
  - nightly

    - rust: nightly

      - libcurl4-openssl-dev
      - libelf-dev
      - libdw-dev
      - cmake
      - gcc
      - binutils-dev
      - libiberty-dev

after_success: |
  wget &&
  tar xzf master.tar.gz &&
  cd kcov-master &&
  mkdir build &&
  cd build &&
  cmake .. &&
  make &&
  make install DESTDIR=../../kcov-build &&
  cd ../.. &&
  rm -rf kcov-master &&
  for file in target/debug/examplerust-*; do [ -x "${file}" ] || continue; mkdir -p "target/cov/$(basename $file)"; ./kcov-build/usr/local/bin/kcov --exclude-pattern=/.cargo,/usr/lib --verify "target/cov/$(basename $file)" "$file"; done &&
  bash <(curl -s &&
  echo "Uploaded code coverage"

This will automatically run each executable and store the results in a different directory. Codecov will automatically find the cobertura.xml files that kcov generates and combine the results.

Other CI services

  • Adjust the materials in the above example as necessary for your CI.
  • Add CODECOV_TOKEN= to your CI's environment variables. (Don't store the raw token in your repo.)
  • Run bash <(curl -s after tests complete.

Produce Coverage Reports

Run your tests with kcov in order to create the necessary coverage reports. For example:

kcov --exclude-pattern=/.cargo,/usr/lib --verify target/cov target/debug/<PROJECT-NAME>-<hash>

<PROJECT-NAME> and <hash> are the appropriate project name and hash for your executable.

The hash at the end may change if cargo generates different test executables with the same name. If you are building your code differently or without cargo, change the last two arguments to kcov to respectively represent where you want the coverage to be stored and which executable to run.

Attempting to run kcov with an executable argument ending in a wildcard like <PROJECT-NAME>-* may result in incorrect coverage results as only a single test executable will run. For best results, run the kcov command for each test executable and store the results in separate directories. Codecov will automatically find and upload the cobertura.xml files and merge the coverage for you.

Note that setting the environment variable RUSTFLAGS="-C link-dead-code" during tests build may improve coverage accuracy by preventing dead-code elimination. Do not set this variable when creating release builds since it will increase binary size.

After you've run the tests and created a cobertura.xml report, you can use [the Codecov global uploader][4] to push that report to Codecov. See below for further details.

Installing kcov is largely dependent on your operating system. It is demonstrated to work on Linux systems but may not be fully compatible with Windows or OS X. Please lookup the appropriate installation instructions. The Travis CI example below demonstrates installing kcov on a Linux computer.


Private Repos

Add to your .travis.yml file.

  - bash <(curl -s -t uuid-repo-token

kcov Version

The version of kcov that is distributed with your package manager may not work with Rust binaries. You usually need to manually build the latest master branch and run kcov from there. All of this is taken care of for you in the .travis.yml file.

  1. More documentation at
  2. Configure codecov through the codecov.yml

We are happy to help if you have any questions. Please contact email our Support at


FOSSA Status


No description, website, or topics provided.



Security policy





No releases published


No packages published