Make cargo -Zbuild-std
work with -Cinstrument-coverage
#133300
+12
−2
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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:
$ LLVM_PROFILE_FILE=file.profraw ./target/release/hello-world write-file
the code coverage shows
fs::write()
as being used (note the1
's):