Skip to content

Commit

Permalink
Make cargo -Zbuild-std work with -Cinstrument-coverage
Browse files Browse the repository at this point in the history
By not trying to inject a profiler runtime when only building an rlib.
This logic already exists for the panic runtime.

This makes

    RUSTFLAGS="-Cinstrument-coverage" cargo build -Zbuild-std=std,profiler_builtins

work. Note that you probably also need
`RUST_COMPILER_RT_FOR_PROFILER=$src/llvm-project/compiler-rt` in your
environment.
  • Loading branch information
Enselic committed Nov 21, 2024
1 parent a00df61 commit f9cc5ae
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions compiler/rustc_metadata/src/creader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -698,11 +698,14 @@ impl<'a, 'tcx> CrateLoader<'a, 'tcx> {
Ok(unsafe { *load_symbol_from_dylib::<*const &[ProcMacro]>(path, &sym_name)? })
}

fn only_generating_rlib(&mut self) -> bool {
!self.tcx.crate_types().iter().any(|ct| *ct != CrateType::Rlib)
}

fn inject_panic_runtime(&mut self, krate: &ast::Crate) {
// If we're only compiling an rlib, then there's no need to select a
// panic runtime, so we just skip this section entirely.
let any_non_rlib = self.tcx.crate_types().iter().any(|ct| *ct != CrateType::Rlib);
if !any_non_rlib {
if self.only_generating_rlib() {
info!("panic runtime injection skipped, only generating rlib");
return;
}
Expand Down Expand Up @@ -777,6 +780,13 @@ impl<'a, 'tcx> CrateLoader<'a, 'tcx> {
}

fn inject_profiler_runtime(&mut self, krate: &ast::Crate) {
// If we're only compiling an rlib, then there's no need to select a
// profiler runtime, so we just skip this section entirely.
if self.only_generating_rlib() {
info!("profiler runtime injection skipped, only generating rlib");
return;
}

if self.sess.opts.unstable_opts.no_profiler_runtime
|| !(self.sess.instrument_coverage() || self.sess.opts.cg.profile_generate.enabled())
{
Expand Down

0 comments on commit f9cc5ae

Please sign in to comment.