taiki-e / cargo-llvm-cov

Cargo subcommand to easily use LLVM source-based code coverage (-C instrument-coverage).
Apache License 2.0
900 stars 57 forks source link

Branch coverage #8

Open taiki-e opened 3 years ago

taiki-e commented 3 years ago

UPDATE: 0.6.8 (https://github.com/taiki-e/cargo-llvm-cov/pull/356) added unstable --branch flag to enable branch coverage. (requires nightly-2024-03-16+.)

LLVM supports branch coverage (https://reviews.llvm.org/D84467), -Zinstrument-coverage does not support it yet.

See https://github.com/rust-lang/rust/issues/79649 for more.

taiki-e commented 3 years ago

I believe this is why we see - (0/0) in html report.

5

(- (0/0) does not look good and confusing, so I need to find a way to get rid of that display somehow.)

TomFryersMidsummer commented 1 year ago

The output can be made nicer with the following workaround.

cargo llvm-cov --html && sed -i "s_<td[^>]*>[^t]*</td></tr>_</tr>_g" target/llvm-cov/html/index.html
Zalathar commented 6 months ago

Branch coverage support has landed in nightly: https://github.com/rust-lang/rust/issues/79649#issuecomment-1999562694.

taiki-e commented 6 months ago

0.6.8 (https://github.com/taiki-e/cargo-llvm-cov/pull/356) added unstable --branch flag to enable branch coverage. (requires nightly-2024-03-16+.)

CobaltCause commented 6 months ago

Seems to also work on rustc 1.78.0-nightly (c67326b06 2024-03-15)?

taiki-e commented 6 months ago

Seems to also work on rustc 1.78.0-nightly (c67326b06 2024-03-15)?

It is nightly-2024-03-16. (The commit date ("c67326b06 2024-03-15" in this case) is one day before the rustup toolchain version: https://github.com/rust-lang/rust/issues/51533)

jayvdb commented 3 months ago

I have tried to utilise this by changing an existing workflow

-cargo llvm-cov --cobertura --output-path coverage.xml --workspace --no-fail-fast --all-features --exclude foo
+cargo +nightly llvm-cov test --cobertura --output-path coverage.xml --branch --workspace --no-fail-fast --all-features --exclude foo

The workflow fails with

error: linking with `cc` failed: exit status: 1
  |
  = note: LC_ALL="C"  PATH="/work/home/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/bin:/work/home/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/bin/self-contained:/work/home/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/bin:/work/home/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/bin/self-contained:/work/home/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/bin:/work/home/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/bin/self-contained:/work/home/.cargo/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" VSLANG="1033" "cc" "-m64" "/tmp/rustcRlY9PE/symbols.o" "/__w/rosalind/rosalind/target/llvm-cov-target/debug/deps/test_tile_request-56790ab4beac6feb.test_tile_request.e66584c38f015a9b-cgu.00.rcgu.o" 
  = note: rust-lld: error: unable to find library -lbar

The lib obviously exists because the workflow passes without this change, and it is in /usr/local/bin. I tried adding env: { LD_LIBRARY_PATH: /usr/local/lib } to the workflow step, to no avail.

taiki-e commented 3 months ago

@jayvdb

I have tried to utilise this by changing an existing workflow

There are two changes in that diff. It would be helpful to understand whether the use of the nightly compiler itself caused the problem or whether the both use of the nightly compiler and use of --branch flag caused the problem.

That said, I guess the cause of the recent nightly's linker problems is basically https://blog.rust-lang.org/2024/05/17/enabling-rust-lld-on-linux.html.

jayvdb commented 3 months ago

I removed --branch and still have a problem, so it isnt this tools probem. Thanks for the link. "-Zlinker-features=-lld" and -Clink-arg=-Wl,-z,nostart-stop-gc didn't do the trick. I'll keep digging.

"-Zlinker-features=-lld" fixed it. Thanks!