work. Note that you probably also need
RUST_COMPILER_RT_FOR_PROFILER=$src/llvm-project/compiler-rt in your environment.
Fixes #79401
TODO
[ ] Figure out how to add a regression test for this. Maybe enough to add a test to the cargo repo? I think cargo tests are run as part of Rust CI?
Demonstration
Before this fix you get these errors:
$ rm -rf target ; RUST_COMPILER_RT_FOR_PROFILER=/home/martin/src/llvm-project/compiler-rt RUSTFLAGS="-Cinstrument-coverage" cargo +nightly build --release -Zbuild-std=std,profiler_builtins
error: `profiler_builtins` crate (required by compiler options) is not compatible with crate attribute `#![no_core]`
error[E0152]: found duplicate lang item `manually_drop`
= note: first definition in `core` loaded from /home/martin/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcore-d453bab70303062c.rlib
= note: second definition in the local crate (`core`)
By not trying to inject a profiler runtime when only building an rlib. This logic already exists for the panic runtime.
This makes
work. Note that you probably also need
RUST_COMPILER_RT_FOR_PROFILER=$src/llvm-project/compiler-rt
in your environment.Fixes #79401
TODO
Demonstration
Before this fix you get these errors:
With the fix the build succeeds:
And we can check code coverage. My example program looks like this:
when the program prints to stdout:
we can see that
fs::write()
is not being used (note the0
's):but when we print to a file:
the code coverage shows
fs::write()
as being used (note the1
's):