2 years ago
#67738
Coder
Code coverage in Rust - "failed to run `rustc` to learn about target-specific information"
I am trying to get code coverage for my project in Rust. I am following the instructions provided here: https://marco-c.github.io/2020/11/24/rust-source-based-code-coverage.html
Based on that (and from https://doc.rust-lang.org/book/ch01-03-hello-cargo.html), I followed the steps:
cd projects // this could be really anything. Just meant to say I am in a clean directory.
cargo new hello_world --bin // creates a new module with hello world
export RUSTFLAGS="-Zinstrument-coverage"
cargo build
Results in following error:
error: failed to run `rustc` to learn about target-specific information
Caused by:
process didn't exit successfully: `rustc - --crate-name ___ --print=file-names -Zinstrument-coverage --crate-type bin --crate-type rlib --crate-type dylib --crate-type cdylib --crate-type staticlib --crate-type proc-macro --print=sysroot --print=cfg` (exit status: 1)
--- stderr
error: the option `Z` is only accepted on the nightly compiler
I followed the post: "Error loading target specification" when building a WebAssembly module with Cargo which has a similar error. But I did not run any rustc
command before. So I am not sure if the suggestion there is valid.
My end goal is to not debug this specific error but just try to find a workable way to get code coverage for the project from the command line. So, if I can debug this issue, that's great or if there is something else which I should follow, please point me to it.
Also, I use Intellij - on which I can get code coverage. But I would like to learn that using a command-line approach.
Thanks!
rust
code-coverage
0 Answers
Your Answer