Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot set rustcSource to rustc-dev rustup package #7589

Closed
RalfJung opened this issue Feb 7, 2021 · 12 comments
Closed

Cannot set rustcSource to rustc-dev rustup package #7589

RalfJung opened this issue Feb 7, 2021 · 12 comments
Labels
C-support Category: support questions

Comments

@RalfJung
Copy link
Member

RalfJung commented Feb 7, 2021

In an attempt to get rust-analyzer to work better for working on Miri (which imports rustc-private crates), I tried setting rust-analyzer.rustcSource to /home/r/.rustup/toolchains/miri/lib/rustlib/rustc-src/rust/compiler/, where the rustc-dev rustup package puts the sources. However, that does not work -- I am getting an error saying "the manifest path must be a path to a Cargo.toml file".

Is there any way to make rust-analyzer use the sources included in the rustc-dev package?

@bjorn3
Copy link
Member

bjorn3 commented Feb 7, 2021

I think you need to point to /home/r/.rustup/toolchains/miri/lib/rustlib/rustc-src/rust/Cargo.toml.

@RalfJung
Copy link
Member Author

RalfJung commented Feb 7, 2021

But in that directory there's only the lib source, not the compiler source.

@RalfJung
Copy link
Member Author

RalfJung commented Feb 7, 2021

There's no such file:

$ ls /home/r/.rustup/toolchains/miri/lib/rustlib/rustc-src/rust/
Cargo.lock  compiler

@bjorn3
Copy link
Member

bjorn3 commented Feb 7, 2021

Maybe try the Cargo.toml of rustc_driver?

@flodiebold
Copy link
Member

I would assume you need an actual checkout of rustc.

@RalfJung
Copy link
Member Author

RalfJung commented Feb 7, 2021

I would assume you need an actual checkout of rustc.

That would be rather unpractical -- the crates it is linking against are installed via rustup, so to make sure the source matches, that should also be taken from rustup.

The rustc-dev package can probably be extended with some more files if that helps.

@RalfJung
Copy link
Member Author

RalfJung commented Feb 7, 2021

Maybe try the Cargo.toml of rustc_driver?

No that does not work either:

rust-analyzer failed to load workspace: Failed to read Cargo metadata for Rust sources: Failed to run `cargo metadata --manifest-path /home/r/.rustup/toolchains/miri/lib/rustlib/rustc-src/rust/compiler/rustc_driver/Cargo.toml` in `/home/r/.rustup/toolchains/miri/lib/rustlib/rustc-src/rust/compiler/rustc_driver`: `cargo metadata` exited with an error:     Updating crates.io index
error: failed to get `build_helper` as a dependency of package `rustc_llvm v0.0.0 (/home/r/.rustup/toolchains/miri/lib/rustlib/rustc-src/rust/compiler/rustc_llvm)`
    ... which is depended on by `rustc_codegen_llvm v0.0.0 (/home/r/.rustup/toolchains/miri/lib/rustlib/rustc-src/rust/compiler/rustc_codegen_llvm)`
    ... which is depended on by `rustc_interface v0.0.0 (/home/r/.rustup/toolchains/miri/lib/rustlib/rustc-src/rust/compiler/rustc_interface)`
    ... which is depended on by `rustc_driver v0.0.0 (/home/r/.rustup/toolchains/miri/lib/rustlib/rustc-src/rust/compiler/rustc_driver)`

Caused by:
  failed to load source for dependency `build_helper`

Caused by:
  Unable to update /home/r/.rustup/toolchains/miri/lib/rustlib/rustc-src/rust/src/build_helper

Caused by:
  failed to read `/home/r/.rustup/toolchains/miri/lib/rustlib/rustc-src/rust/src/build_helper/Cargo.toml`

Caused by:
  No such file or directory (os error 2)

@bnjbvr
Copy link
Contributor

bnjbvr commented Feb 11, 2021

I've found what the root cause of this particular issue is: the src/build_helper directory is missing from the distributed sources. If you manualloy copy it from the Rustc src to ~/.rustup/toolchains/{toolchain}/lib/rustlib/rustc-src/rust/src/build_helper, it works just fine! I'll open a PR for adding this directory when distributing rustc.

bnjbvr added a commit to bnjbvr/rust that referenced this issue Feb 11, 2021
Since it was missing, it wasn't possible to really use rustc-dev to
build, see for instance: rust-lang/rust-analyzer#7589.
JohnTitor added a commit to JohnTitor/rust that referenced this issue Feb 12, 2021
…=Mark-Simulacrum

dist: include src/build_helper as part of the crate graph for rustc-dev

The build_helper dependency is used to build the compiler/rustc_llvm build script.

Since it was missing, it wasn't possible to really use rustc-dev to
build, see for instance: rust-lang/rust-analyzer#7589.
JohnTitor added a commit to JohnTitor/rust that referenced this issue Feb 12, 2021
…=Mark-Simulacrum

dist: include src/build_helper as part of the crate graph for rustc-dev

The build_helper dependency is used to build the compiler/rustc_llvm build script.

Since it was missing, it wasn't possible to really use rustc-dev to
build, see for instance: rust-lang/rust-analyzer#7589.
@lnicola
Copy link
Member

lnicola commented Feb 20, 2021

@bnjbvr can this be closed now?

@RalfJung
Copy link
Member Author

With the latest rustc, pointing to /home/r/.rustup/toolchains/miri/lib/rustlib/rustc-src/rust/compiler/rustc_driver/Cargo.toml seems to do something -- I now get more auto-completion than before.

However, it seems rather strange that I would have to pick one of the many compiler crates. Why rustc_driver? At the very least, the docstring for rustcSource should explicitly say "set this to the Cargo.toml of rustc_driver", or so.

@Veykril Veykril added the C-support Category: support questions label May 27, 2022
@Veykril
Copy link
Member

Veykril commented Apr 7, 2024

Pointing it to <sysroot>/lib/rustlib/rustc-src/rust/compiler/rustc/Cargo.toml should work nowadays (that's what we try to lookup by default), so I believe this can be closed? (I'll close it, re-open if you think otherwise)

@Veykril Veykril closed this as completed Apr 7, 2024
@RalfJung
Copy link
Member Author

RalfJung commented Apr 8, 2024

We are setting "rust-analyzer.rustc.source": "discover" and that's working just fine for years now, so yeah this can be closed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-support Category: support questions
Projects
None yet
Development

No branches or pull requests

6 participants