Skip to content

Commit d744709

Browse files
committed
compiletest: Add support for //@ needs-env-vars
1 parent c6c1796 commit d744709

File tree

4 files changed

+17
-0
lines changed

4 files changed

+17
-0
lines changed

src/doc/rustc-dev-guide/src/tests/directives.md

+1
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ settings:
158158

159159
- `needs-asm-support` — ignores if it is running on a target that doesn't have
160160
stable support for `asm!`
161+
- `needs-env-vars` - ignores if the target doesn't support environment variables
161162
- `needs-profiler-runtime` — ignores the test if the profiler runtime was not
162163
enabled for the target
163164
(`build.profiler = true` in rustc's `bootstrap.toml`)

src/tools/compiletest/src/common.rs

+10
Original file line numberDiff line numberDiff line change
@@ -520,6 +520,16 @@ impl Config {
520520
|| self.target_cfg().os == "emscripten";
521521
!unsupported_target
522522
}
523+
524+
pub fn has_env_vars(&self) -> bool {
525+
// As with some of the other target properties, we don't have a principled
526+
// way to know whether the target supports environment variables, so we
527+
// just hard-code a reasonable approximation.
528+
529+
let target = self.target_cfg();
530+
let no_env = matches!(target.arch.as_str(), "wasm32" | "wasm64") && target.os == "unknown";
531+
!no_env
532+
}
523533
}
524534

525535
/// Known widths of `target_has_atomic`.

src/tools/compiletest/src/directive-list.rs

+1
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ const KNOWN_DIRECTIVE_NAMES: &[&str] = &[
135135
"needs-deterministic-layouts",
136136
"needs-dlltool",
137137
"needs-dynamic-linking",
138+
"needs-env-vars",
138139
"needs-enzyme",
139140
"needs-force-clang-based-tests",
140141
"needs-git-hash",

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

+5
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,11 @@ pub(super) fn handle_needs(
174174
condition: config.with_std_debug_assertions,
175175
ignore_reason: "ignored if std wasn't built with debug assertions",
176176
},
177+
Need {
178+
name: "needs-env-vars",
179+
condition: config.has_env_vars(),
180+
ignore_reason: "ignored on targets without environment variables",
181+
},
177182
];
178183

179184
let (name, rest) = match ln.split_once([':', ' ']) {

0 commit comments

Comments
 (0)