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

"Can't find crate for rustc_*" when cross-compiling a crate with rustc_private on #3255

Closed
momvart opened this issue Mar 7, 2023 · 17 comments
Labels

Comments

@momvart
Copy link

momvart commented Mar 7, 2023

Problem

In our project, we are using rustc components. When building for a x86_64 target it's fine. However, when setting the target to i686-unknown-linux-gnu, cargo (rustc) starts complaining about components not existing.

I think this is a problem due to components installation through rustup. It doesn't look to be installing them for the specified target.

The initial install is done through the following command.

$> rustup toolchain install nightly-2023-01-26 --target i686-unknown-linux-gnu --component rust-src rustc-dev llvm-tools-preview 
info: syncing channel updates for 'nightly-2023-01-26-x86_64-unknown-linux-gnu'
info: latest update on 2023-01-26, rust version 1.69.0-nightly (c18a5e8a5 2023-01-25)
info: downloading component 'cargo'
info: downloading component 'clippy'
info: downloading component 'llvm-tools'
info: downloading component 'rust-docs'
info: downloading component 'rust-src'
info: downloading component 'rust-std' for 'i686-unknown-linux-gnu'
info: downloading component 'rust-std'
info: downloading component 'rustc'
 68.3 MiB /  68.3 MiB (100 %)  45.8 MiB/s in  1s ETA:  0s
info: downloading component 'rustc-dev'
111.1 MiB / 111.1 MiB (100 %)  44.5 MiB/s in  2s ETA:  0s
info: downloading component 'rustfmt'
info: installing component 'cargo'
info: installing component 'clippy'
info: installing component 'llvm-tools'
 32.8 MiB /  32.8 MiB (100 %)  23.6 MiB/s in  1s ETA:  0s
info: installing component 'rust-docs'
 19.4 MiB /  19.4 MiB (100 %)  17.7 MiB/s in  1s ETA:  0s
info: installing component 'rust-src'
info: installing component 'rust-std' for 'i686-unknown-linux-gnu'
 28.1 MiB /  28.1 MiB (100 %)  20.7 MiB/s in  1s ETA:  0s
info: installing component 'rust-std'
 30.1 MiB /  30.1 MiB (100 %)  20.5 MiB/s in  1s ETA:  0s
info: installing component 'rustc'
 68.3 MiB /  68.3 MiB (100 %)  23.2 MiB/s in  2s ETA:  0s
info: installing component 'rustc-dev'
111.1 MiB / 111.1 MiB (100 %)  21.6 MiB/s in  5s ETA:  0s
info: installing component 'rustfmt'

  nightly-2023-01-26-x86_64-unknown-linux-gnu installed - rustc 1.69.0-nightly (c18a5e8a5 2023-01-25)

However, during building rustup complaints as follows.

$> cargo build --target=i686-unknown-linux-gnu
...
error[E0463]: can't find crate for `rustc_middle`
  --> compiler/src/lib.rs:19:1
   |
19 | extern crate rustc_middle;
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^ can't find crate
   |
   = help: maybe you need to install the missing components with: `rustup component add rust-src rustc-dev llvm-tools-preview`

Trying to install components again raises a conflict issue.

$> rustup component add --target i686-unknown-linux-gnu rust-src rustc-dev llvm-tools-preview  
info: component 'rust-src' is up to date
info: downloading component 'rustc-dev' for 'i686-unknown-linux-gnu'
info: installing component 'rustc-dev' for 'i686-unknown-linux-gnu'
128.4 MiB / 128.4 MiB (100 %)  21.6 MiB/s in  5s ETA:  0s
info: rolling back changes
error: failed to install component: 'rustc-dev-i686-unknown-linux-gnu', detected conflict: 'lib/rustlib/rustc-src/rust/Cargo.lock'

Originally, we are using rust-toolchain.toml to define the components and targets. In both cases, these issues exist. Also tried installing it side by side the x86_64 target and the same issue exists.

Steps

  1. Create a project using rustc components.
  2. Create a rust-toolchain.toml to override the toolchain and define components and targets as follows.
[toolchain]
channel = "nightly-2023-01-26"
components = ["rust-src", "rustc-dev", "llvm-tools-preview"]
targets = ["i686-unknown-linux-gnu"]
  1. Build using cargo build --target=i686-unknown-linux-gnu.

Possible Solution(s)

No response

Notes

No response

Rustup version

rustup 1.25.2 (17db695f1 2023-02-01)

Installed toolchains

