Skip to content

Commit 2902236

Browse files
committed
Describe minicore test auxiliary and directive
1 parent cd50462 commit 2902236

File tree

4 files changed

+64
-0
lines changed

4 files changed

+64
-0
lines changed

src/SUMMARY.md

+1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
- [Compiletest](./tests/compiletest.md)
2626
- [UI tests](./tests/ui.md)
2727
- [Test directives](./tests/directives.md)
28+
- [Minicore](./tests/minicore.md)
2829
- [Ecosystem testing](./tests/ecosystem.md)
2930
- [Crater](./tests/crater.md)
3031
- [Fuchsia](./tests/fuchsia.md)

src/tests/compiletest.md

+6
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,9 @@ more information.
283283

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

286+
If you need to work with `#![no_std]` cross-compiling tests, consult the
287+
[`minicore` test auxiliary](./minicore.md) chapter.
288+
286289
[`tests/codegen`]: https://github.com/rust-lang/rust/tree/master/tests/codegen
287290
[FileCheck]: https://llvm.org/docs/CommandGuide/FileCheck.html
288291

@@ -303,6 +306,9 @@ information.
303306

304307
See also the [codegen tests](#codegen-tests) for a similar set of tests.
305308

309+
If you need to work with `#![no_std]` cross-compiling tests, consult the
310+
[`minicore` test auxiliary](./minicore.md) chapter.
311+
306312
[`tests/assembly`]: https://github.com/rust-lang/rust/tree/master/tests/assembly
307313

308314

src/tests/minicore.md

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# `minicore` test auxiliary: using `core` stubs
2+
3+
<!-- date-check Oct 2024 -->
4+
5+
[`tests/auxiliary/minicore.rs`][`minicore`] is a test auxiliary for
6+
ui/codegen/assembly test suites. It provides `core` stubs for tests that need to
7+
build for cross-compiled targets but do not need/want to run.
8+
9+
A test can use [`minicore`] by specifying the `//@ add-core-stubs` directive.
10+
Then, mark the test with `#![feature(no_core)]` + `#![no_std]` + `#![no_core]`.
11+
Due to Edition 2015 extern prelude rules, you will probably need to declare
12+
`minicore` as an extern crate.
13+
14+
Due to the `no_std` + `no_core` nature of these tests, `//@ add-core-stubs`
15+
implies and requires that the test will be built with `-C panic=abort`.
16+
Unwinding panics are not supported.
17+
18+
If you find a `core` item to be missing from the [`minicore`] stub, consider
19+
adding it to the test auxiliary if it's likely to be used or is already needed
20+
by more than one test.
21+
22+
<div class="warning">
23+
Please note that [`minicore`] is only intended for `core` items, and explicitly
24+
**not** `std` or `alloc` items because `core` items are applicable to a wider
25+
range of tests.
26+
</div>
27+
28+
## Example codegen test that uses `minicore`
29+
30+
```rust,no_run
31+
//@ add-core-stubs
32+
//@ revisions: meow bark
33+
//@[meow] compile-flags: --target=x86_64-unknown-linux-gnu
34+
//@[meow] needs-llvm-components: x86
35+
//@[bark] compile-flags: --target=wasm32-unknown-unknown
36+
//@[bark] needs-llvm-components: webassembly
37+
38+
#![crate_type = "lib"]
39+
#![feature(no_core)]
40+
#![no_std]
41+
#![no_core]
42+
43+
extern crate minicore;
44+
use minicore::*;
45+
46+
struct Meow;
47+
impl Copy for Meow {} // `Copy` here is provided by `minicore`
48+
49+
// CHECK-LABEL: meow
50+
#[unsafe(no_mangle)]
51+
fn meow() {}
52+
```
53+
54+
[minicore]: https://github.com/rust-lang/rust/tree/master/tests/auxiliary/minicore.rs

src/tests/ui.md

+3
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ used for many other purposes. For example, tests can also be configured to [run
1313
the resulting program](#controlling-passfail-expectations) to verify its
1414
behavior.
1515

16+
If you need to work with `#![no_std]` cross-compiling tests, consult the
17+
[`minicore` test auxiliary](./minicore.md) chapter.
18+
1619
[`tests/ui`]: https://github.com/rust-lang/rust/blob/master/tests/ui
1720

1821
## General structure of a test

0 commit comments

Comments
 (0)