-
Notifications
You must be signed in to change notification settings - Fork 13.1k
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
rust-src does not include workspace Cargo.toml #95736
Comments
A simple way to reproduce this is: $ cd ~/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/
$ cargo metadata --locked
warning: please specify `--format-version` flag explicitly to avoid compatibility problems
Updating crates.io index
error: the lock file ~/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/src/rust/library/std/Cargo.lock needs to be updated but --locked was passed to prevent this
If you want to try to generate the lock file without accessing the network, remove the --locked flag and use --offline instead. |
This also seems like a regression from #44076 |
The absolute best for the editors would be if Practically, this would allow us to not worry about "large" compiler codebase and only deal with the small set of library crates. Theoretically, it still feels to me that "compiler" and "library" actually exist in separate dimensions, and using a single Cargo.lock for them seems accidental. Obviously, that's "perfect is the enemy of the good" kind of thing, just restoring Cargo.toml/.lock would be helpful |
Another thing worth adding to this is that |
FWIW, the lock file is included because I needed it to make Miri more reliable, and then just added it. I think a PR to simply add Cargo.toml to the list of shipped files would probably go through in a similar vein. However, it is not clear to me whether you are saying the original Cargo.toml should be shipped, or whether it should be somehow modified before shipping. The latter will be more tricky, of course -- is it even clear what the "right" way to adjust the toml file is? |
Oh, you actually linked to my old PR that added the Cargo.lock file. 😂 Looks like it originally intended to also add Cargo.toml but that part got bailed out before landing. This is where I had to remove the Cargo.toml because it caused trouble with distcheck that I didn't have the patience to debug.
FWIW, those crates existing on crates.io is quite deliberate and a key part to their function. |
Cross-posting (potentially relevant) #78790 (comment) (note that that PR was reverted):
|
I think we should just split the sysroot into a new workspace and use it as part of bootstrapping instead of generating a new workspace in the dist step. That may also simplify the tidy license check by not requiring to check if a crate is a dependency of the sysroot to apply stricter license checks. Instead it can apply them to the entire contents of |
One more observation: this problem is exacerbated by the fact that when an editor runs |
Omit stdarch workspace from rust-src The path `library/stdarch/crates/Cargo.toml` does not exist. In Rust 1.61.0, `rust-src` still includes `src/rust/library/stdarch/Cargo.toml` (but not `stdarch-verify`), which includes ```toml [workspace] members = [ "crates/stdarch-verify" ``` This didn't show up when testing with `-Zbuild-std` in rust-lang#94907 since the [standard list of crates](https://github.com/rust-lang/cargo/blob/f624095e1c98228a74a165ddb702078c0dd8b81e/src/cargo/core/compiler/standard_lib.rs#L26-L30) to include when building `std` does not include `stdarch`, but it will show up if a user explicitly requests `stdarch`. Or, perhaps more importantly, because of rust-lang#95736, many editors (like IntelliJ) won't treat the root of `rust-src` as a workspace, and will instead recurse into all the sub-crates directly, which then includes `stdarch`. Also related to rust-lang#94906.
This winds up extra fun under Nix using $RUST_SRC_PATH where the rust sources are literally on a readonly file system, which is the r-a issue here: rust-lang/rust-analyzer#13393 The correct fix for this issue is to add the lockfile and manifest to rust-src, I think, so cargo doesn't try to relock it. |
IMO it's a bug in |
I believe #128534 essentially fixes this? |
It does. I would have linked this issue from that PR if I had remembered this issue existed. |
The
rust-src
component that gets installed by Rustup to~/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust
includes aCargo.lock
that spans the standard library crates, but does not include a correspondingCargo.toml
(essentially thisCargo.toml
).Cargo's
-Zbuild-std
feature makes this work anyway by constructing a virtual workspace for the standard library, but this doesn't work for editors that want to provide users with completion and analysis all the way intostd
/alloc
/core
. They end up runningcargo metadata
directly in the various standard library crates (library/std
for example) (IntelliJ, rust-analyzer). However, since there's no workspace-levelCargo.toml
next to theCargo.lock
, they do not pick up on the locked versions at all, and instead use whatever the latest versions of the standard library's dependencies are. This in turn means that go-to-definition and similar mechanisms do not go to the actual versions used by the standard library the user is actually using.In chatting to @Mark-Simulacrum about this, I think the editors are arguably doing the right thing here by running
cargo metadata
inside the individual crates (like std), and Cargo is doing the right thing not looking at theCargo.lock
since there isn't a workspace there. And it feels like the right thing to do is to synthesize a workspaceCargo.toml
for inclusion withrust-src
. But if we explicitly won't (or can't) include aCargo.toml
inrust-src
's root, we have a couple of options:cargo metadata
could have something like--with-lockfile Cargo.lock
so that you can run it in arbitrary places on disk while pointing to (for example) a checked out repositoriesCargo.lock
.Cargo.lock
as some kind of special dep kind.cargo metadata --include-std
.All of these feel brittle to one extent or another though, and it's not clear that they are sufficient for what editors may need (cc @matklad), so I think we should push for including
Cargo.toml
if we can.Meta
rustc --version --verbose
:The text was updated successfully, but these errors were encountered: