Skip to content

Commit f9cc5ae

Browse files
committed
Make cargo -Zbuild-std work with -Cinstrument-coverage
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.
1 parent a00df61 commit f9cc5ae

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

compiler/rustc_metadata/src/creader.rs

+12-2
Original file line numberDiff line numberDiff line change
@@ -698,11 +698,14 @@ impl<'a, 'tcx> CrateLoader<'a, 'tcx> {
698698
Ok(unsafe { *load_symbol_from_dylib::<*const &[ProcMacro]>(path, &sym_name)? })
699699
}
700700

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

779782
fn inject_profiler_runtime(&mut self, krate: &ast::Crate) {
783+
// If we're only compiling an rlib, then there's no need to select a
784+
// profiler runtime, so we just skip this section entirely.
785+
if self.only_generating_rlib() {
786+
info!("profiler runtime injection skipped, only generating rlib");
787+
return;
788+
}
789+
780790
if self.sess.opts.unstable_opts.no_profiler_runtime
781791
|| !(self.sess.instrument_coverage() || self.sess.opts.cg.profile_generate.enabled())
782792
{

0 commit comments

Comments
 (0)