Repository: rust
Issue: Rethink how cross-compiling works, including the terminology
Labels: A-cross,T-bootstrap,A-docs,T-infra,A-contributor-roadblock

The current config.toml.example in rust says:

~~~~
# In addition to the build triple, other triples to produce full compiler
# toolchains for. Each of these triples will be bootstrapped from the build
# triple and then will continue to bootstrap themselves. This platform must
# currently be able to run all of the triples provided here.
#host = ["x86_64-unknown-linux-gnu"]   # defaults to just the build triple

# In addition to all host triples, other triples to produce the standard library
# for. Each host triple will be used to produce a copy of the standard library
# for each target triple.
#target = ["x86_64-unknown-linux-gnu"] # defaults to just the build triple
~~~~

Note that the terminology here is confusing. "build" in the cross-compiling context actually refers to the "host" platform in a normal compilation context, and "host" in the cross-compiling context actually refers to the "target" platform in a normal context. "target" in the cross-compiling context does not have an analogue in the normal context, since normally one is not compiling a compiler. If you are confused, more suitable names might be "host", "target-compiler" and "target-libstd". In fact it may be better to rename the config.toml keys to these ones. The older more confusing terminology comes from GCC I believe, and perhaps they got it from even older terminology.

In "host" where it says "This platform must currently be able to run all of the triples provided here." - this is (1) ostensibly not true, we have been cross-compiling in Debian arbitrary platforms A to arbitrary platforms B for a few years now by setting build = A, host = [B], target = [B] and (2) not desired, since you want to be able to arbitrarily cross-compile from any platform A to any platform B.

TL;DR: I'm not sure the original intention behind that statement, but it's not true today, not desired, and at least the documentation should be fixed.

In "target" where it says "Each host triple will be used to produce a copy of the standard library for each target triple" is unfortunately true, for example in Debian we have found cross-compiling to break when setting build = A, host = [B], target = [B, wasm32], and then the bootstrap tries to compile libstd:wasm32 using rustc:B which platform A can't run. (For some reason, if target is set to only [B], the bootstrap does *not* try to compile libstd:B using rustc:B, as noted also in the previous paragraph.)

I'm also unsure of the original intention behind this behaviour, I don't see why it's necessary or desirable to compile all target platforms (i.e. all libstds) using all of the host platforms (i.e. toolchains) that you're building, since some of these toolchains might not be executable by the build platform.

I would suggest this be fixed to "the build platform will be used to produce a copy of the standard library for each target triple". I tried doing this, but couldn't figure out how to make this work. In `src/bootstrap/builder.rs` in `maybe_run` I tried changing the "for host in hosts, for target in targets" double-loop into two single loops each with `host:` set to builder.build.build and `target:` set to either host or target, but then other stuff broke.

It doesn't help that the terms "host" and "target" are overloaded so confusingly too.