How to provide standard library sources for IntelliJ IDEA's Rust project?
Asked Answered
I

8

40

I am using Mac for development. I installed Rust 1.13.0 using brew install rust and the Rust plugin 0.1.0.1385 for IntelliJ IDEA. I created my first test project with cargo and while opening it with IDEA I got the message

No standard library sources found, some code insight will not work

I haven't found any sources installed, nor the Rust sources package in Homebrew.

How do I provide sources for the project and what are the practical implication if I ignore this step?

Isomerous answered 4/1, 2017 at 12:39 Comment(2)
I would recommend using rustup, it downloads the correct sources, updates them together with the compiler tools and allows version switching. rustup.rs Without sources, IDEA will not know about any std types or values, which basically makes code completion completely useless.Marmara
I had the same question on in linux because I used asdf-vm to install rust - github.com/asdf-community/asdf-rust/issues/18Impressible
M
48

As commented, the supported approach is to use rustup:

  • Navigate to https://rustup.rs/ and follow the installation instructions for your platform.
  • Add the rust-src component by running: rustup component add rust-src
  • Create a new Rust project in IntelliJ and choose your existing Rust project source. If the folder already contains previous IntelliJ project files, you may have to delete those first before it will let you proceed.
  • IntelliJ-Rust should automatically configure the standard library sources to point to the sources downloaded by rustup.
Mccutchen answered 4/1, 2017 at 21:14 Comment(2)
There appears to be a download button right in the IDE now: i.imgur.com/p0Q7PZZ.pngItinerate
@mpen: unfortunately, this link is not available any more in IDEA 20.1.3.Medardas
C
15

As a reference, since the question title is broad, for Fedora 28 I had to:

dnf install cargo rust-src
sudo ln -s /usr/lib/rustlib/src /usr/lib/rustlib/x86_64-unknown-linux-gnu/

then give /usr/lib/rustlib/x86_64-unknown-linux-gnu/src/rust/src as "Standard library"

Full setup: enter image description here

Issue opened to simplify the process

Cadmann answered 23/3, 2018 at 15:20 Comment(2)
who do you need to use a symlink here? it works fine for me without the symlink by just selecting /usr/lib/rustlib/src/rust/src in intellijAndrogyne
@Androgyne see the Issue link. It is (was?) a bug.Cadmann
T
6

I know the question is for MacOS but this answer is shown up when searching for it on Linux. Below I will answer for Ubuntu.

The path is /usr/lib/rustlib/src/rust/src for Ubuntu 20.04


The way I did is:

  • Installed rustc from the repositories, which includes cargo
sudo apt install rustc
  • Then installed rust source package
sudo apt install rust-src
  • I used apt-file (can be installed with sudo apt install apt-file) to search for the install path of the sources
sudo apt-file update
apt-file list rust-src

This show the path as /usr/src/rustc-1.41.0/src .

But a ls -la in /usr/lib/rustlib/ will reveal symlinks and /usr/lib/rustlib/src/rust/src points to the previous found directory.

Using the symlink on IntelliJ will survive new rust versions.

Toiletry answered 21/7, 2020 at 1:24 Comment(2)
Thanks mate. been fussing with this all day. ubuntu 20.04Fissile
/usr/lib/rustlib/src/rust/src worked for me on Debian 11.Gurgle
H
6

When not using the rustup installer, one can install the source package and direct the rust plugin to use those:

enter image description here

(Tested with CLion 2020.2.1, rust-1.46.0-x86_64-pc-windows-gnu.msi, rustc-1.46.0-src.tar.gz. Offline Rust installers and source archive from there: https://forge.rust-lang.org/infra/other-installation-methods.html )

Hairball answered 17/9, 2020 at 9:0 Comment(0)
A
5

Although the preferred way of installing Rust is by using rustup, as pointed out by the other posts, it is not uncommon to use the packages that your distro makes available.

I use, for example, the packages provided by Gentoo and I share the same problem about the not prefilled field for standard libraries. Nevertheless, you can easily find out where your standard libraries have been installed by typing the following find command:

find /usr/lib* -type d -name "rust" | grep src

or the following if you installed rust in your home

find  -type d -name "rust" | grep src

The previous commands will help, unless, of course, in your distro there is a package for the binaries and one for the source and you only installed the binary one.

Aeriel answered 5/2, 2019 at 20:12 Comment(3)
I'm also using Gentoo. Having installed: [I] dev-lang/rust 1.32 (-clippy -debug -doc -libressl -rls -rustfmt -system-llvm -wasm) I cannot seem to find the standard libraries anywhere... Any ideas why they are missing here?Lissner
@opncow, I had the same trouble, found the answer here: https://mcmap.net/q/412743/-in-intellij-idea-on-gentoo-how-do-i-attach-the-rust-stdlib-sources-since-gentoo-does-not-use-rustup - Use the "rls" useflag for rust to have sources installed.Hangout
Thanks you @ScottTiger! Completely missed this useflag.Lissner
G
4

For Fedora 32 install Rust using command:

dnf install cargo rust-src

and the path to standard libary source is:

/usr/lib/rustlib/src/rust
Gluten answered 1/8, 2020 at 20:16 Comment(0)
F
3

I used Ubuntu. I follow these steps:

  1. sudo apt install rust-src
    wait for the install, then
  2. dpkg -L rust-src
    copy the last line. For me it is the standard library path:

/usr/lib/rustlib/src/rust

Fawne answered 11/10, 2021 at 7:6 Comment(0)
C
2

For MacOS, you need to put /opt/homebrew/bin/.

Cellobiose answered 11/1, 2023 at 12:46 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.