Default host: x86_64-unknown-linux-gnu
rustup home:  ...

installed toolchains
--------------------

stable-x86_64-unknown-linux-gnu
nightly-2023-01-26-x86_64-unknown-linux-gnu
nightly-x86_64-unknown-linux-gnu (default)

installed targets for active toolchain
--------------------------------------

i686-unknown-linux-gnu
x86_64-unknown-linux-gnu

active toolchain
----------------

nightly-2023-01-26-x86_64-unknown-linux-gnu (overridden by '.../rust-toolchain.toml')
rustc 1.69.0-nightly (c18a5e8a5 2023-01-25)
@momvart momvart added the bug label Mar 7, 2023
@rbtcollins
Copy link
Contributor

What does rustup component list --installed output? And rustup target list --installed ?

Then, the contents of each of ~/.rustup/toolchains/*/lib/rustlib/components

@momvart
Copy link
Author

momvart commented Mar 7, 2023

What does rustup component list --installed output?

$>  rustup component list --installed
cargo-x86_64-unknown-linux-gnu
clippy-x86_64-unknown-linux-gnu
llvm-tools-x86_64-unknown-linux-gnu
rust-docs-x86_64-unknown-linux-gnu
rust-src
rust-std-i686-unknown-linux-gnu
rust-std-x86_64-unknown-linux-gnu
rustc-x86_64-unknown-linux-gnu
rustc-dev-x86_64-unknown-linux-gnu
rustfmt-x86_64-unknown-linux-gnu

And rustup target list --installed ?

$> rustup target list --installed
i686-unknown-linux-gnu
x86_64-unknown-linux-gnu

Then, the contents of each of ~/.rustup/toolchains/*/lib/rustlib/components

Sorry. I didn't get this one. Do you want the manifest files contents?

@rbtcollins
Copy link
Contributor

Rustup writes to the file called components matching that glob.

@momvart
Copy link
Author

momvart commented Mar 8, 2023

Rustup writes to the file called components matching that glob.

Yeah but I didn't get the each part. Anyways, this is the components file content.

~/.rustup/toolchains/nightly-2023-01-26-x86_64-unknown-linux-gnu/lib/rustlib$ cat components 
cargo-x86_64-unknown-linux-gnu
clippy-preview-x86_64-unknown-linux-gnu
llvm-tools-preview-x86_64-unknown-linux-gnu
rust-docs-x86_64-unknown-linux-gnu
rust-src
rust-std-x86_64-unknown-linux-gnu
rustc-x86_64-unknown-linux-gnu
rustc-dev-x86_64-unknown-linux-gnu
rustfmt-preview-x86_64-unknown-linux-gnu
rust-std-i686-unknown-linux-gnu

@Stroopwafe1
Copy link

I also had this issue where trying to cross-compile to i686-unknown-linux-gnu failed to find the std and core crates. Even though I used the rustup target add ... command. Turns out that after switching to the stable channel, and adding it again it now works.

Somehow using nightly messes up cross-compilation

