Skip to content

Commit 00c51a5

Browse files
authored
Rollup merge of #151294 - jieyouxu:infer-needs-target-std, r=Zalathar
compiletest: add implied `needs-target-std` for `codegen` mode tests unless annotated with `#![no_std]`/`#![no_core]` A `codegen` mode test (such as `codegen-llvm` test suite) will now by default have an implied `//@ needs-target-std` directive, *unless* the test explicitly has an `#![no_std]`/`#![no_core]` attribute which disables this behavior. - When a test has both `#![no_std]`/`#![no_core]` and `//@ needs-target-std`, the explicit `//@ needs-target-std` directive will cause the test to be ignored for targets that do not support std still. This is to make it easier to test out-of-tree targets / custom targets (and targets not tested in r-l/r CI) without requiring target maintainers to do a bunch of manual `//@ needs-target-std` busywork. Context: [#t-compiler/help > `compiletest` cannot find `core` library for target != host](https://rust-lang.zulipchat.com/#narrow/channel/182449-t-compiler.2Fhelp/topic/.60compiletest.60.20cannot.20find.20.60core.60.20library.20for.20target.20!.3D.20host/with/568652419) ## Implementation remarks This is an alternative version of rust-lang/rust#150672, with some differences: - *This* PR applies this implied-`needs-target-std` behavior to all `codegen` test mode tests. - *This* PR does the synthetic directive injection in the same place as implied-`codegen-run` directives. Both are of course hacks, but at least they're together next to each other.
2 parents f243ae7 + 41b48c6 commit 00c51a5

2 files changed

Lines changed: 10 additions & 2 deletions

File tree

src/tests/compiletest.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -311,14 +311,20 @@ For example, `./x test tests/debuginfo -- --debugger gdb` will only test GDB com
311311
312312
### Codegen tests
313313

314-
The tests in [`tests/codegen-llvm`] test LLVM code generation. They compile the test
315-
with the `--emit=llvm-ir` flag to emit LLVM IR. They then run the LLVM
314+
The tests in [`tests/codegen-llvm`] test LLVM code generation. They compile the
315+
test with the `--emit=llvm-ir` flag to emit LLVM IR. They then run the LLVM
316316
[FileCheck] tool. The test is annotated with various `// CHECK` comments to
317317
check the generated code. See the [FileCheck] documentation for a tutorial and
318318
more information.
319319

320320
See also the [assembly tests](#assembly-tests) for a similar set of tests.
321321

322+
By default, codegen tests will have `//@ needs-target-std` *implied* (that the
323+
target needs to support std), *unless* the `#![no_std]`/`#![no_core]` attribute
324+
was specified in the test source. You can override this behavior and explicitly
325+
write `//@ needs-target-std` to only run the test when target supports std, even
326+
if the test is `#![no_std]`/`#![no_core]`.
327+
322328
If you need to work with `#![no_std]` cross-compiling tests, consult the
323329
[`minicore` test auxiliary](./minicore.md) chapter.
324330

src/tests/directives.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,8 @@ The following directives will check rustc build settings and target settings:
200200
on `wasm32-unknown-unknown` target because the target does not support the
201201
`proc-macro` crate type.
202202
- `needs-target-std` — ignores if target platform does not have std support.
203+
- See also [`#![no_std]`/`#![no_core]` and implied `needs-target-std` for
204+
codegen tests](./compiletest.md#codegen-tests).
203205
- `ignore-backends` — ignores the listed backends, separated by whitespace characters.
204206
Please note
205207
that this directive can be overriden with the `--bypass-ignore-backends=[BACKEND]` command line

0 commit comments

Comments
 (0)