Skip to content

Commit f9df1ad

Browse files
committed
Check for profiler support via a flag, instead of an environment var
1 parent f688dd6 commit f9df1ad

File tree

5 files changed

+27
-2
lines changed

5 files changed

+27
-2
lines changed

src/bootstrap/src/core/build_steps/test.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1976,7 +1976,7 @@ NOTE: if you're sure you want to do this, please open an issue as to why. In the
19761976
}
19771977

19781978
if builder.config.profiler_enabled(target) {
1979-
cmd.env("RUSTC_PROFILER_SUPPORT", "1");
1979+
cmd.arg("--profiler-support");
19801980
}
19811981

19821982
cmd.env("RUST_TEST_TMPDIR", builder.tempdir());

src/tools/compiletest/src/common.rs

+4
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,10 @@ pub struct Config {
387387
// Needed both to construct build_helper::git::GitConfig
388388
pub git_repository: String,
389389
pub nightly_branch: String,
390+
391+
/// True if the profiler runtime is enabled for this target.
392+
/// Used by the "needs-profiler-support" header in test files.
393+
pub profiler_support: bool,
390394
}
391395

392396
impl Config {

src/tools/compiletest/src/header/needs.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ impl CachedNeedsConditions {
238238
sanitizer_memtag: sanitizers.contains(&Sanitizer::Memtag),
239239
sanitizer_shadow_call_stack: sanitizers.contains(&Sanitizer::ShadowCallStack),
240240
sanitizer_safestack: sanitizers.contains(&Sanitizer::Safestack),
241-
profiler_support: std::env::var_os("RUSTC_PROFILER_SUPPORT").is_some(),
241+
profiler_support: config.profiler_support,
242242
xray: config.target_cfg().xray,
243243

244244
// For tests using the `needs-rust-lld` directive (e.g. for `-Clink-self-contained=+linker`),

src/tools/compiletest/src/header/tests.rs

+18
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ struct ConfigBuilder {
6262
llvm_version: Option<String>,
6363
git_hash: bool,
6464
system_llvm: bool,
65+
profiler_support: bool,
6566
}
6667

6768
impl ConfigBuilder {
@@ -100,6 +101,11 @@ impl ConfigBuilder {
100101
self
101102
}
102103

104+
fn profiler_support(&mut self, s: bool) -> &mut Self {
105+
self.profiler_support = s;
106+
self
107+
}
108+
103109
fn build(&mut self) -> Config {
104110
let args = &[
105111
"compiletest",
@@ -142,6 +148,9 @@ impl ConfigBuilder {
142148
if self.system_llvm {
143149
args.push("--system-llvm".to_owned());
144150
}
151+
if self.profiler_support {
152+
args.push("--profiler-support".to_owned());
153+
}
145154

146155
args.push("--rustc-path".to_string());
147156
// This is a subtle/fragile thing. On rust-lang CI, there is no global
@@ -340,6 +349,15 @@ fn sanitizers() {
340349
assert!(check_ignore(&config, "// needs-sanitizer-thread"));
341350
}
342351

352+
#[test]
353+
fn profiler_support() {
354+
let config: Config = cfg().profiler_support(false).build();
355+
assert!(check_ignore(&config, "// needs-profiler-support"));
356+
357+
let config: Config = cfg().profiler_support(true).build();
358+
assert!(!check_ignore(&config, "// needs-profiler-support"));
359+
}
360+
343361
#[test]
344362
fn asm_support() {
345363
let asms = [

src/tools/compiletest/src/lib.rs

+3
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ pub fn parse_config(args: Vec<String>) -> Config {
142142
.optflag("", "force-rerun", "rerun tests even if the inputs are unchanged")
143143
.optflag("", "only-modified", "only run tests that result been modified")
144144
.optflag("", "nocapture", "")
145+
.optflag("", "profiler-support", "is the profiler runtime enabled for this target")
145146
.optflag("h", "help", "show this message")
146147
.reqopt("", "channel", "current Rust channel", "CHANNEL")
147148
.optflag("", "git-hash", "run tests which rely on commit version being compiled into the binaries")
@@ -315,6 +316,8 @@ pub fn parse_config(args: Vec<String>) -> Config {
315316

316317
git_repository: matches.opt_str("git-repository").unwrap(),
317318
nightly_branch: matches.opt_str("nightly-branch").unwrap(),
319+
320+
profiler_support: matches.opt_present("profiler-support"),
318321
}
319322
}
320323

0 commit comments

Comments
 (0)