From 339616b97afbd3b84c9fd5054f5cb8f7bbcfd249 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=AE=B8=E6=9D=B0=E5=8F=8B=20Jieyou=20Xu=20=28Joe=29?= <39484203+jieyouxu@users.noreply.github.com> Date: Thu, 23 Jan 2025 14:38:43 +0800 Subject: [PATCH] compiletest: implement `needs-subprocess` directive --- src/tools/compiletest/src/common.rs | 11 +++++++++++ src/tools/compiletest/src/directive-list.rs | 1 + src/tools/compiletest/src/header/needs.rs | 8 ++++++++ 3 files changed, 20 insertions(+) diff --git a/src/tools/compiletest/src/common.rs b/src/tools/compiletest/src/common.rs index c6f3d7c0d108..00821fc9f9db 100644 --- a/src/tools/compiletest/src/common.rs +++ b/src/tools/compiletest/src/common.rs @@ -488,6 +488,17 @@ impl Config { git_merge_commit_email: &self.git_merge_commit_email, } } + + pub fn has_subprocess_support(&self) -> bool { + // FIXME(#135928): compiletest is always a **host** tool. Building and running an + // capability detection executable against the **target** is not trivial. The short term + // solution here is to hard-code some targets to allow/deny, unfortunately. + + let unsupported_target = self.target_cfg().env == "sgx" + || matches!(self.target_cfg().arch.as_str(), "wasm32" | "wasm64") + || self.target_cfg().os == "emscripten"; + !unsupported_target + } } /// Known widths of `target_has_atomic`. diff --git a/src/tools/compiletest/src/directive-list.rs b/src/tools/compiletest/src/directive-list.rs index 5784cd831196..acdb3cbdd459 100644 --- a/src/tools/compiletest/src/directive-list.rs +++ b/src/tools/compiletest/src/directive-list.rs @@ -152,6 +152,7 @@ const KNOWN_DIRECTIVE_NAMES: &[&str] = &[ "needs-sanitizer-support", "needs-sanitizer-thread", "needs-std-debug-assertions", + "needs-subprocess", "needs-symlink", "needs-target-has-atomic", "needs-threads", diff --git a/src/tools/compiletest/src/header/needs.rs b/src/tools/compiletest/src/header/needs.rs index e19dcd992fc2..12f0790fb104 100644 --- a/src/tools/compiletest/src/header/needs.rs +++ b/src/tools/compiletest/src/header/needs.rs @@ -94,6 +94,11 @@ pub(super) fn handle_needs( condition: config.has_threads(), ignore_reason: "ignored on targets without threading support", }, + Need { + name: "needs-subprocess", + condition: config.has_subprocess_support(), + ignore_reason: "ignored on targets without subprocess support", + }, Need { name: "needs-unwind", condition: config.can_unwind(), @@ -351,6 +356,9 @@ fn find_dlltool(config: &Config) -> bool { dlltool_found } +// FIXME(#135928): this is actually not quite right because this detection is run on the **host**. +// This however still helps the case of windows -> windows local development in case symlinks are +// not available. #[cfg(windows)] fn has_symlinks() -> bool { if std::env::var_os("CI").is_some() {