rust-lang / cargo

The Rust package manager
https://doc.rust-lang.org/cargo
Apache License 2.0
12.66k stars 2.4k forks source link

build error where there shouldnt be #12935

Closed makuru-dd closed 6 months ago

makuru-dd commented 11 months ago

Problem

I'll try to make a small project with slint but it errors out with message:

   compiling …
   Compiling slint-macros v1.2.2
   Compiling slint v1.2.2
error[E0463]: can't find crate for `slint_macros`
   --> /home/lenovo/.cargo/registry/src/index.crates.io-6f17d22bba15001f/slint-1.2.2/lib.rs:202:9
    |
202 | pub use slint_macros::slint;
    |         ^^^^^^^^^^^^ can't find crate

For more information about this error, try `rustc --explain E0463`.
error: could not compile `slint` (lib) due to previous error

even though it is defined in cargo.toml

Steps

  1. Install Nixos
  2. copy my config (ask for it)
  3. run my project calculator.zip

Possible Solution(s)

No response

Notes

https://github.com/slint-ui/slint/issues/3877

Version

cargo 1.73.0 (9c4383fb5 2023-08-26)
release: 1.73.0
commit-hash: 9c4383fb55986096b414d98125421ab87b5fd642
commit-date: 2023-08-26
host: x86_64-unknown-linux-gnu
libgit2: 1.6.4 (sys:0.17.2 vendored)
libcurl: 8.2.1-DEV (sys:0.4.65+curl-8.2.1 vendored ssl:OpenSSL/1.1.1u)
ssl: OpenSSL 1.1.1u  30 May 2023
os: NixOS 23.11.0 [64-bit]
epage commented 11 months ago

I downloaded the zip file and it wouldn't build because the build.rs needed slint_build. I uncommented that dependency and cargo check worked. This was with cargo 1.73.0 (9c4383fb5 2023-08-26) on a regular Linux distribution.

ogoffart commented 11 months ago

I originally got this reported at https://github.com/slint-ui/slint/issues/3877 I've never seen this error before and many user have been using the slint crate from crates.io without a problem. And the slint-macros crate is not even behind a feature flag.

Perhaps something to do with the NixOS environment which can be sometimes a bit special?

weihanglo commented 11 months ago

I use Nix as a package manager on AWS Amazon Linux 2 and built your project flawlessly.

Not sure if it is relevant, but how did you install Rust on NixOS? Is it possible to share related nix env or settings?

makuru-dd commented 11 months ago
  users.users.lenovo = {
    uid = 1001;
    isNormalUser = true;
    extraGroups = [ "wheel" "networkmanager" "libvirtd" "adbusers" ];
    packages = with pkgs; [

      ……………………
      # Development
      vscodium-fhs
      direnv
      python3Full
      rustup
      rust-analyzer
      gcc_multi
      pkg-config
      fontconfig
      android-studio
      qt6.full
      mesa
      libGLU
      slint-lsp

      # programming
      python311Packages.matplotlib
      python311Packages.numpy
      python311Packages.pyserial
      pylint
      openssl
      pkg-config

      ……………………
    ];
  };
weihanglo commented 11 months ago

This issue might be relevant: https://github.com/rust-lang/rust/issues/115073

It is happening because on Nix, we need to patch the binary's dynamic linker (.interp) and dynamic library search path (rpath/RUNPATH) so that they point at the Nix-specific values ...

weihanglo commented 6 months ago

With nix-shell -p slint-lsp I can confirm it's slint-lsp that confuses rustc: https://github.com/NixOS/nixpkgs/blob/d272ca50d1f7424fbfcd1e6f1c9e01d92f6da167/pkgs/development/tools/misc/slint-lsp/default.nix#L50

I am going to close this, as it is more like a NixOS specific behavior that might not be fixable on Cargo side. If possible, I would recommend installing it from cargo install slint-lsp as a workaround.