<!-- mobian-agent-page publisher="dailydev" canonical="https://daily.dev/posts/rust-integrating-llvm-source-base-code-coverage-with-gitlab-jxbiiuwpw" -->

---
title: Rust: integrating LLVM source-base code coverage with GitLab
description: A step-by-step guide to setting up LLVM source-based code coverage for Rust projects integrated with GitLab CI. The tutorial covers configuring the Rust...
canonical: https://daily.dev/posts/rust-integrating-llvm-source-base-code-coverage-with-gitlab-jxbiiuwpw
twitter:card: summary_large_image
twitter:site: @dailydotdev
og:type: website
og:site_name: daily.dev
og:title: Rust: integrating LLVM source-base code coverage with GitLab | daily.dev
og:description: A step-by-step guide to setting up LLVM source-based code coverage for Rust projects integrated with GitLab CI. The tutorial covers configuring the Rust...
og:url: https://daily.dev/posts/rust-integrating-llvm-source-base-code-coverage-with-gitlab-jxbiiuwpw
og:image: https://api.daily.dev/og/posts/jxbIiUwpW.png
og:image:alt: Rust: integrating LLVM source-base code coverage with GitLab
og:image:width: 1200
og:image:height: 630
og:locale: en
---

> ## Documentation Index
> Fetch the complete documentation index at: https://daily.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Rust: integrating LLVM source-base code coverage with GitLab

