rust-lang / rust-lang/rustup

Lazy installation of targets listed in rust-toolchain.toml

Open
#4,027 6 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement
Dominant language
Rust
Stars
7k
Forks
1.1k
Avg merge
22h 40m
Merged PRs (30d)
46

Description

Problem you are trying to solve

My team builds our software for 5 different Rust targets:

  • aarch64-apple-darwin
  • x86_64-apple-darwin
  • x86_64-unknown-linux-gnu
  • wasm32-unknown-unknown
  • x86_64-pc-windows-msvc

When building for macOS, we typically only build aarch64-apple-darwin, but sometimes also build for Intel Macs when we're putting together a release. Similarly, on Linux, we sometimes are compiling for the host architecture, but sometimes (especially in CI) compiling for wasm.

If we don't include our extra targets in rust-toolchain.toml, we'll run into errors when running cargo with a cross-compilation target (unless we explicitly install the toolchain). If we do include the extra targets, they'll get installed on every machine and CI runner, whether it makes sense or not. (We really don't need the macOS targets when we're on a Linux CI runner trying to make sure our wasm binary compiles.)

While it's not that hard to explicitly install the toolchain where we need it, it's extra friction vs. sticking it in the targets list and having it automatically installed.

Solution you'd like

It would be nice if there were a way to keep all of our supported targets listed in rust-toolchain.toml, but defer installation of the target until cargo is invoked for that particular target.

It's the best of both worlds - we get automatic installation of the cross-compilation targets we need, but we don't end up installing them eagerly on systems where it doesn't make sense.

As a strawman, one could imagine something like the following:

[toolchain]
channel = "1.80.1"
components = ["rustfmt", "clippy"]
# List all targets that we support.
targets = [
    "aarch64-apple-darwin",
    "x86_64-apple-darwin",
    "x86_64-unknown-linux-gnu",
    "wasm32-unknown-unknown",
    "x86_64-pc-windows-msvc",
]
# Only install the target on the host machine at the time it is actually needed.
lazy-target-installation = true
profile = "minimal"
Notes

No response

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by tracing how rustup handles the targets listed in rust-toolchain.toml when cargo is invoked for a cross-compilation target. Define the behavior for lazy-target-installation, including when a target is installed and when it remains absent; done means the documented configuration installs only the target actually requested.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
cli, tooling
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.