diff --git a/compiler/rustc_codegen_ssa/src/back/link.rs b/compiler/rustc_codegen_ssa/src/back/link.rs index 511430ffade5a..a95b02559c7d1 100644 --- a/compiler/rustc_codegen_ssa/src/back/link.rs +++ b/compiler/rustc_codegen_ssa/src/back/link.rs @@ -1163,7 +1163,7 @@ fn add_profiler_libraries(sess: &Session, crate_type: CrateType, linker: &mut dy || sess.opts.unstable_opts.profile || sess.opts.cg.profile_generate.enabled()) // If user doesn't provide custom profiler runtime, link default llvm profiler. - && sess.opts.unstable_opts.profiler_runtime == "profiler_builtins" + && sess.opts.unstable_opts.profiler_runtime.is_none() { link_profiler_runtime(sess, linker); } diff --git a/compiler/rustc_interface/src/tests.rs b/compiler/rustc_interface/src/tests.rs index eb8e65a6d59d3..7a442d031dacd 100644 --- a/compiler/rustc_interface/src/tests.rs +++ b/compiler/rustc_interface/src/tests.rs @@ -770,7 +770,7 @@ fn test_unstable_options_tracking_hash() { tracked!(profile, true); tracked!(profile_emit, Some(PathBuf::from("abc"))); tracked!(profile_sample_use, Some(PathBuf::from("abc"))); - tracked!(profiler_runtime, "abc".to_string()); + tracked!(profiler_runtime, Some("abc".to_string())); tracked!(relax_elf_relocations, Some(true)); tracked!(relro_level, Some(RelroLevel::Full)); tracked!(remap_cwd_prefix, Some(PathBuf::from("abc"))); diff --git a/compiler/rustc_metadata/src/creader.rs b/compiler/rustc_metadata/src/creader.rs index 4a20cdf083618..dc34911a7bf41 100644 --- a/compiler/rustc_metadata/src/creader.rs +++ b/compiler/rustc_metadata/src/creader.rs @@ -764,21 +764,23 @@ impl<'a> CrateLoader<'a> { || !(self.sess.instrument_coverage() || self.sess.opts.unstable_opts.profile || self.sess.opts.cg.profile_generate.enabled()) - || self.sess.opts.unstable_opts.profiler_runtime == "profiler_builtins" { return; } - info!("loading profiler"); + // If user doesn't provide custom profiler runtime, skip injection. + if let Some(profiler_runtime) = &self.sess.opts.unstable_opts.profiler_runtime { + info!("loading profiler: {}", profiler_runtime); - let name = Symbol::intern(&self.sess.opts.unstable_opts.profiler_runtime); + let name = Symbol::intern(profiler_runtime); - let Some(cnum) = self.resolve_crate(name, DUMMY_SP, CrateDepKind::Implicit) else { return; }; - let data = self.cstore.get_crate_data(cnum); + let Some(cnum) = self.resolve_crate(name, DUMMY_SP, CrateDepKind::Implicit) else { return; }; + let data = self.cstore.get_crate_data(cnum); - // Sanity check the loaded crate to ensure it is indeed a profiler runtime - if !data.is_profiler_runtime() { - self.sess.emit_err(NotProfilerRuntime { crate_name: name }); + // Sanity check the loaded crate to ensure it is indeed a profiler runtime + if !data.is_profiler_runtime() { + self.sess.emit_err(NotProfilerRuntime { crate_name: name }); + } } } diff --git a/compiler/rustc_metadata/src/errors.rs b/compiler/rustc_metadata/src/errors.rs index 7c387b9a9ecde..633f4acb17add 100644 --- a/compiler/rustc_metadata/src/errors.rs +++ b/compiler/rustc_metadata/src/errors.rs @@ -601,7 +601,7 @@ pub struct CannotFindCrate { pub missing_core: bool, pub current_crate: String, pub is_nightly_build: bool, - pub profiler_runtime: Symbol, + pub profiler_runtime: Option, pub locator_triple: TargetTriple, } @@ -641,7 +641,7 @@ impl IntoDiagnostic<'_> for CannotFindCrate { if self.is_nightly_build { diag.help(rustc_errors::fluent::metadata_consider_building_std); } - } else if self.crate_name == self.profiler_runtime { + } else if Some(self.crate_name) == self.profiler_runtime { diag.note(rustc_errors::fluent::metadata_compiler_missing_profiler); } else if self.crate_name.as_str().starts_with("rustc_") { diag.help(rustc_errors::fluent::metadata_install_missing_components); diff --git a/compiler/rustc_metadata/src/locator.rs b/compiler/rustc_metadata/src/locator.rs index 35f9ef92a1c42..befd39f72c105 100644 --- a/compiler/rustc_metadata/src/locator.rs +++ b/compiler/rustc_metadata/src/locator.rs @@ -1124,7 +1124,12 @@ impl CrateError { .clone() .unwrap_or("".to_string()), is_nightly_build: sess.is_nightly_build(), - profiler_runtime: Symbol::intern(&sess.opts.unstable_opts.profiler_runtime), + profiler_runtime: sess + .opts + .unstable_opts + .profiler_runtime + .as_ref() + .map(|x| Symbol::intern(x)), locator_triple: locator.triple, }); } diff --git a/compiler/rustc_session/src/options.rs b/compiler/rustc_session/src/options.rs index 713480d4f8e8c..357b7d5eaa3be 100644 --- a/compiler/rustc_session/src/options.rs +++ b/compiler/rustc_session/src/options.rs @@ -1483,8 +1483,8 @@ options! { (default based on relative source path)"), profile_sample_use: Option = (None, parse_opt_pathbuf, [TRACKED], "use the given `.prof` file for sampled profile-guided optimization (also known as AutoFDO)"), - profiler_runtime: String = (String::from("profiler_builtins"), parse_string, [TRACKED], - "name of the profiler runtime crate to automatically inject (default: `profiler_builtins`)"), + profiler_runtime: Option = (None, parse_opt_string, [TRACKED], + "name of the profiler runtime crate to automatically inject"), query_dep_graph: bool = (false, parse_bool, [UNTRACKED], "enable queries of the dependency graph for regression testing (default: no)"), randomize_layout: bool = (false, parse_bool, [TRACKED],