|
| 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 |
0 commit comments