Repository navigation
Add shared toolchain directories #4967
Description
Problem you are trying to solve
Hello!
As a package maintainer, I want to package different Rust toolchain distributions, such as stable, nightly, specific stable versions, or custom forks (for example, the ESP toolchain). To make this practical, some kind of toolchain multiplexer is needed. While I could write a minimal multiplexer myself, it would lack many useful features.
On the other hand, I could use rustup, which is widely adopted and well supported. However, its main drawback is poor integration with OS package managers. There is no automatic way to make a system-provided Rust toolchain available through rustup. Although it is possible to manually link a system toolchain, there is no mechanism to keep it synchronized with updates from the package manager.
As a user, I want to be able to use both the system-provided toolchain and the official Rust toolchain. For example, I may use one for day-to-day development and the other for feature testing or validation or in some cases I may want to use local distribution infrastructure. Which is possible but with some extra work.
Solution you'd like
To solve these issues, a separate shared directory managed by external tools could be added.
rustup should automatically discover toolchains from the shared directory.
Toolchains in RUSTUP_HOME should take precedence over toolchains from the shared directory. If a local toolchain shadows a shared toolchain with the same name, this should be clearly indicated. For example:
rustup default alt
info: shared toolchain overridden by `RUSTUP_HOME` toolchain
info: default toolchain set to alt
This feature should be opt-in. It should be possible to enable it through user or system configuration, or with an environment variable.
rustup toolchain list should clearly indicate which toolchains belong to which mechanism. For example:
$ rustup toolchain list
shared toolchains:
alt-1.90 (default)
alt-1.92
alt-nightly-1.95 (shadowed)
esp (shadowed)
local:
stable
alt-nightly-1.95
esp (active)
nightly
$ rustup toolchain list -v
shared toolchains (/usr/lib64/rust-toolchains/):
alt-1.90 (default) /usr/lib64/rust-toolchains/alt-1.90/
alt-1.92 /usr/lib64/rust-toolchains/alt-1.92/
alt-nightly-1.95 (shadowed) /usr/lib64/rust-toolchains/alt-nightly-1.95/
esp (shadowed) /usr/lib64/rust-toolchains/esp
local (/home/user/.rustup):
stable /home/user/.rustup/toolchains/stable
alt-nightly-1.95 /home/user/.rustup/toolchains/alt-nightly-1.95
esp (active) /home/user/RPM/BUILD/rust-esp/build/host/stage1
nightly /home/user/.rustup/toolchains/nightly
Notes
Related to #313, #1085, and #2383.
Unresolved problem:
Should this feature provide a mechanism for specifying multiple shared directories, or should it support only a single shared directory?
I have some initial work in progress, so I would like to implement this feature.
Activity
rami3l commentedon Jul 20, 2026
@Rx1513 Hello! My apologies but I'm not quite sure what are you looking for with this proposal.
As I understand it, since it's a link, a linked system toolchain from the package manager is automatically synchronized with updates from the package manager.
Why would batch-assigning a directory of linked toolchains simplify your workflow? Could you please elaborate?
Should it be the responsibility of the external tools, whatever they may be, to add such links?
PS: We are avoiding adding more layered configurations so I would prefer being more careful with that part of your proposal, and it's vital that we reach an understanding of what exactly is needed in your use case.
PPS: If you are referring to using project-specific sets of tools under a specific name, I have this proposal that may suit your needs: #4636
Rx1513 commentedon Jul 21, 2026
The problem is that each link is handled manually.
Two middle steps seems very unnecessary as it requires new useless information for user and some extra steps, especially when compared to official toolchains installation:
What I want is to make usage of system's toolchains is similar to usage of official toolchains:
or even:
In my opinion the additional lookup directory should create much smoother user experience when dealing with toolchains from other external sources.
It doesn't require from each user doing manual tedious work. It helps separate responsibilities: external tools manage external directories under administrator control, while the user's home directory remains solely the user's responsibility.
As far as I know many Linux distributions discourage when package manager messes with home directory so it's not the way. The only way is if user manually links every external toolchain or if administrator does it for them, which yet again messes with responsibility.
I think this feature keeps the configuration largely unchanged. It only adds an additional lookup directory for externally managed toolchains, while the existing per-user links continue to work unchanged.
I don't think this is related to the problems I'm addressing here, but thanks for help.
rami3l commentedon Jul 21, 2026
@Rx1513 Thanks for your detailed reply! As I roughly understand it, you are referring to adding support for a new toolchain directory for automatic toolchain discovery (but read-only)?
IRRC rustup treats every folder under the toolchain directory as a valid toolchain, so I am curious about how we could probably make it work with your case.
What is your specific distro/external tool that installs externally-managed Rust toolchains in a way that is compatible with your new directory proposed here? For Homebrew (what I'm using) for example, the system Rust toolchain is installed alongside other packages. Is rustup supposed to distinguish between those?
I'm not opposed to adding a new folder in the current rustup installation layout of some sort that you can possibly link a local directory to, IMHO the most important thing here is still what tool you are trying to make rustup work with.
Not quite; the
alt-nightly-1.95 (shadowed)in your previous example might indicate thatalt-nightly-1.95has different semantics under different situations, that is exactly the kind of extra complexity we would like to avoid.Rx1513 commentedon Jul 27, 2026
ALT Linux which uses apt-rpm. Currently we package our rust distribution in /usr/lib64/rust-toolchains and provide symlinks to it. So if you install rust and rustup and then replace /usr/bin/ toolchain symlinks with rustup proxies and then link toolchains you will be able to use both official and system's toolchain.
Package manager, nfs, rsync directories or any other ways to distribute compiled artifacts which rustup is able to treat as a toolchain.
I understand the concern about added complexity. However, the (shadowed) tag is simply an indication that a shared toolchain has a conflicting name with a user's toolchain, meaning the user's toolchain will take precedence. Without this indication, it wouldn't be obvious why the shared toolchain isn't being run. Although I may be wrong here, since I had forgotten that the active toolchain is already marked as (active), which may already provide enough context.
rami3l commentedon Jul 27, 2026
@Rx1513 Thanks for sharing the context!
I think in this case I can allow say linking
toolchain/+systo/usr/lib64/rust-toolchains, and then you can call your new toolchain assys/alt-nightly-1.95. Then an extra CLI interface can be provided, sayrustup toolchain link --dir sys /usr/lib64/rust-toolchainsThis is possible because the
+prefix has been allowed for toolchain names in #4650 plus/is not allowed in regular custom toolchain names, so that will not cause name clashes with existing toolchains.Do you think that would be a better compromise?
That is correct. What I want to say here is that I would prefer not to create precedence in new features, unless proven absolutely necessary.
Rx1513 commentedon Jul 28, 2026
I think that's a great compromise! But wouldn't it also allow relative paths that were prohibited in 2c9297d? I think the implementation should be extremely strict about which patterns are allowed, rejecting any extra
/,., or..components.rami3l commentedon Jul 28, 2026
@Rx1513 Would you mind elaborating? IIRC relative links means that the link targets are relative, but in this case link targets are absolute.
foo/barjust looks for a toolchain located at$RUSTUP_HOME/toolchains/+foo/bar, and$RUSTUP_HOME/toolchains/+foomust link to an absolute target.I don't think we will allow other kinds of components;
/is just a separator and is only allowed to appear once.Rx1513 commentedon Jul 28, 2026
I meant that rustup should reject any path traversal like
+foo/../../malicious/baror+foo/bar/../../malicious/barso rustup behaves exactly like you described it.