Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Append ~/.rustup/toolchains/bin to PATH when running a proxy #3389

Open
jyn514 opened this issue Jun 21, 2023 · 2 comments
Open

Append ~/.rustup/toolchains/bin to PATH when running a proxy #3389

jyn514 opened this issue Jun 21, 2023 · 2 comments

Comments

@jyn514
Copy link
Member

jyn514 commented Jun 21, 2023

Problem you are trying to solve

I am writing a new rustc_driver tool (say it's called foo). I want to be able to have multiple versions, so I've put it in the toolchain directory instead of the per-user ~/.cargo/bin (which only allows a single version). Additionally, I want to be able to run it as cargo +nightly foo, so I have a cargo-foo binary which works like cargo-clippy, setting RUSTC_WORKSPACE_WRAPPER.

90% percent of this already works. cargo +nightly foo runs the rustup proxy, which sets RUSTUP_TOOLCHAIN and runs the correct version of cargo, which calls cargo-foo. Here's the problem: cargo-foo is not actually in PATH. It's in /Users/jyn/.local/lib/rustup/toolchains/stage1/bin/cargo-foo, not ~/.cargo/bin. To make this work, I have to write a third cargo-foo binary to go in ~/.cargo/bin and dispatch based on RUSTUP_TOOLCHAIN.

Solution you'd like

It would be really nice if rustup would add /Users/jyn/.local/lib/rustup/toolchains/stage1/bin to PATH so that I don't need to write this third binary. That would make it fully scoped to the toolchain directory so there's no global setup needed and I don't have to worry about differences between the proxy in different versions.

Notes

Unfortunately, this has caused issues in the past; #3178 has a very good writeup. I think as long as we always append the directory to the path, so that it's only used if there's no proxy in ~/.cargo/bin, this should work ok, but it's a complicated space.

@jyn514
Copy link
Member Author

jyn514 commented Jun 21, 2023

Oh, another alternative which is much less likely to break is to have a custom x setup foo step where bootstrap is the one in charge of installing the proxy - that wouldn't need rustup changes and only comes at the cost of a single extra manual step.

@rbtcollins
Copy link
Contributor

So adding to the path means that when users do complicated things; e.g. consider two levels of recursion through proxies, outer layer toolchain X, inner layer toolchain Y, PATH then has $ORIG_PATH:X/bin:Y/bin, anything resolving by PATH will get binaries from X, not Y.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants