Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rustc option "instrument-coverage" stabilized #790

Merged
merged 9 commits into from
Apr 13, 2022
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/CICD.yml
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,12 @@ jobs:
key: test-${{ runner.os }}-cargo-gcc-${{ matrix.gcc }}-clang-${{ matrix.clang }}-${{ hashFiles('**/Cargo.lock') }}
- name: Build
env:
RUSTFLAGS: -Zinstrument-coverage
RUSTFLAGS: -Cinstrument-coverage
run: cargo build
- name: Test
env:
LLVM_PROFILE_FILE: grcov-%p-%m.profraw
RUSTFLAGS: -Zinstrument-coverage
RUSTFLAGS: -Cinstrument-coverage
run: cargo test
- name: Generate coverage
run: |
Expand Down
11 changes: 5 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,7 @@ you can run `cargo install grcov`.

## Usage

**Nightly Rust is required** to use grcov for Rust coverage. Alternatively, you can `export
RUSTC_BOOTSTRAP=1`, which basically turns your stable rustc into a Nightly one.
Build your code with rust compiler flag `-C instrument-coverage`. and run with `LLWM_PROFILE_FILE` environment variable.
kazuk marked this conversation as resolved.
Show resolved Hide resolved

### Example: How to generate source-based coverage for a Rust project

Expand All @@ -173,7 +172,7 @@ RUSTC_BOOTSTRAP=1`, which basically turns your stable rustc into a Nightly one.
2. Ensure that the following environment variable is set up:

```sh
export RUSTFLAGS="-Zinstrument-coverage"
export RUSTFLAGS="-C instrument-coverage"
kazuk marked this conversation as resolved.
Show resolved Hide resolved
```

3. Build your code:
Expand Down Expand Up @@ -265,11 +264,11 @@ before_install:
matrix:
include:
- os: linux
rust: nightly
rust: stable

script:
- rustup component add llvm-tools-preview
- export RUSTFLAGS="-Zinstrument-coverage"
- export RUSTFLAGS="-Cinstrument-coverage"
- cargo build --verbose
- LLVM_PROFILE_FILE="your_name-%p-%m.profraw" cargo test --verbose
- ./grcov . --binary-path ./target/debug/ -s . -t lcov --branch --ignore-not-existing --ignore "/*" -o lcov.info
Expand All @@ -287,7 +286,7 @@ before_install:
matrix:
include:
- os: linux
rust: nightly
rust: stable

script:
- export CARGO_INCREMENTAL=0
Expand Down