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

Rust anaylzer fails to compile crates which build properly with cargo build #17615

Open
ethanniser opened this issue Jul 17, 2024 · 15 comments
Open
Labels
C-bug Category: bug

Comments

@ethanniser
Copy link

ethanniser commented Jul 17, 2024

rust-analyzer version: (eg. output of "rust-analyzer: Show RA Version" command, accessible in VSCode via Ctrl/⌘+Shift+P)

0.3.2037-standalone (e9afba5 2024-07-14)

rustc version: (eg. output of rustc -V)

rustc 1.79.0 (129f3b996 2024-06-10)

editor or extension: (eg. VSCode, Vim, Emacs, etc. For VSCode users, specify your extension version; for users of other editors, provide the distribution if applicable)

vscode

relevant settings: (eg. client settings, or environment variables like CARGO, RUSTC, RUSTUP_HOME or CARGO_HOME)

none

===

I am on macos
I have a barebones cargo init project just with the uncased crate added in cargo.toml (the issue is not specific to this crate, it happens with others too)

cargo build runs just fine

but rust analyzer is unable compile it

2024-07-17T06:09:38.121175Z ERROR rust_analyzer::main_loop: FetchBuildDataError:
error: could not exec the linker `rust-lld.exe`
  |
  = note: Not a directory (os error 20)
  = note: env -u IPHONEOS_DEPLOYMENT_TARGET -u TVOS_DEPLOYMENT_TARGET -u XROS_DEPLOYMENT_TARGET LC_ALL="C" PATH="/nix/store/mm3mkpsyrkam2832ry5b3l0vnkd5967j-rust-stable-2024-06-13/lib/rustlib/aarch64-apple-darwin/bin:/Users/ethan/.nix-profile/bin:/etc/profiles/per-user/ethan/bin:/run/current-system/sw/bin:/nix/var/nix/profiles/default/bin:/opt/homebrew/bin:/Users/ethan/.npm-global/bin:/usr/local/bin:/usr/bin:/usr/sbin:/bin:/sbin:/Users/ethan/.config/zsh/plugins/powerlevel10k:/Users/ethan/.config/zsh/plugins/powerlevel10k-config" VSLANG="1033" ZERO_AR_DATE="1" "rust-lld.exe" "-flavor" "darwin" "-arch" "arm64" "-platform_version" "macos" "11.0" "11.0" "/var/folders/yv/wd8ppgks5wg0150bjf1yrxyr0000gn/T/rustc8ViwwR/symbols.o" "/Users/ethan/src/personal/tmp/rust-test/target/rust-analyzer/debug/build/uncased-18387905a62a1cca/build_script_build-18387905a62a1cca.build_script_build.94d5a8eee99c4963-cgu.0.rcgu.o" "/Users/ethan/src/personal/tmp/rust-test/target/rust-analyzer/debug/build/uncased-18387905a62a1cca/build_script_build-18387905a62a1cca.2m0u35fh66bvisgy.rcgu.o" "-L" "/Users/ethan/src/personal/tmp/rust-test/target/rust-analyzer/debug/deps" "-L" "/nix/store/mm3mkpsyrkam2832ry5b3l0vnkd5967j-rust-stable-2024-06-13/lib/rustlib/aarch64-apple-darwin/lib" "/Users/ethan/src/personal/tmp/rust-test/target/rust-analyzer/debug/deps/libversion_check-f33dfa893f0af023.rlib" "/nix/store/0jm39pz8p7d9qic4kaawwawhb56vaw2k-rust-stable-2024-06-13/lib/rustlib/aarch64-apple-darwin/lib/libstd-7f95fd207255b41e.rlib" "/nix/store/0jm39pz8p7d9qic4kaawwawhb56vaw2k-rust-stable-2024-06-13/lib/rustlib/aarch64-apple-darwin/lib/libpanic_unwind-97393370543e3207.rlib" "/nix/store/0jm39pz8p7d9qic4kaawwawhb56vaw2k-rust-stable-2024-06-13/lib/rustlib/aarch64-apple-darwin/lib/libobject-a3d7c43b176960f9.rlib" "/nix/store/0jm39pz8p7d9qic4kaawwawhb56vaw2k-rust-stable-2024-06-13/lib/rustlib/aarch64-apple-darwin/lib/libmemchr-6371ee3a4bb27ae4.rlib" "/nix/store/0jm39pz8p7d9qic4kaawwawhb56vaw2k-rust-stable-2024-06-13/lib/rustlib/aarch64-apple-darwin/lib/libaddr2line-a7cf1a11761951bf.rlib" "/nix/store/0jm39pz8p7d9qic4kaawwawhb56vaw2k-rust-stable-2024-06-13/lib/rustlib/aarch64-apple-darwin/lib/libgimli-dad018a8d4ef8593.rlib" "/nix/store/0jm39pz8p7d9qic4kaawwawhb56vaw2k-rust-stable-2024-06-13/lib/rustlib/aarch64-apple-darwin/lib/librustc_demangle-913776ff724458d1.rlib" "/nix/store/0jm39pz8p7d9qic4kaawwawhb56vaw2k-rust-stable-2024-06-13/lib/rustlib/aarch64-apple-darwin/lib/libstd_detect-364b04ba0ead75b3.rlib" "/nix/store/0jm39pz8p7d9qic4kaawwawhb56vaw2k-rust-stable-2024-06-13/lib/rustlib/aarch64-apple-darwin/lib/libhashbrown-918cdfbdd32cf1d1.rlib" "/nix/store/0jm39pz8p7d9qic4kaawwawhb56vaw2k-rust-stable-2024-06-13/lib/rustlib/aarch64-apple-darwin/lib/librustc_std_workspace_alloc-424311e8ba1b9112.rlib" "/nix/store/0jm39pz8p7d9qic4kaawwawhb56vaw2k-rust-stable-2024-06-13/lib/rustlib/aarch64-apple-darwin/lib/libminiz_oxide-d4352744eff98311.rlib" "/nix/store/0jm39pz8p7d9qic4kaawwawhb56vaw2k-rust-stable-2024-06-13/lib/rustlib/aarch64-apple-darwin/lib/libadler-dd9df5b2170395b8.rlib" "/nix/store/0jm39pz8p7d9qic4kaawwawhb56vaw2k-rust-stable-2024-06-13/lib/rustlib/aarch64-apple-darwin/lib/libunwind-6b98b9caf95b8907.rlib" "/nix/store/0jm39pz8p7d9qic4kaawwawhb56vaw2k-rust-stable-2024-06-13/lib/rustlib/aarch64-apple-darwin/lib/libcfg_if-d4913584d9013c52.rlib" "/nix/store/0jm39pz8p7d9qic4kaawwawhb56vaw2k-rust-stable-2024-06-13/lib/rustlib/aarch64-apple-darwin/lib/liblibc-04f062133e43a7ac.rlib" "/nix/store/0jm39pz8p7d9qic4kaawwawhb56vaw2k-rust-stable-2024-06-13/lib/rustlib/aarch64-apple-darwin/lib/liballoc-5397ff6f88f2713a.rlib" "/nix/store/0jm39pz8p7d9qic4kaawwawhb56vaw2k-rust-stable-2024-06-13/lib/rustlib/aarch64-apple-darwin/lib/librustc_std_workspace_core-5142793ba4eb4c05.rlib" "/nix/store/0jm39pz8p7d9qic4kaawwawhb56vaw2k-rust-stable-2024-06-13/lib/rustlib/aarch64-apple-darwin/lib/libcore-24a1e099f55e6f0d.rlib" "/nix/store/0jm39pz8p7d9qic4kaawwawhb56vaw2k-rust-stable-2024-06-13/lib/rustlib/aarch64-apple-darwin/lib/libcompiler_builtins-9ca5cbf9e98b80b9.rlib" "-lSystem" "-lc" "-lm" "-syslibroot" "/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk" "-L" "/nix/store/mm3mkpsyrkam2832ry5b3l0vnkd5967j-rust-stable-2024-06-13/lib/rustlib/aarch64-apple-darwin/lib" "-o" "/Users/ethan/src/personal/tmp/rust-test/target/rust-analyzer/debug/build/uncased-18387905a62a1cca/build_script_build-18387905a62a1cca" "-dead_strip"