sixfold-origami added a commit to TheBevyFlock/bevy_cli that referenced this issue Sep 2, 2024
…c components (#28)

I got bit by this when trying to build the CLI for the first time.
Apparently, there's [a
bug](rust-lang/rustup#3255) in `rustup` that
causes components to not be installed when nightly is selected.
Fortunately, installing them manually works just fine, so I added
instructions for it to the README.
@tombh
Copy link

tombh commented Oct 16, 2024

I'm seeing this issue too, but can't find a workaround. Neither manually adding components nor switching to stable, re-adding and switching to nightly, seem to help.

I actually have a public repo that can be used to reproduce this, here's a permalink to a failing Github Action workflow: https://github.com/tombh/rust-gpu-cli/blob/4a2492a95759cf103f4c2f3f9e51a1c7d0866b06/.github/workflows/release.yml#L45 And a failing workflow run's logs: https://github.com/tombh/rust-gpu-cli/actions/runs/11373072910/job/31638834293#step:5:373

@rami3l
Copy link
Member

rami3l commented Oct 17, 2024

I'm seeing this issue too, but can't find a workaround. Neither manually adding components nor switching to stable, re-adding and switching to nightly, seem to help.

I actually have a public repo that can be used to reproduce this, here's a permalink to a failing Github Action workflow: https://github.com/tombh/rust-gpu-cli/blob/4a2492a95759cf103f4c2f3f9e51a1c7d0866b06/.github/workflows/release.yml#L45 And a failing workflow run's logs: https://github.com/tombh/rust-gpu-cli/actions/runs/11373072910/job/31638834293#step:5:373

@tombh Thanks for the ping! However, It looks like you're not describing a toolchain corruption (the symbolic "failed to install component" message is missing from your log), but another scenario which is related to RustGPU usage specifically.

I've found EmbarkStudios/kajiya#78 which looks similar, but I'm not completely sure what has caused the issue for you, especially since you're cross-compiling for another target... Is there any prior art in building RustGPU with cross?

PS: You have a typo in your script, it's --target aarch64-unknown-linux-gnu, not aarch63.

@tombh
Copy link

tombh commented Oct 17, 2024

Thanks for looking into this!

So if I'm understanding the original bug report the issue arises before, and indeed can be reproduced without, the failed to install component error. Copying from the parent comment, this is the error that both @momvart and I are seeing:

$> cargo build --target=i686-unknown-linux-gnu
...
error[E0463]: can't find crate for `rustc_middle`
  --> compiler/src/lib.rs:19:1
   |
19 | extern crate rustc_middle;
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^ can't find crate
   |
   = help: maybe you need to install the missing components with: `rustup component add rust-src rustc-dev llvm-tools-preview`

In other words, this is how I believe the error can be stated: there appears to be no way in which rust-src can be installed such that cross-compilation works on nightly Rust.

I agree that the subsequent error (ie failed to install component) is both an understandable next step (heeding the advice of the hint) and a reasonable response from rustup (either there is a further double-install bug, or there is a conflict with rust-toolchain.toml). But this is not the error in question.

https://github.com/Rust-GPU/rust-gpu is the original, underlying repo. The thing to note is that the core of the project is a custom codegen backend, which is what necessitates the rust-src, rustc-dev, llvm-tools components. And because it's still in beta, they've never tried to release any packages, and so have never ventured into cross-compiling.

Ah yes, that was a typo in aarch63, but it was just a debugging line. I removed it and still get the same error: https://github.com/tombh/rust-gpu-cli/actions/runs/11386877927/job/31680155871#step:5:373

@rami3l
Copy link
Member

rami3l commented Oct 18, 2024

@tombh Thanks for your reply. Now that I think about it, it's less likely an issue specific to RustGPU, but common to nightly + rustc_private + cross compilation. I'm still not sure what has caused it: I mean, is it the component, the distribution, Rustup itself, or some sort of config / extern state?

Anyway, I'll find some time to do more investigation.

Possibly related: os-checker/MIRAI#3

@rami3l rami3l changed the title Components not getting installed correctly for a target error[E0463]: can't find crate for rustc_*` when cross-compiling a crate with rustc_private` on Oct 18, 2024
@rami3l rami3l changed the title error[E0463]: can't find crate for rustc_*` when cross-compiling a crate with rustc_private` on `error[E0463]: can't find crate for rustc_*`` when cross-compiling a crate with rustc_private` on Oct 18, 2024
@rami3l rami3l changed the title `error[E0463]: can't find crate for rustc_*`` when cross-compiling a crate with rustc_private` on ` error[E0463]: can't find crate for rustc_* when cross-compiling a crate with rustc_private` on Oct 18, 2024
@rami3l rami3l changed the title ` error[E0463]: can't find crate for rustc_* when cross-compiling a crate with rustc_private` on "Can't find crate for rustc_*" when cross-compiling a crate with rustc_private on Oct 18, 2024
@rami3l
Copy link
Member

rami3l commented Oct 18, 2024

@tombh I just tried locally to add rustc-dev to a new target, and it failed without any concurrency, so my previous categorization might turn out to be incorrect.

OTOH I do believe there is something wrong in the way rustc-dev is managed currently that may lead to a real conflict.

Also, to add to the context, it is useful to note that maybe you need to install the missing components with is not a hint message from rustup, but rather rustc. I think they are just making a best-effort guess (maybe the current distribution of rustc-dev has failed to uphold some sort of contract with rustc in the case of cross-compilation), which in this case unfortunately didn't help too much.

This might require some effort on the release side, esp. regarding how rustc-dev components should be located and found in rustc. I've updated the title of this issue accordingly.

@tombh
Copy link

tombh commented Oct 22, 2024

Thanks for the update. Would it be useful to make a minimal reproducible repo? And can you think of any avenues for workarounds worth exploring?

@rami3l
Copy link
Member

rami3l commented Oct 22, 2024

Thanks for the update. Would it be useful to make a minimal reproducible repo?

@tombh I think a minimal repro would be very useful indeed.

And can you think of any avenues for workarounds worth exploring?

... it really has to do with the way rustc and/or cargo look for the component in question. Once that has been figured out, maybe we can fake the installation manually.

Similar to #3717 (which is also related to incorrect packaging of component(s)), opening a new issue at https://github.com/rust-lang/rust might be helpful, as the actual packaging happens there IIRC.

@tombh
Copy link

tombh commented Oct 22, 2024

Thanks, great, so here's the minimal reproducible repo: https://github.com/tombh/nightly_cross_minimal_repro

Pasting main.rs:

#![feature(rustc_private)]

extern crate rustc_ast;
extern crate rustc_driver;
extern crate rustc_macros;

fn main() {
    println!("{}", rustc_ast::node_id::CRATE_NODE_ID)
}

The build commands are here: https://github.com/tombh/nightly_cross_minimal_repro/blob/main/.github/workflows/ci.yml

Pasting the most relevant part:

rustup toolchain install nightly-2024-09-30
rustup default nightly-2023-09-30
rustup target add aarch64-unknown-linux-gnu
rustup component add rust-src rustc-dev-aarch64-unknown-linux-gnu llvm-tools
...
cargo -v build --locked --release --target aarch64-unknown-linux-gnu

And here is the failing build: https://github.com/tombh/nightly_cross_minimal_repro/actions/runs/11463471346/job/31897390824#step:5:9

Also, just out of interest, here is a failing build with yesterday's nightly (nightly-2024-10-21), it fails differently, it can't find derive_where: https://github.com/tombh/nightly_cross_minimal_repro/actions/runs/11463505291/job/31897508604#step:5:9

I can also reproduce the build errors locally on my aarch64 machine using: cargo build --release --target x86_64-unknown-linux-gnu.

If you or anybody else can also reproduce this then I'll report it on https://github.com/rust-lang/rust too.

@weihanglo
Copy link
Member

This doesn't look like a rustup issue, might be rust or Cargo's. Any change you know which specific version of nightly toolchain starts having this failure?

@rami3l
Copy link
Member

rami3l commented Oct 23, 2024

This doesn't look like a rustup issue, might be rust or Cargo's. Any change you know which specific version of nightly toolchain starts having this failure?

@weihanglo I guess the problem is there since forever, it's just that few have tried to use rustc_private with cross builds. As I said, the current packaging of rustc-dev seems incompatible with this scenario...

I've tried to find something similar in rust-lang/rust but I'm not quite there yet. Possibly related:

@tombh Thanks for your minimal reproduction. I can reliably reproduce this on my ARM64 Mac with the following error message:

error[E0463]: can't find crate for `derive_where` which `rustc_ast` depends on
 --> src/main.rs:3:1
  |
3 | extern crate rustc_ast;
  | ^^^^^^^^^^^^^^^^^^^^^^^ can't find crate

error[E0463]: can't find crate for `rustc_ast`
 --> src/main.rs:4:1
  |
4 | extern crate rustc_driver;
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^ can't find crate
  |
  = help: maybe you need to install the missing components with: `rustup component add rust-src rustc-dev llvm-tools-preview`

error[E0463]: can't find crate for `rustc_macros`
 --> src/main.rs:5:1
  |
5 | extern crate rustc_macros;
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^ can't find crate
  |
  = help: maybe you need to install the missing components with: `rustup component add rust-src rustc-dev llvm-tools-preview`

It'd definitely be nice if a follow-up to rust-lang/rust#70838 can be filed. If it's not a valid use case to cross compile with rustc-dev, I think the release team should simply ban it from appearing on the server.

@tombh
Copy link

tombh commented Nov 7, 2024

Thanks for testing it out. I made an issue in the main Rust repo: rust-lang/rust#132728

@rami3l
Copy link
Member

rami3l commented Nov 8, 2024

It'd definitely be nice if a follow-up to rust-lang/rust#70838 can be filed. If it's not a valid use case to cross compile with rustc-dev, I think the release team should simply ban it from appearing on the server.
#3255 (comment)

Yeah, I think it would make sense to omit rustc-dev-aarch64-unknown-linux-gnu from the rustup manifest for hosts other than aarch64-unknown-linux-gnu.
rust-lang/rust#132728 (comment)

Following the previous comments, I'm going to close this issue in favor of rust-lang/rust#132728, as this indeed looks more like a release-related problem.

@rami3l rami3l closed this as not planned Won't fix, can't repro, duplicate, stale Nov 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

6 participants