Rustup: Optionally download source code along with toolchain

Created on 5 Dec 2015  Â·  17Comments  Â·  Source: rust-lang/rustup

Rust sources comes handy when you are using racer or when you are cross-compiling etc...
It would be nice to have a possibility to download/upgrade rust sources along with the toolchain.

Most helpful comment

Okay, so installing things works... But I expected a more out-of-the-box experience. Right now on arch linux it's actually harder to set up racer with rust sources installed by rustup than setting it up by installing rust-src from the AUR, because with rustup the sources are now in a much more obscure path – $HOME/.multirust/toolchains/$TOOLCHAIN/lib/rustlib/src/rust/src instead of just /usr/src/rust/src/. I don't know where this would best be fixed, as apparently rustup run isn't for what I thought it was so exporting it from there probably wouldn't make sense. But I think it's important that it is fixed somewhere.

I'll leave this here, in case someone on a different distribution wants to use the sources installed by rustup. It will set RUST_SRC_PATH to where rustup installed them (assuming you installed them for your default toolchain) when put in your shells config file (usually ~/.bashrc; requires re-login to take effect). EDIT: Much simplified version based on info from the racer issue:

export RUST_SRC_PATH="$(rustc --print sysroot)/lib/rustlib/src/rust/src"

All 17 comments

Maybe it's a good idea even to download them by default. libstd should not be that big, and if you are using multirust then you are most likely a developer and need sources for completion anyway.

if you are using multirust then you are most likely a developer and need sources for completion anyway.

Not all developers use completion.

Not all developers use completion.

Hm, I think that overwhelming majority uses at least hippie-expand or some alternative in their editor of choice.

Not all developers setup semantic completion, but I think it is because hippie-expand works out of the box, and almost anything else requires some awkward setup to actually be useful. So I think your argument works backwards: if we download sources by default, completion setup becomes easier and more developers use it :)

However I think that this may be not the best option here: see https://internals.rust-lang.org/t/what-do-you-think-about-publishing-libstd-on-crates-io/3227

Hm, I think that overwhelming majority uses at least hippie-expand

I've never even heard of hippie-expand. :smile: I think it really depends on the circles you run in.

I've never even heard of hippie-expand.
or some alternative in their editor of choice.

In vim it is Ctrl-N and called keyword completion I think

@brson I'd like to try to implement this unless libstd and related crates are uploaded to crates.io in the nearest future :)

@matklad Any updates?

@toothbrush7777777 no, unfortunately other things have happened :) At the same time the https://github.com/rust-lang/rfcs/pull/1133/ RFC looks like a better solution for the problem. The RFC, among other things, should allow cargo to download the source of stdlib.

Prerequisite: rust-lang/rust-buildbot#102

rust-lang/rust-buildbot#102 was merged.

@aka-demik Yep, the next nightly will be the first to contain source packages. Then we can test #659 against those source packages and hopefully get it merged.

I'm confident we'll be able to install source packages with the next release of rustup.

So the good news is that the rustup support for adding components (eg. source packages) was merged. The bad news is that it uncovered a problem in the new rust-src package generated upstream (see rust-lang/rust#35840) :disappointed:

rustup component add rust-src seems to work now! :)

I'll have to install racer via cargo it seems, as rustup run nightly-x86_64-unknown-linux-gnu racer complete std::io::B errors with a command not found when racer is in /usr/bin. But that shouldn't be a problem. I'll report back when it's installed and I've played around with it a bit!

Okay, so installing things works... But I expected a more out-of-the-box experience. Right now on arch linux it's actually harder to set up racer with rust sources installed by rustup than setting it up by installing rust-src from the AUR, because with rustup the sources are now in a much more obscure path – $HOME/.multirust/toolchains/$TOOLCHAIN/lib/rustlib/src/rust/src instead of just /usr/src/rust/src/. I don't know where this would best be fixed, as apparently rustup run isn't for what I thought it was so exporting it from there probably wouldn't make sense. But I think it's important that it is fixed somewhere.

I'll leave this here, in case someone on a different distribution wants to use the sources installed by rustup. It will set RUST_SRC_PATH to where rustup installed them (assuming you installed them for your default toolchain) when put in your shells config file (usually ~/.bashrc; requires re-login to take effect). EDIT: Much simplified version based on info from the racer issue:

export RUST_SRC_PATH="$(rustc --print sysroot)/lib/rustlib/src/rust/src"

o/ finally!

@jplatte I've opened this issue: phildawes/racer#595 which will make this zero setup.

Well, this doesn’t work very well for the Atom integration, which use either default /usr/local/src/rust/src or some static string of text (so I can’t use the --print sysroot trick).

@ariasuni I got around this by creating a symlink. Added a little script in my bash profile to keep it updated as well:

if [ "$(readlink -- "/usr/local/src/rust/src")" = "" ]; then
    $(ln -s $RUST_SRC_PATH /usr/local/src/rust)
elif [ "$(readlink -- "/usr/local/src/rust/src")" != "$RUST_SRC_PATH" ]; then
    rm /usr/local/src/rust/src
    $(ln -s $RUST_SRC_PATH /usr/local/src/rust)
fi

Silly, but it works (:

Was this page helpful?
0 / 5 - 0 ratings