Skip to content

Commit 760c13f

Browse files
committed
Rewrite instrument-coverage documentation to use LLVM tools directly
llvm-tools-preview is still experimental, so document it as such, and don't use it in the examples.
1 parent 34106f8 commit 760c13f

File tree

1 file changed

+14
-24
lines changed

1 file changed

+14
-24
lines changed

src/doc/rustc/src/instrument-coverage.md

Lines changed: 14 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -119,29 +119,21 @@ If `LLVM_PROFILE_FILE` contains a path to a non-existent directory, the missing
119119

120120
LLVM's supplies two tools—`llvm-profdata` and `llvm-cov`—that process coverage data and generate reports. There are several ways to find and/or install these tools, but note that the coverage mapping data generated by the Rust compiler requires LLVM version 12 or higher. (`llvm-cov --version` typically shows the tool's LLVM version number.):
121121

122-
- The LLVM tools may be installed (or installable) directly to your OS (such as via `apt-get`, for Linux).
122+
- You can install the LLVM tools from your operating system distribution, or from your distribution of LLVM.
123123
- If you are building the Rust compiler from source, you can optionally use the bundled LLVM tools, built from source. Those tool binaries can typically be found in your build platform directory at something like: `rust/build/x86_64-unknown-linux-gnu/llvm/bin/llvm-*`.
124-
- You can install compatible versions of these tools via `rustup`.
124+
- You can install compatible versions of these tools via the `rustup` component `llvm-tools-preview`, though this is still considered experimental. In this case, you may also find `cargo-binutils` useful as a wrapper around these tools.
125125

126-
The `rustup` option is guaranteed to install a compatible version of the LLVM tools, but they can be hard to find. We recommend [`cargo-binutils`], which installs Rust-specific wrappers around these and other LLVM tools, so you can invoke them via `cargo` commands!
127-
128-
```shell
129-
$ rustup component add llvm-tools-preview
130-
$ cargo install cargo-binutils
131-
$ cargo profdata -- --help # note the additional "--" preceding the tool-specific arguments
132-
```
133-
134-
[`cargo-binutils`]: https://crates.io/crates/cargo-binutils
126+
The examples in this document show how to use the llvm tools directly.
135127

136128
## Creating coverage reports
137129

138-
Raw profiles have to be indexed before they can be used to generate coverage reports. This is done using [`llvm-profdata merge`] (or `cargo profdata -- merge`), which can combine multiple raw profiles and index them at the same time:
130+
Raw profiles have to be indexed before they can be used to generate coverage reports. This is done using [`llvm-profdata merge`], which can combine multiple raw profiles and index them at the same time:
139131

140132
```shell
141133
$ llvm-profdata merge -sparse formatjson5.profraw -o formatjson5.profdata
142134
```
143135

144-
Finally, the `.profdata` file is used, in combination with the coverage map (from the program binary) to generate coverage reports using [`llvm-cov report`] (or `cargo cov -- report`), for a coverage summaries; and [`llvm-cov show`] (or `cargo cov -- show`), to see detailed coverage of lines and regions (character ranges) overlaid on the original source code.
136+
Finally, the `.profdata` file is used, in combination with the coverage map (from the program binary) to generate coverage reports using [`llvm-cov report`], for a coverage summaries; and [`llvm-cov show`], to see detailed coverage of lines and regions (character ranges) overlaid on the original source code.
145137

146138
These commands have several display and filtering options. For example:
147139

@@ -218,19 +210,18 @@ test result: ok. 31 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out
218210
You should have one or more `.profraw` files now, one for each test binary. Run the `profdata` tool to merge them:
219211

220212
```shell
221-
$ cargo profdata -- merge \
222-
-sparse json5format-*.profraw -o json5format.profdata
213+
$ llvm-profdata merge -sparse json5format-*.profraw -o json5format.profdata
223214
```
224215

225216
Then run the `cov` tool, with the `profdata` file and all test binaries:
226217

227218
```shell
228-
$ cargo cov -- report \
219+
$ llvm-cov report \
229220
--use-color --ignore-filename-regex='/.cargo/registry' \
230221
--instr-profile=json5format.profdata \
231222
--object target/debug/deps/lib-30768f9c53506dc5 \
232223
--object target/debug/deps/json5format-fececd4653271682
233-
$ cargo cov -- show \
224+
$ llvm-cov show \
234225
--use-color --ignore-filename-regex='/.cargo/registry' \
235226
--instr-profile=json5format.profdata \
236227
--object target/debug/deps/lib-30768f9c53506dc5 \
@@ -246,7 +237,7 @@ $ cargo cov -- show \
246237
For `bash` users, one suggested way to automatically complete the `cov` command with the list of binaries is with a command like:
247238

248239
```bash
249-
$ cargo cov -- report \
240+
$ llvm-cov report \
250241
$( \
251242
for file in \
252243
$( \
@@ -275,22 +266,21 @@ The previous examples run `cargo test` with `--tests`, which excludes doc tests.
275266

276267
To include doc tests in the coverage results, drop the `--tests` flag, and apply the
277268
`-C instrument-coverage` flag, and some doc-test-specific options in the
278-
`RUSTDOCFLAGS` environment variable. (The `cargo profdata` command does not change.)
269+
`RUSTDOCFLAGS` environment variable. (The `llvm-profdata` command does not change.)
279270

280271
```bash
281272
$ RUSTFLAGS="-C instrument-coverage" \
282273
RUSTDOCFLAGS="-C instrument-coverage -Z unstable-options --persist-doctests target/debug/doctestbins" \
283274
LLVM_PROFILE_FILE="json5format-%m.profraw" \
284275
cargo test
285-
$ cargo profdata -- merge \
286-
-sparse json5format-*.profraw -o json5format.profdata
276+
$ llvm-profdata merge -sparse json5format-*.profraw -o json5format.profdata
287277
```
288278

289279
The `-Z unstable-options --persist-doctests` flag is required, to save the test binaries
290280
(with their coverage maps) for `llvm-cov`.
291281

292282
```bash
293-
$ cargo cov -- report \
283+
$ llvm-cov report \
294284
$( \
295285
for file in \
296286
$( \
@@ -308,8 +298,8 @@ $ cargo cov -- report \
308298
--instr-profile=json5format.profdata --summary-only # and/or other options
309299
```
310300

311-
> **Note**: The differences in this `cargo cov` command, compared with the version without
312-
> doc tests, include:
301+
> **Note**: The differences in this `llvm-cov` invocation, compared with the
302+
> version without doc tests, include:
313303
314304
- The `cargo test ... --no-run` command is updated with the same environment variables
315305
and flags used to _build_ the tests, _including_ the doc tests. (`LLVM_PROFILE_FILE`

0 commit comments

Comments
 (0)