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

[BUG] Rust toolchain linking broken - CARGO_HOME not set #1419

Closed
clotodex opened this issue Sep 6, 2024 · 10 comments
Closed

[BUG] Rust toolchain linking broken - CARGO_HOME not set #1419

clotodex opened this issue Sep 6, 2024 · 10 comments
Labels
bug Something isn't working

Comments

@clotodex
Copy link
Contributor

clotodex commented Sep 6, 2024

Describe the bug
All cargo subcommands are broken for me.
For example:

$ cargo sqlx prepare 
Could not start dynamically linked executable: /home/user/.cargo/bin/cargo-sqlx
NixOS cannot run dynamically linked executables intended for generic
linux environments out of the box. For more information, see:
https://nix.dev/permalink/stub-ld

This also goes for anything else, including rust analyzer, breaking most IDEs.

To reproduce

cargo new project
cd project
devenv init
# edit the devenv.nix to enable rust (does not matter how, fenix also does not work

Now run for example:
rust-analyzer analysis-stats .
And you will get:

Error: Failed to load the project at /tmp/project/./Cargo.toml

Caused by:
    0: Failed to query rust toolchain version at /tmp/project, is your toolchain setup correctly?
    1: cd "/tmp/nix-build-test" && RUSTUP_TOOLCHAIN="/nix/store/v00vzaszpvi6wrm213dgislmpr05gcfp-rustc-1.76.0" "/home/user/.cargo/bin/cargo" "--version" failed, exit status: 127
       stderr:
       Could not start dynamically linked executable: /home/user/.cargo/bin/cargo
       NixOS cannot run dynamically linked executables intended for generic
       linux environments out of the box. For more information, see:
       https://nix.dev/permalink/stub-ld

Version
devenv 1.0.8 (x86_64-linux)
Extra info
I am on NixOS, so nothing "local" is helping me resolve this. I can work around it (but not in IDEs) with using steam-run

@clotodex
Copy link
Contributor Author

clotodex commented Sep 6, 2024

This seems to be a devenv issue (i think).
When I use this repo: https://github.com/cpu/rust-flake, add sqlx-cli to the runtimeDeps and then run cargo sqlx prepare it works.
So something is going wrong in the devenv is my current assumption.

@clotodex
Copy link
Contributor Author

clotodex commented Sep 6, 2024

Also the local example https://github.com/cachix/devenv/tree/main/examples/rust does not work. Cd into there, run devenv shell and then run rust-analyzer analysis-stats . - same error

@clotodex
Copy link
Contributor Author

clotodex commented Sep 6, 2024

What is interesting though is that it is independent of the devenv.lock - so also old rust installs dont work anymore. Either this is something internal then or still correlated with NixOS, just in a weird way that only breaks devenv...

Happy for any support, willing to PR, but I dont know what is wrong yet.

@clotodex
Copy link
Contributor Author

bump... - this is breaking my setup fully. Can anyone reproduce this?

@serpent213
Copy link

I'm seeing this issue, might or might not be related:

==> phoenix_ecto
Compiling 7 files (.ex)
Generated phoenix_ecto app
   Compiling proc-macro2 v1.0.9
   Compiling unicode-xid v0.2.0
   Compiling syn v1.0.16
   Compiling libc v0.2.67
   Compiling slab v0.4.2
   Compiling memchr v2.3.3
error[E0463]: can't find crate for `std`
  |
  = note: the `x86_64-unknown-linux-musl` target may not be installed
  = help: consider downloading the target with `rustup target add x86_64-unknown-linux-musl`

error: cannot find macro `unreachable` in this scope
   --> /home/self/.cargo/registry/src/index.crates.io-6f17d22bba15001f/slab-0.4.2/src/lib.rs:895:18

Same build and devenv works fine on aarch64-darwin.

@clotodex
Copy link
Contributor Author

clotodex commented Oct 1, 2024

Hm not sure if this is the same issue. Depending on what you are doing this might also just be missing some cross-compilation setup (using fenix with the musl toolchain).
Testing devenv 1.2 it did not change anything and commands like cargo sqlx prepare are still broken

@serpent213
Copy link

I don't know much about Rust, but I'm not attempting a cross-compilation...

@clotodex
Copy link
Contributor Author

I finally gave it another debug and found the culprit.
CARGO_HOME is not set when using rust with devenv, no matter if fenix or vanilla. Maybe #1500 can/will change things.

@clotodex clotodex changed the title [BUG] Rust toolchain bricked - probably CARGO_INSTALL_ROOT not respected [BUG] Rust toolchain linking broken - CARGO_HOME not set Dec 23, 2024
@clotodex
Copy link
Contributor Author

The / directory of the cargo package does not allow .package-cache
This breaks rust-analyzer still.

@clotodex
Copy link
Contributor Author

nevermind.
Uff, this is my bad
Something actually installed a cargo into ~/.cargo/bin
This made all programs fall back to this and could not make any kind of setup work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants