Rustup: show rust-src path -- for tools IDE tools like racer

Created on 2 Oct 2016  路  5Comments  路  Source: rust-lang/rustup

Tools like racer need to know the rust-src path of the current toolchain to work correctly (see https://github.com/phildawes/racer/issues/627).

It is already possible to query the path of binaries like rustc via rustup which rustc, which gives something like:

  • ~/.multirust/toolchains/stable-x86_64-unknown-linux-gnu/bin/rustc

Now it would be nice to have a similar command like rustup show rust-src return

  • ~/.multirust/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/src/

To my knowledge this is currently not possible. My first questions are:

  • Do you think this makes sense?
  • How should such a command look like?

Most helpful comment

Do you know about rustc --print sysroot? You can use it to print the toolchain root of your currently enabled toolchain, and the part after that (i.e. /lib/rustlib/src/rust/src/) should always be the same.

All 5 comments

Do you know about rustc --print sysroot? You can use it to print the toolchain root of your currently enabled toolchain, and the part after that (i.e. /lib/rustlib/src/rust/src/) should always be the same.

@Boddlnagg thanks, that's already a good hint. I included this in my suggestion for racer to make an "educated guess", where the source code resides for the currently active toolchain instead of relying on a global environment variable. :-)

Still I wonder if a direct query via rustup could be more stable. I.e. if the '_part after that_' changes unexpectedly, tools like racer could rely on rustup to handle this correctly - since the rust-src is installed by rustup anyway. But apart from that it's already quite good.

Using rustc --print sysroot is preferable, because then it doesn't matter if rust was installed through rustup or not.

Leaving this here: if you don't know what you're doing, but you want RACER to be happy:
rustup component add rust-src gets you the needed src folder, and then you can find its path:
echo `rustc --print sysroot`/lib/rustlib/src/rust/src

On windows10, rust 1.23.0, rustup component add rust-src was enough, thanks!

Was this page helpful?
0 / 5 - 0 ratings