about summary refs log tree commit diff
diff options
context:
space:
mode:
authorJieyou Xu <jieyouxu@outlook.com>2025-06-10 22:10:10 +0800
committerJieyou Xu <jieyouxu@outlook.com>2025-06-10 22:10:10 +0800
commit8ef8062d65055f2b54bd030487ae0e3388aa827a (patch)
treea64ad7f3c994d9a242be6d0b8295c39da93f3453
parent7c10378e1fee5ddc6573b916aeb884ab10e0de17 (diff)
downloadrust-8ef8062d65055f2b54bd030487ae0e3388aa827a.tar.gz
rust-8ef8062d65055f2b54bd030487ae0e3388aa827a.zip
Extract target no-std hack to `build_helpers`
To centralize this hack in one place with a backlink to the issue
tracking this hack, as this logic is also needed by compiletest to
implement a `//@ needs-target-std` directive.
-rw-r--r--src/bootstrap/src/core/config/toml/target.rs2
-rw-r--r--src/build_helper/src/lib.rs1
-rw-r--r--src/build_helper/src/targets.rs11
3 files changed, 13 insertions, 1 deletions
diff --git a/src/bootstrap/src/core/config/toml/target.rs b/src/bootstrap/src/core/config/toml/target.rs
index 7f074d1b25e..b8fc3e74c35 100644
--- a/src/bootstrap/src/core/config/toml/target.rs
+++ b/src/bootstrap/src/core/config/toml/target.rs
@@ -84,7 +84,7 @@ pub struct Target {
 impl Target {
     pub fn from_triple(triple: &str) -> Self {
         let mut target: Self = Default::default();
-        if triple.contains("-none") || triple.contains("nvptx") || triple.contains("switch") {
+        if !build_helper::targets::target_supports_std(triple) {
             target.no_std = true;
         }
         if triple.contains("emscripten") {
diff --git a/src/build_helper/src/lib.rs b/src/build_helper/src/lib.rs
index 1f5cf723641..05de8fd2d42 100644
--- a/src/build_helper/src/lib.rs
+++ b/src/build_helper/src/lib.rs
@@ -6,6 +6,7 @@ pub mod fs;
 pub mod git;
 pub mod metrics;
 pub mod stage0_parser;
+pub mod targets;
 pub mod util;
 
 /// The default set of crates for opt-dist to collect LLVM profiles.
diff --git a/src/build_helper/src/targets.rs b/src/build_helper/src/targets.rs
new file mode 100644
index 00000000000..cccc413368b
--- /dev/null
+++ b/src/build_helper/src/targets.rs
@@ -0,0 +1,11 @@
+// FIXME(#142296): this hack is because there is no reliable way (yet) to determine whether a given
+// target supports std. In the long-term, we should try to implement a way to *reliably* determine
+// target (std) metadata.
+//
+// NOTE: this is pulled out to `build_helpers` to share this hack between `bootstrap` and
+// `compiletest`.
+pub fn target_supports_std(target_tuple: &str) -> bool {
+    !(target_tuple.contains("-none")
+        || target_tuple.contains("nvptx")
+        || target_tuple.contains("switch"))
+}