error: aborting due to 1 previous error


error: could not compile `uncased` (build script) due to 2 previous errors

Im a bit confused how rust-lld.exe would ever be called on macos
any help is appreciated thanks

@ethanniser ethanniser added the C-bug Category: bug label Jul 17, 2024
@lnicola
Copy link
Member

lnicola commented Jul 17, 2024

Does cargo check work in the VS Code terminal?

@ethanniser
Copy link
Author

@lnicola Yes
here is the whole project if it means anything: https://github.com/ethanniser/rust-analyzer-issue

happy to provide additional information or try different steps

thanks again

@lnicola
Copy link
Member

lnicola commented Jul 17, 2024

Any cargo.toml anywhere? Where do these come from: env -u IPHONEOS_DEPLOYMENT_TARGET -u TVOS_DEPLOYMENT_TARGET -u XROS_DEPLOYMENT_TARGET?

@ethanniser
Copy link
Author

I appreciate you taking the time to help

Any cargo.toml anywhere?

as in like randomly in my file system? there shouldnt be

Where do these come from: env -u IPHONEOS_DEPLOYMENT_TARGET -u TVOS_DEPLOYMENT_TARGET -u XROS_DEPLOYMENT_TARGET?

I genuinely have no clue I thought they were something specific to the crate


I installed the rust toolchain today via fenix

Is there anything else I can do to help you?

@lnicola
Copy link
Member

lnicola commented Jul 17, 2024

Does cargo check work in the VS Code terminal?
@lnicola Yes

Sorry, cargo build!

I genuinely have no clue I thought they were something specific to the crate

No, I think it will fail even without dependencies.

Is there anything else I can do to help you?

