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

Rustup can't find crate "std" #25863

Closed
mythmon opened this issue May 17, 2017 · 27 comments
Closed

Rustup can't find crate "std" #25863

mythmon opened this issue May 17, 2017 · 27 comments

Comments

@mythmon
Copy link
Contributor

mythmon commented May 17, 2017

Issue description

After installing rust via rustup (installed via nix-shell or nix-env), trying to build even a simple hello world rust program results in error[E0463]: can't find crate for 'std'

I performed these tests on nixpkgs commit 6d599b7, which is the latest commit as I am writing this.

Steps to reproduce

[mythmon@gallium:~]$ nix-shell --pure -p rustup
[nix-shell:~]$ BASE=/tmp/rustup-test-$$
[nix-shell:~]$ export RUSTUP_HOME=$BASE
[nix-shell:~]$ export CARGO_HOME=$BASE
[nix-shell:~]$ mkdir $BASE
[nix-shell:~]$ cd $BASE
[nix-shell:/tmp/rustup-test-9987]$ rustup toolchain list
[nix-shell:/tmp/rustup-test-9987]$ rustup toolchain install stable
info: syncing channel updates for 'stable-x86_64-unknown-linux-gnu'
info: downloading component 'rustc'
info: downloading component 'rust-std'
info: downloading component 'cargo'
info: downloading component 'rust-docs'
info: installing component 'rustc'
info: installing component 'rust-std'
info: installing component 'cargo'
info: installing component 'rust-docs'

  stable-x86_64-unknown-linux-gnu installed - rustc 1.17.0 (56124baa9 2017-04-24)
[nix-shell:/tmp/rustup-test-9987/test_project]$ rustup toolchain list
stable-x86_64-unknown-linux-gnu (default)
[nix-shell:/tmp/rustup-test-9987]$ rustup default stable
info: using existing install for 'stable-x86_64-unknown-linux-gnu'
info: default toolchain set to 'stable-x86_64-unknown-linux-gnu'

  stable-x86_64-unknown-linux-gnu unchanged - rustc 1.17.0 (56124baa9 2017-04-24)
[nix-shell:/tmp/rustup-test-9987]$ cargo new --bin test_project
     Created binary (application) `test_project` project
