asdf-community / asdf-rust

Rust plugin for the asdf version manager
https://github.com/asdf-vm/asdf
Apache License 2.0
97 stars 16 forks source link

question - how to get stdlib sources for intellij? #18

Open timabell opened 2 years ago

timabell commented 2 years ago

Hi, this is more of a question than a bug, I hope you don't mind me asking here.

I have installed rustc etc with this asdf plugin and that's all working great.

When I open the project I'm working on in IntelliJ (CLion) with the IntelliJ Rust plugin it can't find stdlib and asks for the location or rustup. Having looked around it seems this plugin only installs the tool binaries (which makes sense), so I don't currently have the sources it's looking for.

Selection_029

I haven't installed rustup as presumably that overlaps in purpose with asdf. I don't really want to mess up my asdf setup by using rustup so I'm not sure what to do.


Edit I got this working as per https://stackoverflow.com/questions/41464063/how-to-provide-standard-library-sources-for-intellij-ideas-rust-project/63934669#63934669 by downloading and extracting the sources directly from the source code links at the bottom of https://forge.rust-lang.org/infra/other-installation-methods.html#source-code and telling IntelliJ where to find them:

Settings_001


I guess ideally it'd be cool if this asdf plugin could also pull in the sources needed for intellij to behave.

begleynk commented 2 years ago

I'm actually facing a similar issue and found this issue through some Googling. My VSCode and Vim setups can't autocomplete std modules. My own code in the workspace autocompletes just fine.

I've tried updating the $RUST_SRC_PATH env var to point to asdf's current toolchain and the included std lib source, but this hasn't had an effect. Not quite sure how to debug this further at the moment. I suspect the editors are just not picking up the asdf toolchain or something?

This might not even really be an issue with asdf itself, but would love to hear if/how someone else has resolved this.

begleynk commented 2 years ago

Ended up solving my issue, I think. Seems like rustup is setting the path for $RUST_SRC_PATH incorrectly. Nothing to do with asdf.

After I updated it from

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

to (note the last part)

export RUST_SRC_PATH="$( $HOME/.cargo/bin/rustc --print sysroot )/lib/rustlib/src/rust/library"

things started working for me.

sontek commented 2 years ago

I just ran into this, I don't even see src in my install:

❯ find /Users/sontek/.asdf/installs/rust/1.61.0 -name src
/Users/sontek/.asdf/installs/rust/1.61.0/share/doc/rust/html/book/2018-edition/src
/Users/sontek/.asdf/installs/rust/1.61.0/share/doc/rust/html/book/first-edition/src
/Users/sontek/.asdf/installs/rust/1.61.0/share/doc/rust/html/src
/Users/sontek/.asdf/installs/rust/1.61.0/share/doc/rust/html/src/core/up/up/portable-simd/crates/core_simd/src
/Users/sontek/.asdf/installs/rust/1.61.0/share/doc/rust/html/src/core/up/up/stdarch/crates/core_arch/src
/Users/sontek/.asdf/installs/rust/1.61.0/share/doc/rust/html/src/std/up/up/backtrace/src
/Users/sontek/.asdf/installs/rust/1.61.0/share/doc/rust/html/src/std/up/up/portable-simd/crates/std_float/src

Here is all I got:

❯ ls -a
Permissions Size User   Date Modified Name
drwxr-xr-x     - sontek 26 Jun 21:47  .
drwxr-xr-x     - sontek 26 Jun 21:47  ..
.rw-r--r--   170 sontek 26 Jun 21:47  components
drwxr-xr-x     - sontek 26 Jun 21:47  etc
.rw-r--r--  115k sontek 26 Jun 21:47  install.log
.rw-r--r--  3.2k sontek 26 Jun 21:47  manifest-cargo
.rw-r--r--   353 sontek 26 Jun 21:47  manifest-clippy-preview
.rw-r--r--  1.2k sontek 26 Jun 21:47  manifest-llvm-tools-preview
.rw-r--r--   271 sontek 26 Jun 21:47  manifest-rls-preview
.rw-r--r--  3.2k sontek 26 Jun 21:47  manifest-rust-analysis-x86_64-apple-darwin
.rw-r--r--   315 sontek 26 Jun 21:47  manifest-rust-demangler-preview
.rw-r--r--    65 sontek 26 Jun 21:47  manifest-rust-docs
.rw-r--r--  3.6k sontek 26 Jun 21:47  manifest-rust-std-x86_64-apple-darwin
.rw-r--r--  2.1k sontek 26 Jun 21:47  manifest-rustc
.rw-r--r--   347 sontek 26 Jun 21:47  manifest-rustfmt-preview
.rw-r--r--     2 sontek 26 Jun 21:47  rust-installer-version
.rwxr-xr-x   28k sontek 26 Jun 21:47  uninstall.sh
drwxr-xr-x     - sontek 26 Jun 21:47  x86_64-apple-darwin
cjbottaro commented 1 year ago

Same as @sontek , I don't have a src dir in my asdf installed rustc --print sysroot.

This causes my VS Code extension rust-analyzer to spit out errors.

arturictus commented 1 year ago

Same as @sontek and @cjbottaro , No src in the installation. My VS Code extension rust-analyzer is not working either.

$ ls -a $(rustc --print sysroot)/lib/rustlib
total 188K
-rw-r--r-- 1 artur artur  170 jul 30 11:47 components
drwxr-xr-x 2 artur artur 4,0K jul 30 11:46 etc
-rw-r--r-- 1 artur artur 106K jul 30 11:47 install.log
-rw-r--r-- 1 artur artur 2,9K jul 30 11:47 manifest-cargo
-rw-r--r-- 1 artur artur  343 jul 30 11:47 manifest-clippy-preview
-rw-r--r-- 1 artur artur 1,4K jul 30 11:47 manifest-llvm-tools-preview
-rw-r--r-- 1 artur artur  263 jul 30 11:47 manifest-rls-preview
-rw-r--r-- 1 artur artur 3,3K jul 30 11:47 manifest-rust-analysis-x86_64-unknown-linux-gnu
-rw-r--r-- 1 artur artur 2,0K jul 30 11:46 manifest-rustc
-rw-r--r-- 1 artur artur  307 jul 30 11:47 manifest-rust-demangler-preview
-rw-r--r-- 1 artur artur  337 jul 30 11:47 manifest-rustfmt-preview
-rw-r--r-- 1 artur artur 3,8K jul 30 11:46 manifest-rust-std-x86_64-unknown-linux-gnu
-rw-r--r-- 1 artur artur    2 jul 30 11:46 rust-installer-version
-rwxr-xr-x 1 artur artur  28K jul 30 11:46 uninstall.sh
drwxr-xr-x 5 artur artur 4,0K jul 30 11:47 x86_64-unknown-linux-gnu
cjbottaro commented 1 year ago

I switched to https://github.com/code-lever/asdf-rust and it works perfectly.

Which is frustrating because "asdf-community" sounds more official.

kennyp commented 1 year ago

Something like this should work and put it in the same location as rustup:

pushd $(rustc --print sysroot)
mkdir -p lib/rustlib/src
wget https://github.com/rust-lang/rust/archive/refs/tags/$(basename $(pwd)).tar.gz -O lib/rustlib/src/archive.tar.gz
cd lib/rustlib/src
tar vxzf archive.tar.gz
rm -f archive.tar.gz
mv rust-* rust
popd

We should add this as a default or at the very lease a command for the plugin.

apatrida commented 1 year ago

After install, just add the component using rust-up.

rustup component add rust-src

now the source will be present in the toolchain.