Repository navigation
Testing a cross-compiled toolchain #108914
Description
We (Android platform) build a custom version of rustc. Basically, we take the source distro, apply a few patches, and run x.py with a custom config.toml.
I am working on 2 things, which are related:
-
We want to build a Rust toolchain that runs on Windows (MinGW). For various reasons, we'd prefer to do this by cross-compiling (i.e. build a Windows rustc on a Linux machine).
-
We want to test our toolchain in our CI pipeline. For example, run
x.py test tests/ui
So, I had the following "clever" idea:
- Cross-compile a windows toolchain on Linux.
- Copy it to a Windows machine.
- In Windows,
x.py --stage 0 test tests/uiwith the stage 0 / bootstrap configured to use my new toolchain.
I got a very helpful warning that I probably shouldn't be doing this, and inviting me to file this issue. When I proceeded anyway, with COMPILETEST_FORCE_STAGE0=1, I got a number of test failures (~200 out of ~13,000). (For comparison, when I ran x.py test tests/ui the "right" way, the tests all passed, so I'm pretty confident the failures weren't due to our patches and custom configuration.)
Is there a correct, supported way to do this? That is, run tests "after-the-fact" on a toolchain you just built, possibly on a different machine? If not, I am willing to add support for it, if there is interest.
I found several things that seemed related, but not quite right:
- According to the docs,
./x.py test distcheckapplies to a source tarball, not a compiled toolchain. - The remote test server seems to be for testing different targets, not for when the toolchain itself is cross-compiled. It also seems like it would be very difficult to use in our CI pipeline. It also seems like it poses security issues in a production environment (opening a port allowing arbitrary code execution).
Activity
jfgoog commentedon Mar 8, 2023
I took a look at some of the test failures, and they all seem to be related to the verbosity of error messages. For example, src/test/ui/borrowck/borrowck-move-out-of-overloaded-auto-deref.rs reports the following diff:
From digging into the code, I wonder if
-Zui-testingshould be forcing the extra context to be printed, but sometimes does not.the8472 commentedon Mar 8, 2023
Maybe copy over the output toolchain into the appropriate
build/<target>/stage1*directories and then run tests with--keep-stage? Low confidence in that it'll work since I haven't tried that.jfgoog commentedon Mar 8, 2023
I tried your suggestion, and it doesn't work. Or, at least, it's not straightforward. The contents of the stageX directories don't neatly correspond to a packaged toolchain. For example, I have stage1, stage1-std, and stage1-rustc directories, so I would probably have to do some surgery on the packaged toolchain and figure out where each bit came from, and where to restore it. It seems like that is likely to be brittle.
It also did a bunch of unnecessary work, including building LLVM, before finally failing with:
jyn514 commentedon Mar 9, 2023
This is about missing the source for libstd, not the verbosity. Don't know why that would vary between machines; maybe the absolute path to the repository is getting embedded into rustc at build time somehow?
In general, I don't want to spend very much time at all trying to support this; bootstrap already tries to support far too many use cases and we have no way to test "a toolchain built on one machine but run on another" in CI.
jfgoog commentedon Mar 9, 2023
This is helpful. I will see if I can figure out why we can't find the libstd sources.
I sympathize with your observation about testability. It would improve our testing, but make it harder for you.
jfgoog commentedon Mar 13, 2023
Just to close the loop, since I didn't mention it earlier: It is possible for us to build natively on Windows, just more awkward. We will probably try that route, which has the advantage of being what the official version of x86_64-pc-windows-gnu does.
RodBurman commentedon Apr 1, 2026
It has been 3 years since the last moment on this issue, so is it still an issue? If not we should close.