8000 Add `minicore` test auxiliary and support `//@ add-core-stubs` directive in ui/assembly/codegen tests by jieyouxu · Pull Request #130693 · rust-lang/rust · GitHub
[go: up one dir, main page]

Skip to content

Conversation

jieyouxu
Copy link
Member
@jieyouxu jieyouxu commented Sep 22, 2024

Context: Real cross-compiling tests instead of #![no_core] silliness #130375
MCP: rust-lang/compiler-team#786
Tracking issue: #131485

This prototype PR is subject to further changes based on feedback.

New minicore test auxiliary and //@ add-core-stubs compiletest directive

This PR introduces a prototype implementation of a minicore auxiliary test helper that provides core stubs for #![no_core] ui/assembly/codegen tests that need to build but not run on both the host platform and the cross-compiled target platform.

Key summary:

  • tests/auxiliary/minicore.rs contains stub definitions of core items intended for consumption by check-pass/build-pass tests that want the typical prelude items like Copy to be stubbed out under #![no_core] scenarios, so that the test can be built (not run) for cross-compiled target platforms. Such tests don't want nor need full -Z build-std (e.g. tests/ui/abi/compatibility.rs).
  • minicore is intended for core items only, not std- or alloc-exclusive items. If stubs for alloc or std are wanted, they should be provided by an additional directive and test auxiliary, a 8000 nd not be conflated with minicore or core stubs. This is because a wider range of tests can benefit from core-only stubs.

Implementation

  • The minicore auxiliary is a single source file tests/auxiliary/minicore.rs.
  • The path to minicore is made avaiable from bootstrap to compiletest via the --minicore-path compiletest flag.
  • minicore is then built on-demand via the //@ add-core-stubs compiletest directive, for each test revision for the given target platform (this distinction is important for when host platform != target platform in cross-compilation scenario).
  • minicore is then made available to the test as an extern prelude.

Example usage

// tests/ui/abi/my-abi-test.rs

//@ check-pass
//@ add-core-stubs
//@ compile-flags: --target i686-unknown-linux-gnu
//@ needs-llvm-components: x86

#![feature(no_core, lang_items)]
#![no_std]
#![no_core]
#![allow(unused, internal_features)]

extern crate minicore;
use minicore::*;

#[lang = "clone"]
pub trait Clone: Sized {      // `Sized` is provided by `minicore`
    fn clone(&self) -> Self;
}

Implementation steps

  • 1. Add an initial minicore test auxiliary.
  • 2. Build minicore in bootstrap.
  • 3. Setup a --minicore-path compiletest cli flag and pass minicore build artifact path from bootstrap to compiletest.
  • 4. Assert add-core-stubs is mutually incompatible with tests that require to be run, as the stubs are only good for tests that only need to be built (i.e. no run-{pass,fail}).
  • 5. Add some self-tests to sanity check the behavior.
  • 6. Ensure that tests/auxiliary/minicore.rs is input stamped, i.e. modifying tests/auxiliary/minicore.rs should invalidate test cache and force the test to be rerun.

Known limitations

  • The current minicore is very minimal, because this PR is intended to focus on supporting the test infrastructure first. Further stubs could be added in follow-up PRs and/or on a as-needed basis.

try-job: aarch64-apple
try-job: armhf-gnu
try-job: x86_64-msvc
try-job: test-various
try-job: dist-various-1

@rustbot rustbot added A-testsuite Area: The testsuite used to check the correctness of rustc S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Sep 22, 2024
@jieyouxu jieyouxu added needs-mcp This change is large enough that it needs a major change proposal before starting work. A-compiletest Area: The compiletest test runner S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Sep 22, 2024
@jieyouxu
Copy link
Member Author

@bors try

bors added a commit to rust-lang-ci/rust that referenced this pull request Sep 22, 2024
[PROTOTYPE] Add minicore test auxiliary and support `//@ use-minicore` directive in ui/assembly/codegen tests

**TODO: work in progress prototype implementation, opened early for MCP to reference**

