Skip to content

Real cross-compiling tests instead of #![no_core] silliness #130375

Open

Description

@workingjubilee

We have a zillion tests that use the #![no_core] hack, like this one:

A given test involves:

  • Host A
  • Target B
  • Some Rust source (compiled for Target B)
  • Test tooling (run on Host A)

Most of our test infra assumes that Host A and Target B are the same thing. This greatly simplifies a lot of assumptions. But this hack we have introduced in so many tests essentially exists so that we can be sure the test runs even when cross-compiling from Host A to Target B. It's possible there's some weird finagling of test flags that can enable this without the hack, but that would be another hack itself. Cross-compiled tests should be relatively easy, like just writing something like:

//@ cross-compile-targets: arch_1-unknown-os_3-env_5 arch_2-unknown-os_4-env_6 arch_1-unknown-os_4-env_5 arch_2-unknown-os_3-env_7

Activity

  1. added
    needs-triageThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triaging
    on Sep 14, 2024
  2. added
    A-testsuiteArea: The testsuite used to check the correctness of rustc
    A-compiletestArea: The compiletest test runner
    on Sep 14, 2024
  3. added
    T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
    on Sep 14, 2024
  4. added
    T-bootstrapRelevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap)
    on Sep 14, 2024
  5. workingjubilee commented on Sep 14, 2024

    @workingjubilee
    MemberAuthor

    sorry @jieyouxu!

  6. added
    C-enhancementCategory: An issue proposing an enhancement or a PR with one.
    and removed
    needs-triageThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triaging
    on Sep 15, 2024
  7. nikic commented on Sep 16, 2024

    @nikic
    Contributor

    The problem here is that without no_core, you actually have to build core/std for the target. We have some tests that test ~all targets, and having everyone build core/std for 100 targets just to run some codegen or assembly tests would be ... not great.

  8. workingjubilee commented on Sep 16, 2024

    @workingjubilee
    MemberAuthor

    That would probably be bad, yes. Handling this correctly probably requires some coordination between bootstrap and compiletest about which stdlibs are built (or can be built, or may be desirable to build).

  9. workingjubilee commented on Sep 16, 2024

    @workingjubilee
    MemberAuthor

    I don't know that we'd even need much to extract information like "Ignored 20 assembly tests with 50 revisions because you didn't build std for aarch64-apple-darwin and 69 other targets."

    That would presume treating it like something between needs-llvm-component and compile-flags: --target.

    It probably wouldn't replace every no_core test. But there are many cases where no_core tests aren't good enough or are too tedious to write so they simply don't get written, and then there's no way to run the test that didn't get written, but if we had at least the core built we could write the tests.

  10. RalfJung commented on Sep 16, 2024

    @RalfJung
    Member

    We also have the problem that for most of our targets, you can't easily cross-compile the sysroot. Building a windows std on my Linux host doesn't "just work", at the very least it requires a bunch of tooling to be installed system-wide (because std has C dependencies, and because a linker is needed to build the final artifact). As long as that requirement stands, I think the no_core approach is crucial to be able to let people run and --bless those tests without having to install all sorts of stuff on their system.

    We don't actually need std for these tests, though. Can we build a "core-only sysroot" for these targets when needed? That should be faster than building a full sysroot, and it should in principle be possible without any target-specific tools.

    That said, looking at one of my own no_core tests (tests/ui/abi/compatibility.rs), I definitely don't want to have to build core 12 times just to be able to run that test on all targets. So I think we want to keep tests like this no_core. I don't think that's actually such a bad hack, TBH -- the only thing that bothers me about it is having to update all those lang items in a bunch of tests. That can be fixed with a minicore.rs file that we include! into these no_core tests, rather than having to copy-paste the same stuff everywhere.

  11. 3 remaining items

  12. jieyouxu commented on Sep 17, 2024

    @jieyouxu
    Member

    I can work on this, I'm just not sure what the exact design should be.

  13. self-assigned this
    on Sep 17, 2024
  14. jieyouxu commented on Sep 17, 2024

    @jieyouxu
    Member

    As @compiler-errors mentioned in #130466 (comment), we can probably have something like //@ aux-build: minicore.rs but a separate compiletest flag since we don't want to have a copy of minicore.rs under a auxiliary folder relative to every test that needs it.

  15. RalfJung commented on Sep 17, 2024

    @RalfJung
    Member

    Yeah I am not sure what is the best way to do this -- something like tests/util/minicore.rs that we can include! everywhere would work, but maybe an aux-build is better?

    Maybe this should be an MCP, then more t-compiler people can weigh in.

  16. jieyouxu commented on Sep 17, 2024

    @jieyouxu
    Member

    Yeah, I can file a new MCP ~tomorrow so more compiler people can advice.

  17. jieyouxu commented on Sep 17, 2024

    @jieyouxu
    Member

    Yeah I am not sure what is the best way to do this -- something like tests/util/minicore.rs that we can include! everywhere would work, but maybe an aux-build is better?

    ui tests have the precedent of a C test_helpers.c file, so I suppose assembly and codegen tests could get their own special support file lol. Just don't want any hard-to-debug cursedness due to staging and whatever.

  18. added a commit that references this issue on Sep 22, 2024
  19. jieyouxu commented on Sep 22, 2024

    @jieyouxu
    Member

    I have a prototype PR at #130693 and opened MCP at rust-lang/compiler-team#786.

  20. added
    E-mediumCall for participation: Medium difficulty. Experience needed to fix: Intermediate.
    on Oct 17, 2024
  21. added 2 commits that reference this issue on Oct 31, 2024
  22. added a commit that references this issue on Oct 31, 2024
  23. removed their assignment
    on Dec 12, 2025
  24. added
    E-hardCall for participation: Hard difficulty. Experience needed to fix: A lot.
    and removed
    E-mediumCall for participation: Medium difficulty. Experience needed to fix: Intermediate.
    on Dec 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-compiletestArea: The compiletest test runnerA-crossArea: Cross compilationA-testsuiteArea: The testsuite used to check the correctness of rustcC-enhancementCategory: An issue proposing an enhancement or a PR with one.E-hardCall for participation: Hard difficulty. Experience needed to fix: A lot.T-bootstrapRelevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap)T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions