Show installed path of Rust components: sources, docs & Clippy
Problem you are trying to solve
It would be nice if Rustup itself could show the paths of where Rust components (eg. rustc, rust_src, etc.) are installed.
Solution you'd like
Add a command to show path of Rust components (if installed).
$ rustup which rust_src
/path/to/folder/where/installed/rust_src
Notes
No response
Components aren't installed into isolated directories - they all exist under the toolchain root.
If you want the path to a binary, rustup which rustc already exists.
Possibly documentation could be improved here.
@rbtcollins How can I find the path to installed Rust sources?
You can see the files that rust-src includes by cat ~/.rustup/toolchains/<toolchain-name>/lib/rustlib/manifest-rust-src.
You can see the files that rust-src includes by
cat ~/.rustup/toolchains/<toolchain-name>/lib/rustlib/manifest-rust-src.
@rbtcollins rustup which rust-src should show path to sources of the default toolchain (stable or nightly). Similarly, rustup which clippy and rustup which rust-docs should also work.
Components aren't installed into isolated directories - they all exist under the toolchain root.
If you want the path to a binary,
rustup which rustcalready exists.Possibly documentation could be improved here.
@rbtcollins I believe we have rustup doc --path for this.
@rami3l TIL about rustup doc --path - is this mentioned in the documentation? Also are there similar commands to find paths of Rust sources and Clippy?
@sohang3112 May I ask what you are using these paths for?
TIL about
rustup doc --path- is this mentioned in the documentation?
Not yet, but there probably should be. It's already in the --help string though.
Also are there similar commands to find paths of Rust sources and Clippy?
Yes. Please note that clippy-driver is the real name of clippy, this is clearly documented in the Clippy User Guide.
So for the moment being:
$ rustup which clippy-driver # Gives the path of clippy
$ rustup which ../lib/rustlib/manifest-rust-src # A HACK, but does give the path of `rust-src`
If you don't like that hack, there's a more stable alternative to it:
$ echo "$(rustup show home)/toolchains/$(rustup show active-toolchain | awk '{print $1;}')"
I agree that the user experience here is awfully inconsistent and could use some improvements, doc-wise or impl-wise.
@rbtcollins Moving forwards I suggest we either:
- Implement
rustup which --prefixwhich gives~/.rustup/toolchains/<toolchain-name>/binand let the user handle the rest. - Implement something like
rustup component list --verbosewhich will add a path to lines likerustc-aarch64-apple-darwin (installed), and will print the path next to each component onrustup component list --installed --verbose. - Implement
rustup show active-toolchain --verbosewhich will do something similar to 2) but just for a single toolchain.
In any case, this should be scheduled after https://github.com/rust-lang/rustup/pull/3225 and https://github.com/rust-lang/rustup/pull/3596. The actual subcommand can be debated. We can afford to have true aliases as in #3596.
@sohang3112 Thanks a lot for your support!
... but you haven't answered my question yet:
May I ask what you are using these paths for?
Your original motivation is also very important in deciding the way forward.
@rami3l I originally started looking for the path to Rust sources when VS Code wasn't able to find Rust sources (I think it had something to do with some things not working for Rust in VS Code: Go to Definition, hovering to show function, etc. - I don't remember the exact details now). VS Code Rust extension gave an error that it couldn't find Rust sources.
@rami3l Is there any update on this issue?
@rami3l Is there any update on this issue?
@sohang3112 The plan is to finish this in the v1.28.0 release cycle, but as my life plans have suddenly changed and I'm now prioritizing my personal issues, I cannot give any guarantees on that. Please remember the Rustup project is fully run by volunteers and so far all team members are doing this as a hobby. If you'd like to work on this issue, please go ahead :)
If you'd like to work on this issue, please go ahead :)
Ok, I'll do that in a while. I'm new to Rust so I'll ask you if I have any questions.