rust icon indicating copy to clipboard operation
rust copied to clipboard

Implement `//@ needs-target-std` compiletest directive

Open jieyouxu opened this issue 7 months ago • 1 comments

Closes rust-lang/rust#141863. Needed to unblock rust-lang/rust#139244 and rust-lang/rust#141856.

Summary

This PR implements a //@ needs-target-std compiletest directive that gates test execution based on whether the target supports std or not. For some cases, this should be preferred over e.g. some combination of //@ ignore-none, //@ ignore-nvptx and more[^none-limit].

Implementation limitation

Unfortunately, since there is currently no reliable way to determine from metadata whether a given target supports std or not, we have to resort to a hack. Bootstrap currently determines whether or not a target supports std by a naive target tuple substring comparison: a target supports std if its target tuple does not contain one of ["-none", "nvptx", "switch"] substrings. This PR simply pulls that hack out into build_helpers to avoid reimplementing the same hack in compiletest, and uses that logic to inform //@ needs-target-std.

Auxiliary changes

This PR additionally changes a few run-make tests to use //@ needs-target-std over an inconsistent combination of target-based ignores. This should help with rust-lang/rust#139244.


r? bootstrap

[^none-limit]: Notably, target_os = "none" is not a sufficient condition for "target does not support std"

jieyouxu avatar Jun 10 '25 14:06 jieyouxu

This PR modifies src/bootstrap/src/core/config.

If appropriate, please update CONFIG_CHANGE_HISTORY in src/bootstrap/src/utils/change_tracker.rs.

The rustc-dev-guide subtree was changed. If this PR only touches the dev guide consider submitting a PR directly to rust-lang/rustc-dev-guide otherwise thank you for updating the dev guide with your changes.

cc @BoxyUwU, @jieyouxu, @kobzol

rustbot avatar Jun 10 '25 14:06 rustbot

Since you're already looking at it, r? Kobzol

jieyouxu avatar Jun 10 '25 15:06 jieyouxu

Maybe you could do the usual try build with "annoying CI jobs that cross-compile". Feel free to r=me with or without doing that.

Kobzol avatar Jun 10 '25 15:06 Kobzol

We have some metadata for that inn the Target json input/output.

https://github.com/rust-lang/rust/blob/100199c9aa50b0c47b37c9c86335d68b2a77b535/compiler/rustc_target/src/json.rs#L101

Urgau avatar Jun 10 '25 15:06 Urgau

We have some metadata for that inn the Target json input/output.

https://github.com/rust-lang/rust/blob/100199c9aa50b0c47b37c9c86335d68b2a77b535/compiler/rustc_target/src/json.rs#L101

Please see https://github.com/rust-lang/rust/issues/142296, I've looked at that avenue already. TL;DR not all built-in target specs have this metadata std field

rustc similarly does not have any way to convey this information. For instance, the closest thing is the target spec metadata.std field, but not all built-in target specs actually populate this field[^intent]. Built-in target specs currently without std support field

(Which additionally, the metadata field is only intended for doc generation purposes, and I don't think we can rely on that as-is even if all target specs do have this metadata available.)

jieyouxu avatar Jun 10 '25 15:06 jieyouxu

@bors2 try jobs=test-various,armhf-gnu

jieyouxu avatar Jun 10 '25 15:06 jieyouxu

:hourglass: Trying commit c558db34dc4ad66236d09ba7a2101a4c6b8cacd5 with merge 5a1574d9d1d5c87041fdcc35c5794fbf60746c7c…

To cancel the try build, run the command @bors2 try cancel.

rust-bors[bot] avatar Jun 10 '25 15:06 rust-bors[bot]

@rustbot author

jieyouxu avatar Jun 10 '25 16:06 jieyouxu

:sunny: Try build successful (CI) Build commit: 5a1574d9d1d5c87041fdcc35c5794fbf60746c7c (5a1574d9d1d5c87041fdcc35c5794fbf60746c7c)

rust-bors[bot] avatar Jun 10 '25 17:06 rust-bors[bot]

@bors r=Kobzol rollup

jieyouxu avatar Jun 10 '25 18:06 jieyouxu

:pushpin: Commit c558db34dc4ad66236d09ba7a2101a4c6b8cacd5 has been approved by Kobzol

It is now in the queue for this repository.

bors avatar Jun 10 '25 18:06 bors