I don't know anything about Nix, sorry 😔.

Normally, rust-lld is installed by rustup, somewhere like ~/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/bin/rust-lld. But it shouldn't be used on Mac OS, where the system linker is "good enough" AFAIK.

@ethanniser
Copy link
Author

ethanniser commented Jul 17, 2024

both cargo build and cargo check run fine

I really dont see how this would be a nix thing
in my mind either the required executables / variables are in the environment or they arent ... and everything is (right?- thats why cargo build works?)


just to try it I removed the fenix stuff, just installed rustup as a nix package (no different than downloading it)

then running

╰─ rustup toolchain install stable
info: syncing channel updates for 'stable-aarch64-apple-darwin'

  stable-aarch64-apple-darwin unchanged - rustc 1.79.0 (129f3b996 2024-06-10)

so I should have a regular rustup install

so that path exists on my machine:

─    ~/.r/toolchains/stable-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/bin ········································································································· ✔  23:45:23  
╰─ lst  
.
├── gcc-ld
│  ├── ld.lld
│  ├── ld64.lld
│  ├── lld-link
│  └── wasm-ld
└── rust-lld

same issue remains

@Veykril
Copy link
Member

Veykril commented Jul 17, 2024

Can you try building with rust-analyzer via task? That should pop up a new terminal tab showing what command is being run, including what cargo specifically. Ctrl/⌘+Shift+P -> rust-analyzer: Run when inside the main.rs file

@ethanniser
Copy link
Author

main.rs -> Ctrl/⌘+Shift+P -> rust-analyzer: Run -> cargo run -p run-test

 *  Executing task: cargo run --package rust-test 

    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.00s
     Running `target/debug/rust-test`
hello world

(there was also cargo check -p run-test --all-targets and cargo test -p run-test --all-targets - all ran successfully)

same error as at the start still present in rust-analyzer output

@Jeremiah-Griffin
Copy link

Jeremiah-Griffin commented Jul 21, 2024

Any cargo.toml anywhere? Where do these come from: env -u IPHONEOS_DEPLOYMENT_TARGET -u TVOS_DEPLOYMENT_TARGET -u XROS_DEPLOYMENT_TARGET?

Hi, I've run into an issue I believe to share a root cause. In my example repo I make use of cargo.toml and am able to reproduce the behavior of rust-analyzer rejecting code that rustc is happy to compile.

OS: Win 11 Home 22H2 (22621.3880)
rustc version: 1.81.0-nightly (5affbb171 2024-07-18)
rust-analyzer version: 1.81.0-nightly (5affbb17 2024-07-18)
editor: helix 23.10 (f6021dd0)
relevant settings: .cargo/config.toml of linked repository

This behavior seems to have manifested itself somewhat recently for me. Maybe around 2 - 3 weeks ago. It's been a while since I had worked in the affected repository and longer since a toolchain upgrade so I cannot be sure.

This repo replicates the issue using uuid and sqlx.

It does seem to be an issue in part with the [env] structure in config.toml.

@Jeremiah-Griffin
Copy link

I've tracked my issue to nightly-2024-06-24-x86_64-pc-windows-msvc.

Ill see if I can try to find the specific commit tonight or tomorrow.

@ethanniser
Copy link
Author

ethanniser commented Jul 24, 2024

really appreciate you taking a look
fwiw I just tried using rust-anaylzer in neovim through mason which installed 2024-07-22 and it seems to be working just fine

@Jeremiah-Griffin
Copy link

really appreciate you taking a look fwiw I just tried using rust-anaylzer in neovim through mason which installed 2024-07-22 and it seems to be working just fine

I will move to a new issue then.

@ethanniser
Copy link
Author

sure
just to clarify, the issue is still the same as originally described in vscode

@Veykril
Copy link
Member

Veykril commented Jul 25, 2024

Any cargo.toml anywhere? Where do these come from: env -u IPHONEOS_DEPLOYMENT_TARGET -u TVOS_DEPLOYMENT_TARGET -u XROS_DEPLOYMENT_TARGET?

Hi, I've run into an issue I believe to share a root cause. In my example repo I make use of cargo.toml and am able to reproduce the behavior of rust-analyzer rejecting code that rustc is happy to compile.

OS: Win 11 Home 22H2 (22621.3880) rustc version: 1.81.0-nightly (5affbb171 2024-07-18) rust-analyzer version: 1.81.0-nightly (5affbb17 2024-07-18) editor: helix 23.10 (f6021dd0) relevant settings: .cargo/config.toml of linked repository

This behavior seems to have manifested itself somewhat recently for me. Maybe around 2 - 3 weeks ago. It's been a while since I had worked in the affected repository and longer since a toolchain upgrade so I cannot be sure.

This repo replicates the issue using uuid and sqlx.

It does seem to be an issue in part with the [env] structure in config.toml.

I think your issue is resolved by #17697

@Veykril
Copy link
Member

Veykril commented Jul 25, 2024

Regarding the original issue, I am a bit stumped here as well

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

No branches or pull requests

4 participants