Context: [Real cross-compiling tests instead of `#![no_core]` silliness rust-lang#130375](rust-lang#130375)

This PR introduces a prototype implementation of `minicore` auxiliary test helper. `minicore` contains stub definitions of std/core prelude items intended for consumption by tests that want the typical prelude items like `Copy` or `Result` in cross-compilation scenarios, but don't want nor need full `-Z build-std` (e.g. `tests/ui/abi/compatibility.rs`).

The `minicore` auxiliary is a single source file `tests/auxiliary/minicore.rs`. The path to this auxiliary is made avaiable from bootstrap to compiletest via the `--minicore-path` compiletest flag. The `minicore` auxiliary is then built, on demand via `//@ use-minicore` compiletest directives, for each test revision for the given target (this distinction is important for when host != target in cross-compilation scenario).

### Implementation steps

- [ ] 1. File an MCP to describe `tests/auxiliary/minicore.rs`, `--minicore-path` compiletest flag, `//@ use-minicore` compiletest directive and the behavior.
- [ ] 2. And some self-tests to sanity check the behavior.
- [ ] 3. Update rustc-dev-guide to describe the new `use-minicore` directive and provide an example, noting that `use-minicore` both requires `no_std` + `no_core` and implies `-C panic=abort` for the test file.

r? `@ghost` (not yet ready for full review, still needs some self-tests and some try-jobs)

(TODO: cc interested people once this passes initial try jobs in cross-compilation scenarios)
cc `@/workingjubilee` `@/RalfJung` `@/nikic` `@/chrisnc` (if this makes sense to you in terms of functionality and UX)

try-job: aarch64-apple
try-job: armhf-gnu
try-job: x86_64-msvc
try-job: test-various
try-job: dist-various-1
@bors
Copy link
Collaborator
bors commented Sep 22, 2024

⌛ Trying commit 9d6f01a with merge 01b2fff...

@jieyouxu jieyouxu added S-waiting-on-MCP Status: PR has a compiler MCP and is waiting for the compiler MCP to complete. and removed needs-mcp This change is large enough that it needs a major change proposal before starting work. labels Sep 22, 2024
@rust-log-analyzer

8000 This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@bors
Copy link
Collaborator
bors commented Sep 22, 2024

💔 Test failed - checks-actions

pub struct ManuallyDrop<T: ?Sized> {
value: T,
}
impl<T: Copy + ?Sized> Copy for ManuallyDrop<T> {}
Copy link
Member
@bjorn3 bjorn3 Sep 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can derive Copy if you add

#[rustc_builtin_macro]
pub macro Copy($item:item) {
    /* compiler built-in */
}

and the same applies to Clone.

8000
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did not make this change because I couldn't figure out how to make use of this, just kept manual impl Copy for ... for now.

@jieyouxu
Copy link
Member Author
jieyouxu commented Sep 28, 2024

Changes since last review:

  • Fixed bootstrap path of tests/auxiliary/minicore.rs to be constructed from a builder.src prefix.
  • Trimmed minicore.rs to only include a minimal subset of core items, excluding the ones that are easy to abuse like #[rustc_layout_scalar_valid_range_start(1)] or #[rustc_nonnull_optimization_guaranteed].
  • Made sure no alloc or std-specific items get included in minicore.
  • Removed cfg(host) and cfg(non(host)) distinction in tests/abi/compatibility.rs, and just unconditionally stub out core items. Not sure if this is desirable.
  • Fixed minicore doc comments to no longer mention std, instead emphasize core items only. Also added remarks about rustc-attribute-annotated core items.

@jieyouxu jieyouxu force-pushed the minicore branch 2 times, most recently from f4a7c38 to 8bd9644 Compare September 28, 2024 14:19

/// Builds `minicore`. Returns the path to the minicore rlib within the base test output
/// directory.
fn build_minicore(&self) -> PathBuf {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remark: I don't like how convoluted the top-level runtest logic is, but intended for future compiletest cleanup PRs instead of this PR.

@jieyouxu jieyouxu changed the title [PROTOTYPE] Add minicore test auxiliary and support //@ use-minicore directive in ui/assembly/codegen tests Add minicore test auxiliary and support //@ use-minicore directive in ui/assembly/codegen tests Sep 28, 2024
@jieyouxu
Copy link
Member Author

Rebased, no changes.

@bjorn3
Copy link
Member
bjorn3 commented Oct 31, 2024

r=me with the above change applied.

@bjorn3
Copy link
Member
bjorn3 commented Oct 31, 2024

@bors r+

@bors
Copy link
Collaborator
bors commented Oct 31, 2024

📌 Commit adb6d47 has been approved by bjorn3

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Oct 31, 2024
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Oct 31, 2024
Add `minicore` test auxiliary and support `//@ add-core-stubs` directive in ui/assembly/codegen tests

Context: [Real cross-compiling tests instead of `#![no_core]` silliness rust-lang#130375](rust-lang#130375)
MCP: rust-lang/compiler-team#786
Tracking issue: rust-lang#131485

This prototype PR is subject to further changes based on feedback.

### New `minicore` test auxiliary and `//@ add-core-stubs` compiletest directive

This PR introduces a prototype implementation of a `minicore` auxiliary test helper that provides `core` stubs for `#![no_core]` ui/assembly/codegen tests that need to build but not run on both the host platform and the cross-compiled target platform.

Key summary:

- `tests/auxiliary/minicore.rs` contains stub definitions of `core` items intended for consumption by `check-pass`/`build-pass` tests that want the typical prelude items like `Copy` to be stubbed out under `#![no_core]` scenarios, so that the test can be built (not run) for cross-compiled target platforms. Such tests don't want nor need full `-Z build-std` (e.g. `tests/ui/abi/compatibility.rs`).
- `minicore` is intended for `core` items **only**, not `std`- or `alloc`-exclusive items. If stubs for `alloc` or `std` are wanted, they should be provided by an additional directive and test auxiliary, and not be conflated with `minicore` or `core` stubs. This is because a wider range of tests can benefit from `core`-only stubs.

### Implementation

- The `minicore` auxiliary is a single source file `tests/auxiliary/minicore.rs`.
- The path to `minicore` is made avaiable from bootstrap to compiletest via the `--minicore-path` compiletest flag.
- `minicore` is then built on-demand via the `//@ add-core-stubs` compiletest directive, for each test revision for the given target platform (this distinction is important for when host platform != target platform in cross-compilation scenario).
- `minicore` is then made available to the test as an [extern prelude].

[extern prelude]: https://doc.rust-lang.org/reference/names/preludes.html#extern-prelude

### Example usage

```rs
// tests/ui/abi/my-abi-test.rs

//@ check-pass
//@ add-core-stubs
//@ compile-flags: --target i686-unknown-linux-gnu
//@ needs-llvm-components: x86

#![feature(no_core, lang_items)]
#![no_std]
#![no_core]
#![allow(unused, internal_features)]

extern crate minicore;
use minicore::*;

#[lang = "clone"]
pub trait Clone: Sized {      // `Sized` is provided by `minicore`
    fn clone(&self) -> Self;
}
```

### Implementation steps

- [x] 1. Add an initial `minicore` test auxiliary.
- [x] 2. Build `minicore` in bootstrap.
- [x] 3. Setup a `--minicore-path` compiletest cli flag and pass `minicore` build artifact path from bootstrap to compiletest.
- [x] 4. Assert `add-core-stubs` is mutually incompatible with tests that require to be `run`, as the stubs are only good for tests that only need to be built (i.e. no `run-{pass,fail}`).
- [x] 5. Add some self-tests to sanity check the behavior.
- [x] 6. Ensure that `tests/auxiliary/minicore.rs` is input stamped, i.e. modifying `tests/auxiliary/minicore.rs` should invalidate test cache and force the test to be rerun.

### Known limitations

- The current `minicore` is very minimal, because this PR is intended to focus on supporting the test infrastructure first. Further stubs could be added in follow-up PRs and/or on a as-needed basis.

try-job: aarch64-apple
try-job: armhf-gnu
try-job: x86_64-msvc
try-job: test-various
try-job: dist-various-1
bors added a commit to rust-lang-ci/rust that referenced this pull request Oct 31, 2024
…iaskrgr

Rollup of 5 pull requests

Successful merges:

 - rust-lang#130693 (Add `minicore` test auxiliary and support `//@ add-core-stubs` directive in ui/assembly/codegen tests)
 - rust-lang#132316 (CI: use free runners for 3 fast windows jobs)
 - rust-lang#132354 (Add `lp64e` RISC-V ABI)
 - rust-lang#132395 (coverage: Avoid ICE when `coverage_cx` is unexpectedly unavailable)
 - rust-lang#132396 (CI: use free runners for x86_64-gnu-tools and x86_64-rust-for-linux)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 2da5560 into rust-lang:master Oct 31, 2024
6 checks passed
@rustbot rustbot added this to the 1.84.0 milestone Oct 31, 2024
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Oct 31, 2024
Rollup merge of rust-lang#130693 - jieyouxu:minicore, r=bjorn3

Add `minicore` test auxiliary and support `//@ add-core-stubs` directive in ui/assembly/codegen tests

Context: [Real cross-compiling tests instead of `#![no_core]` silliness rust-lang#130375](rust-lang#130375)
MCP: rust-lang/compiler-team#786
Tracking issue: rust-lang#131485

This prototype PR is subject to further changes based on feedback.

### New `minicore` test auxiliary and `//@ add-core-stubs` compiletest directive

This PR introduces a prototype implementation of a `minicore` auxiliary test helper that provides `core` stubs for `#![no_core]` ui/assembly/codegen tests that need to build but not run on both the host platform and the cross-compiled target platform.

Key summary:

- `tests/auxiliary/minicore.rs` contains stub definitions of `core` items intended for consumption by `check-pass`/`build-pass` tests that want the typical prelude items like `Copy` to be stubbed out under `#![no_core]` scenarios, so that the test can be built (not run) for cross-compiled target platforms. Such tests don't want nor need full `-Z build-std` (e.g. `tests/ui/abi/compatibility.rs`).
- `minicore` is intended for `core` items **only**, not `std`- or `alloc`-exclusive items. If stubs for `alloc` or `std` are wanted, they should be provided by an additional directive and test auxiliary, and not be conflated with `minicore` or `core` stubs. This is because a wider range of tests can benefit from `core`-only stubs.

### Implementation

- The `minicore` auxiliary is a single source file `tests/auxiliary/minicore.rs`.
- The path to `minicore` is made avaiable from bootstrap to compiletest via the `--minicore-path` compiletest flag.
- `minicore` is then built on-demand via the `//@ add-core-stubs` compiletest directive, for each test revision for the given target platform (this distinction is important for when host platform != target platform in cross-compilation scenario).
- `minicore` is then made available to the test as an [extern prelude].

[extern prelude]: https://doc.rust-lang.org/reference/names/preludes.html#extern-prelude

### Example usage

```rs
// tests/ui/abi/my-abi-test.rs

//@ check-pass
//@ add-core-stubs
//@ compile-flags: --target i686-unknown-linux-gnu
//@ needs-llvm-components: x86

#![feature(no_core, lang_items)]
#![no_std]
#![no_core]
#![allow(unused, internal_features)]

extern crate minicore;
use minicore::*;

#[lang = "clone"]
pub trait Clone: Sized {      // `Sized` is provided by `minicore`
    fn clone(&self) -> Self;
}
```

### Implementation steps

- [x] 1. Add an initial `minicore` test auxiliary.
- [x] 2. Build `minicore` in bootstrap.
- [x] 3. Setup a `--minicore-path` compiletest cli flag and pass `minicore` build artifact path from bootstrap to compiletest.
- [x] 4. Assert `add-core-stubs` is mutually incompatible with tests that require to be `run`, as the stubs are only good for tests that only need to be built (i.e. no `run-{pass,fail}`).
- [x] 5. Add some self-tests to sanity check the behavior.
- [x] 6. Ensure that `tests/auxiliary/minicore.rs` is input stamped, i.e. modifying `tests/auxiliary/minicore.rs` should invalidate test cache and force the test to be rerun.

### Known limitations

- The current `minicore` is very minimal, because this PR is intended to focus on supporting the test infrastructure first. Further stubs could be added in follow-up PRs and/or on a as-needed basis.

try-job: aarch64-apple
try-job: armhf-gnu
try-job: x86_64-msvc
try-job: test-various
try-job: dist-various-1
@jieyouxu jieyouxu deleted the minicore branch October 31, 2024 15:30
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is much nicer! Thank you.

@jieyouxu jieyouxu added the A-test-infra-minicore Area: `minicore` test auxiliary and `//@ add-core-stubs` label Apr 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-compiletest Area: The compiletest test runner A-test-infra Area: test infrastructure (may span bootstrap/compiletest/more) A-test-infra-minicore Area: `minicore` test auxiliary and `//@ add-core-stubs` A-testsuite Area: The testsuite used to check the correctness of rustc S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Projects

No open projects
Development

Successfully merging this pull request may close these issues.

10 participants

0