Skip to content

Implement //@ needs-target-std compiletest directive #142297

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jun 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/bootstrap/src/core/config/toml/target.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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") {
Expand Down
1 change: 1 addition & 0 deletions src/build_helper/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
11 changes: 11 additions & 0 deletions src/build_helper/src/targets.rs
Original file line number Diff line number Diff line change
@@ -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"))
}
1 change: 1 addition & 0 deletions src/doc/rustc-dev-guide/src/tests/directives.md
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ settings:
`//@ needs-crate-type: cdylib, proc-macro` will cause the test to be ignored
on `wasm32-unknown-unknown` target because the target does not support the
`proc-macro` crate type.
- `needs-target-std` — ignores if target platform does not have std support.

The following directives will check LLVM support:

Expand Down
1 change: 1 addition & 0 deletions src/tools/compiletest/src/directive-list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ const KNOWN_DIRECTIVE_NAMES: &[&str] = &[
"needs-subprocess",
"needs-symlink",
"needs-target-has-atomic",
"needs-target-std",
"needs-threads",
"needs-unwind",
"needs-wasmtime",
Expand Down
5 changes: 5 additions & 0 deletions src/tools/compiletest/src/header/needs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,11 @@ pub(super) fn handle_needs(
condition: config.with_std_debug_assertions,
ignore_reason: "ignored if std wasn't built with debug assertions",
},
Need {
name: "needs-target-std",
condition: build_helper::targets::target_supports_std(&config.target),
ignore_reason: "ignored if target does not support std",
},
];

let (name, rest) = match ln.split_once([':', ' ']) {
Expand Down
11 changes: 11 additions & 0 deletions src/tools/compiletest/src/header/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -945,3 +945,14 @@ fn test_ignore_auxiliary() {
let config = cfg().build();
assert!(check_ignore(&config, "//@ ignore-auxiliary"));
}

#[test]
fn test_needs_target_std() {
// Cherry-picks two targets:
// 1. `x86_64-unknown-none`: Tier 2, intentionally never supports std.
// 2. `x86_64-unknown-linux-gnu`: Tier 1, always supports std.
let config = cfg().target("x86_64-unknown-none").build();
assert!(check_ignore(&config, "//@ needs-target-std"));
let config = cfg().target("x86_64-unknown-linux-gnu").build();
assert!(!check_ignore(&config, "//@ needs-target-std"));
}
6 changes: 1 addition & 5 deletions tests/run-make/cpp-global-destructors/rmake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,11 @@
//@ ignore-cross-compile
// Reason: the compiled binary is executed

//@ ignore-none
// Reason: no-std is not supported.
//@ ignore-wasm32
//@ ignore-wasm64
// Reason: compiling C++ to WASM may cause problems.

// Neither of these are tested in full CI.
//@ ignore-nvptx64-nvidia-cuda
// Reason: can't find crate "std"
// Not exercised in full CI, but sgx technically supports std.
//@ ignore-sgx

use run_make_support::{build_native_static_lib_cxx, run, rustc};
Expand Down
3 changes: 1 addition & 2 deletions tests/run-make/export-executable-symbols/rmake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@
// (See #85673)
//@ ignore-wasm32
//@ ignore-wasm64
//@ ignore-none
// Reason: no-std is not supported
//@ needs-target-std

use run_make_support::{bin_name, llvm_readobj, rustc};

Expand Down
5 changes: 1 addition & 4 deletions tests/run-make/incr-foreign-head-span/rmake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@
// source file from disk during compilation of a downstream crate.
// See https://github.com/rust-lang/rust/issues/86480

//@ ignore-none
// Reason: no-std is not supported
//@ ignore-nvptx64-nvidia-cuda
// Reason: can't find crate for 'std'
//@ needs-target-std

use run_make_support::{rfs, rust_lib_name, rustc};

Expand Down
6 changes: 1 addition & 5 deletions tests/run-make/incr-prev-body-beyond-eof/rmake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,7 @@
// was hashed by rustc in addition to the span length, and the fix still
// works.

//@ ignore-none
// reason: no-std is not supported

//@ ignore-nvptx64-nvidia-cuda
// FIXME: can't find crate for `std`
//@ needs-target-std

use run_make_support::{rfs, rustc};

Expand Down
5 changes: 1 addition & 4 deletions tests/run-make/incr-test-moved-file/rmake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,7 @@
// for successful compilation.
// See https://github.com/rust-lang/rust/issues/83112

//@ ignore-none
// Reason: no-std is not supported
//@ ignore-nvptx64-nvidia-cuda
// FIXME: can't find crate for 'std'
//@ needs-target-std

use run_make_support::{rfs, rustc};

Expand Down
5 changes: 1 addition & 4 deletions tests/run-make/moved-src-dir-fingerprint-ice/rmake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,7 @@
// sessions.
// See https://github.com/rust-lang/rust/issues/85019

//@ ignore-none
// Reason: no-std is not supported
//@ ignore-nvptx64-nvidia-cuda
// FIXME: can't find crate for 'std'
//@ needs-target-std

use run_make_support::{rfs, rust_lib_name, rustc};

Expand Down
Loading