From 8b61f4694f19cb37843f821618381b525a0ae9ae Mon Sep 17 00:00:00 2001 From: Joshua Ford Date: Thu, 6 Oct 2022 20:36:47 -0500 Subject: [PATCH] build: add "coverage" profile to cargo Cargo doesn't fully pay attention to the RUSTFLAGS variable. As such, to pass appropriate flags to rustc, Cargo uses a profile. We thus create a profile specifically for generating code coverage and updating the code coverage docs accordingly. See https://github.com/rust-lang/rust/issues/78011. Closes #3553. --- Cargo.toml | 13 +++++++++++++ implementations/rust/DEVELOP.md | 2 +- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 2f7f3618622..77637f907c1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -32,3 +32,16 @@ members = [ ] exclude = ["implementations/rust/ockam/ockam_examples/example_projects"] + +# Coverage profile for generating code coverage with grcov. +# +# See https://github.com/rust-lang/rust/issues/78011. +# +[profile.coverage] +panic = "abort" +opt-level = 0 +overflow-checks = false +incremental = false +codegen-units = 1 +inherits = "test" + diff --git a/implementations/rust/DEVELOP.md b/implementations/rust/DEVELOP.md index ae233ee3969..4087158e436 100644 --- a/implementations/rust/DEVELOP.md +++ b/implementations/rust/DEVELOP.md @@ -83,7 +83,7 @@ Get a code coverage report: ``` cargo +nightly install grcov -env CARGO_INCREMENTAL=0 RUSTFLAGS="-Zprofile -Ccodegen-units=1 -Copt-level=0 -Clink-dead-code -Coverflow-checks=off -Zpanic_abort_tests -Cpanic=abort --cfg tokio_unstable" RUSTDOCFLAGS="-Cpanic=abort" cargo +nightly test +env CARGO_INCREMENTAL=0 RUSTFLAGS="-Zprofile -Clink-dead-code --cfg tokio_unstable" cargo +nightly test --profile coverage grcov --llvm . -s . --binary-path ./target/debug/ -t html --branch --ignore-not-existing -o ./target/debug/coverage/