[nix-shell:/tmp/rustup-test-9987]$ cd test_project
[nix-shell:/tmp/rustup-test-9987/test_project]$ cargo run
   Compiling test_project v0.1.0 (file:///tmp/rustup-test-9987/test_project)
error[E0463]: can't find crate for `std`

error: aborting due to previous error

error: Could not compile `test_project`.

To learn more, run the command again with --verbose.

Technical details

  • System: 17.09pre106916.c5badb123a (Hummingbird)
  • Nix version: nix-env (Nix) 1.11.9
  • Nixpkgs version: "17.09pre106916.c5badb123a"
  • Sandboxing enabled: build-use-sandbox = false
@flosse
Copy link
Contributor

flosse commented May 18, 2017

I can agree to this problem (using 17.09pre106299.7f3b857d0d (Hummingbird))

@Mic92
Copy link
Member

Mic92 commented May 18, 2017

Yeah, unfortunately it is still broken. So what I did to run the unmodified toolchain, was to patch rustup to always to pass the executable as first argument to ld-linux-x86-64.so.2 to avoid the use of patchelf. This worked well, however rust internally uses /proc/self/exe to find where its toolchain lives. Usually this works as rustc is the target of the /proc/self/exe symlink. However in our case it is the link loader ld-linux-x86-64.so.2 outside of ~/.rustup. This is why everything breaks horrible. A hack around it, would be to copy ld-linux-x86-64.so.2 to ~/.rustup/toolchains/<toolchain>/bin.

I probably will mark this as broken or remove it again from nixpkgs, so other people will not waste their time and use the other options to install rust.

@retrry
Copy link
Contributor

retrry commented May 19, 2017

What I do in my project. I've added this line to my default.nix shellHook:

export RUSTFLAGS="-L $HOME/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/"

I don't really like this hardcoded way, but I at least I can use rustup.

@retrry
Copy link
Contributor

retrry commented May 19, 2017

Also @Mic92 please don't remove it, or at least leave some way of installing it :) For me it is way easier to use rustup for nightly compiler, even with this workaround (my project requires nightly).

@Mic92
Copy link
Member

Mic92 commented May 19, 2017

oh, good idea. This would be a less uglier workaround, which could be integrate into rustup.

@bkchr
Copy link
Contributor

bkchr commented May 26, 2017

For rust and Nixos I would propose to use the rust-overlay https://github.com/mozilla/nixpkgs-mozilla
Then you don't have to play any environment variable tricks :)

@Mic92
Copy link
Member

Mic92 commented May 29, 2017

it does not address cross-compilers if I remember correctly.

@retrry
Copy link
Contributor

retrry commented May 29, 2017

@Mic92 I wasn't able to get cross compiling working. I've tried to compile musl target.

@Mic92
Copy link
Member

Mic92 commented May 29, 2017

I meant nixpkgs-mozilla.

@bkchr
Copy link
Contributor

bkchr commented May 29, 2017

I have a pull request open for cross compilation support(mozilla/nixpkgs-mozilla#24).

@joepie91
Copy link
Contributor

For anybody who has ended up here while trying to figure out how to get Xargo working; you'll want to have a look at mozilla/nixpkgs-mozilla#51, which includes a workaround.

@unode
Copy link
Member

unode commented Jan 14, 2018

Any progress here?

I'm currently getting two rustup related issues. The one discussed in this thread and rust-lang/rustup#1062 which seems to be fixed in newer versions of rustup.

To note, the latest version of rustup at the time of writing is 1.9.0. Nixpkgs has 1.3.0.

@bkchr
Copy link
Contributor

bkchr commented Jan 15, 2018

Did you tried the overlay? I'm using it for cross compilation.

@unode
Copy link
Member

unode commented Jan 15, 2018

Overlay works fine but no rustup there.

@bkchr
Copy link
Contributor

bkchr commented Jan 15, 2018

Why do you need rustup? Rustup defeats the purpose of Nixpkgs/NixOS(yeah I know, the overlay is also not standard compliant).

@unode
Copy link
Member

unode commented Jan 15, 2018

Convinence mostly. Being able to script around rustup and have it work on multiple platforms.

@bkchr
Copy link
Contributor

bkchr commented Jan 15, 2018

Yeah, that will be complicated on Nixos. The main problem is, that you would need to run patchelf manually on the downloaded toolchain.
I'm currently updating rustup and will send a pull request in the next hour, I hope that fixes some of your problems.

@retrry
Copy link
Contributor

retrry commented Jan 15, 2018

Are you talking about stable? Because on unstable rustup works correctly.

@unode
Copy link
Member

unode commented Jan 15, 2018

I'm talking about nixos-17.09, if that's what you refer by stable.

@Mic92
Copy link
Member

Mic92 commented Jan 15, 2018

If you could test if cbe326f works correctly on 17.09, I can back port this patch.

@ysndr
Copy link
Member

ysndr commented Feb 7, 2018

@Mic92 a quick test today seemed to work alright using the nixpkgs master branch. Can't tell about cross compiling though. Thanks for the effort

@Mic92
Copy link
Member

Mic92 commented Feb 8, 2018

backported in b1be17c

@vandenoever
Copy link
Contributor

@bkchr I'd like to experiment with rust for wasm and raspberry on nixos. What is currently best way of compiling for those targets?

@bkchr
Copy link
Contributor

bkchr commented Apr 18, 2018

I think you should use the Mozilla nix overlay.

(latest.rustChannels.nightly.rust.override { extensions = [ "rust-src" ]; targets = [ "wasm-unknown-linux-unknown" ];})

That should give you a rust with all the things you need :) (I'm unsure if the target name is correct, but it print a list of available targets if something is not correct)

@Mic92
Copy link
Member

Mic92 commented Apr 21, 2018

Rustup also worked for me when I compiled for the musl target. So both the overlay and rustup should be ok.

@Mic92
Copy link
Member

Mic92 commented Apr 21, 2018

I think this issue was solved.

@Mic92 Mic92 closed this as completed Apr 21, 2018
@alehander92
Copy link

alehander92 commented Feb 28, 2024

i know this is resolved, just if someone has a similar error these days for info: i had this problem when copying the rustc binary/link from my nix setup instead of linking to it: linking to it resolved it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

10 participants