**[Collabora Blog](https://daily.dev/sources/collabora)** · 6 min read · 0 upvotes · 0 comments

## Summary

A step-by-step guide to setting up LLVM source-based code coverage for Rust projects integrated with GitLab CI. The tutorial covers configuring the Rust nightly compiler with the `-Zinstrument-coverage` flag, using grcov to generate HTML and lcov reports, converting lcov to Cobertura format for GitLab's Test Coverage Visualization, and parsing coverage totals via regex in GitLab's CI/CD settings. Workarounds for current grcov limitations (no native Cobertura support) are included, along with a complete final CI job definition and links to real-world examples in the zbus and gstreamer-rs projects.

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <https://www.collabora.com/news-and-blog/blog/2021/03/24/rust-integrating-llvm-source-base-code-coverage-with-gitlab>

## Questions this post answers

### How do I set up LLVM source-based code coverage for a Rust project in GitLab CI?

Set `RUSTFLAGS="-Zinstrument-coverage"` and `LLVM_PROFILE_FILE="coverage-%p-%m.profraw"` in your CI job, add the `llvm-tools-preview` component via `rustup`, run `cargo test`, then use grcov to generate HTML and lcov reports. Convert the lcov report to Cobertura format using `lcov_cobertura` and pass it as a `reports: cobertura` artifact so GitLab's Test Coverage Visualization can display per-line coverage in merge requests.

_Rust developers wiring up coverage pipelines share configs and gotchas on daily.dev._

### Why does grcov need the --ignore "*cargo*" flag when generating Rust coverage reports?

Without `--ignore "*cargo*"`, grcov includes coverage data from all Cargo registry dependencies alongside your own crate's code, inflating or distorting the reported coverage. Passing `--ignore "*cargo*"` excludes the Cargo registry path so only your crate's source lines are counted. The recommended approach is to first generate a report without any ignore flags, then iteratively add ignore patterns to exclude non-crate code.

_Teams tuning Rust test coverage metrics find practical patterns like this on daily.dev._

### How do I get GitLab to display the coverage percentage from an lcov report in CI pipelines?

Install the `lcov` tool in your CI job and run `lcov --summary coverage.lcov` to print a summary to the job log. Then in GitLab's CI/CD settings under Test Coverage Parsing, set the regex `\s*lines\.*:\s*([\d\.]+%)` so GitLab can extract the covered-lines percentage from the log output and display it on pipelines and merge requests.

_Developers integrating coverage reporting into GitLab pipelines track tooling updates on daily.dev._

## Similar posts on daily.dev

- [Rust For Linux 7.3 Begins Seeing Fixes To Prepare For Rust's GCC Backend](https://daily.dev/posts/rust-for-linux-7-3-begins-seeing-fixes-to-prepare-for-rust-s-gcc-backend-7bzhbculc) · Phoronix · 0 upvotes · 0 comments
- [A Vision for Cargo](https://daily.dev/posts/a-vision-for-cargo-9f2kssnoj) · Lobsters · 1 upvotes · 0 comments
- [Nice CLI Crash Reports in Rust](https://daily.dev/posts/nice-cli-crash-reports-in-rust-refjbwkvz) · Pascal’s scribbles · 1 upvotes · 0 comments

---

Tags: [#general-programming](https://daily.dev/tags/general-programming), [#rust](https://daily.dev/tags/rust), [#gitlab-ci](https://daily.dev/tags/gitlab-ci)

[View this post on daily.dev](https://daily.dev/posts/rust-integrating-llvm-source-base-code-coverage-with-gitlab-jxbiiuwpw)

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://daily.dev/#organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180},"sameAs":["https://twitter.com/dailydotdev","https://github.com/dailydotdev","https://www.linkedin.com/company/daily-dev-ltd"]},{"@type":"WebSite","@id":"https://daily.dev/#website","url":"https://daily.dev","name":"daily.dev","publisher":{"@id":"https://daily.dev/#organization"},"potentialAction":{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https://daily.dev/search?q={search_term_string}"},"query-input":"required name=search_term_string"}}]}
{"@context":"https://schema.org","@type":"TechArticle","headline":"Rust: integrating LLVM source-base code coverage with GitLab","url":"https://daily.dev/posts/rust-integrating-llvm-source-base-code-coverage-with-gitlab-jxbiiuwpw","mainEntityOfPage":{"@type":"WebPage","@id":"https://daily.dev/posts/rust-integrating-llvm-source-base-code-coverage-with-gitlab-jxbiiuwpw"},"datePublished":"2026-08-11T08:53:34.085Z","dateModified":"2026-08-11T09:16:58.427Z","description":"A step-by-step guide to setting up LLVM source-based code coverage for Rust projects integrated with GitLab CI. The tutorial covers configuring the Rust...","image":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/7cc8a346799dbfea4aca8141012f5c05?_a=AQAEuop","thumbnailUrl":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/7cc8a346799dbfea4aca8141012f5c05?_a=AQAEuop","isAccessibleForFree":true,"articleSection":"Collabora Blog","inLanguage":"en","publisher":{"@type":"Organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180}},"author":{"@type":"Organization","name":"Collabora Blog","logo":"https://media.daily.dev/image/upload/s--ZGZ0FjqS--/f_auto,q_auto/v1786438306/logos/collabora?_a=BAMAMicg0","url":"https://daily.dev/sources/collabora"},"commentCount":0,"discussionUrl":"https://daily.dev/posts/rust-integrating-llvm-source-base-code-coverage-with-gitlab-jxbiiuwpw","interactionStatistic":[{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":0},{"@type":"InteractionCounter","interactionType":{"@type":"CommentAction"},"userInteractionCount":0}],"keywords":"general-programming,rust,gitlab-ci","timeRequired":"PT6M"}
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://daily.dev"},{"@type":"ListItem","position":2,"name":"Collabora Blog","item":"https://daily.dev/sources/collabora"},{"@type":"ListItem","position":3,"name":"Rust: integrating LLVM source-base code coverage with GitLab"}]}
{"@context":"https://schema.org","@type":"FAQPage","@id":"https://daily.dev/posts/rust-integrating-llvm-source-base-code-coverage-with-gitlab-jxbiiuwpw#faq","mainEntity":[{"@type":"Question","name":"How do I set up LLVM source-based code coverage for a Rust project in GitLab CI?","acceptedAnswer":{"@type":"Answer","text":"Set `RUSTFLAGS=\"-Zinstrument-coverage\"` and `LLVM_PROFILE_FILE=\"coverage-%p-%m.profraw\"` in your CI job, add the `llvm-tools-preview` component via `rustup`, run `cargo test`, then use grcov to generate HTML and lcov reports. Convert the lcov report to Cobertura format using `lcov_cobertura` and pass it as a `reports: cobertura` artifact so GitLab's Test Coverage Visualization can display per-line coverage in merge requests. Rust developers wiring up coverage pipelines share configs and gotchas on daily.dev."}},{"@type":"Question","name":"Why does grcov need the --ignore \"*cargo*\" flag when generating Rust coverage reports?","acceptedAnswer":{"@type":"Answer","text":"Without `--ignore \"*cargo*\"`, grcov includes coverage data from all Cargo registry dependencies alongside your own crate's code, inflating or distorting the reported coverage. Passing `--ignore \"*cargo*\"` excludes the Cargo registry path so only your crate's source lines are counted. The recommended approach is to first generate a report without any ignore flags, then iteratively add ignore patterns to exclude non-crate code. Teams tuning Rust test coverage metrics find practical patterns like this on daily.dev."}},{"@type":"Question","name":"How do I get GitLab to display the coverage percentage from an lcov report in CI pipelines?","acceptedAnswer":{"@type":"Answer","text":"Install the `lcov` tool in your CI job and run `lcov --summary coverage.lcov` to print a summary to the job log. Then in GitLab's CI/CD settings under Test Coverage Parsing, set the regex `\\s*lines\\.*:\\s*([\\d\\.]+%)` so GitLab can extract the covered-lines percentage from the log output and display it on pipelines and merge requests. Developers integrating coverage reporting into GitLab pipelines track tooling updates on daily.dev."}}]}
```

