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

Fails to detect crate std on NixOS #53

Open
shimunn opened this issue Feb 1, 2023 · 7 comments
Open

Fails to detect crate std on NixOS #53

shimunn opened this issue Feb 1, 2023 · 7 comments

Comments

@shimunn
Copy link

shimunn commented Feb 1, 2023

Hi,

I've just ran into an issue with autocfg when trying to use zbus which depends on autocfg in my project. I'm developing on NixOS which has an bit of an unusual directory structure, which may lead autocfg astray. Which is why indexmap is led to belive it's being built in a nostd environment.

Is there any way to make autocfg belive that an certain crate is available or some other workaround?

@cuviper
Copy link
Owner

cuviper commented Feb 1, 2023

For indexmap in particular, it also has a cargo feature "std" that bypasses the autocfg check. If you add that dependency to your project with the feature enabled, cargo will unify features with the rest of your dependency tree.

But autocfg is just running rustc, and the expectation is that std should be found in the sysroot. What does NixOS do differently there? If you manually run rustc on a simple fn main() {}, does that find std?

@shimunn
Copy link
Author

shimunn commented Feb 3, 2023

For indexmap in particular, it also has a cargo feature "std" that bypasses the autocfg check. If you add that dependency to your project with the feature enabled, cargo will unify features with the rest of your dependency tree.

That's a fix but not an solution.

But autocfg is just running rustc, and the expectation is that std should be found in the sysroot. What does NixOS do differently there? If you manually run rustc on a simple fn main() {}, does that find std?

Yes I can compile using lain rustc just fine.

@cuviper
Copy link
Owner

cuviper commented Feb 3, 2023

Is there a wrapper or something that sets the sysroot or library search path? I'm not sure what's missing here...

@shimunn
Copy link
Author

shimunn commented Feb 6, 2023

Seems to be my dev environment, with an shell(nix shell nixpkgs#cargo nixpkgs#rustc) just containing cargo & rustc everything works as expected.

Could you point out the env variables I would have to check to get my dev environment working once again? My sysroot looks fine in my eyes:

rustc --print sysroot
/nix/store/l49zzww7wl3qxnvx61jbcb5kwpcp31ln-rust-nightly-complete-2023-02-06

tree /nix/store/l49zzww7wl3qxnvx61jbcb5kwpcp31ln-rust-nightly-complete-2023-02-06 -L 2
/nix/store/l49zzww7wl3qxnvx61jbcb5kwpcp31ln-rust-nightly-complete-2023-02-06
├── bin
│   ├── cargo
│   ├── cargo-clippy
│   ├── cargo-fmt
│   ├── cargo-miri
│   ├── clippy-driver
│   ├── miri
│   ├── rls
│   ├── rust-analyzer
│   ├── rustc
│   ├── rustdoc
│   ├── rustfmt
│   ├── rust-gdb
│   ├── rust-gdbgui
│   └── rust-lldb
├── etc
│   └── bash_completion.d
├── lib
│   ├── libLLVM-15-rust-1.69.0-nightly.so -> /nix/store/hd29v2rlzvhi1snx0178475s0ffb2x9j-rustc-nightly-complete-2023-02-06/lib/libLLVM-15-rust-1.69.0-nightly.so
│   ├── librustc_driver-0d5965989a9dd9e8.so
│   ├── libstd-6e3768d17ed5c91f.so -> /nix/store/hd29v2rlzvhi1snx0178475s0ffb2x9j-rustc-nightly-complete-2023-02-06/lib/libstd-6e3768d17ed5c91f.so
│   ├── libtest-5df56ae6cfa4ea18.so -> /nix/store/hd29v2rlzvhi1snx0178475s0ffb2x9j-rustc-nightly-complete-2023-02-06/lib/libtest-5df56ae6cfa4ea18.so
│   └── rustlib
├── libexec
│   ├── cargo-credential-1password -> /nix/store/jpwjibja78sy7wq99l232ynm34hxka11-cargo-nightly-complete-2023-02-06/libexec/cargo-credential-1password
│   └── rust-analyzer-proc-macro-srv -> /nix/store/hd29v2rlzvhi1snx0178475s0ffb2x9j-rustc-nightly-complete-2023-02-06/libexec/rust-analyzer-proc-macro-srv
└── share
    ├── doc
    ├── man
    └── zsh

echo $RUST_SRC_PATH
/nix/store/l49zzww7wl3qxnvx61jbcb5kwpcp31ln-rust-nightly-complete-2023-02-06/lib/rustlib

# running autocfg tests
cargo test
    Finished test [unoptimized + debuginfo] target(s) in 0.01s
     Running unittests src/lib.rs (target/debug/deps/autocfg-7098375cc8c07875)
error[E0463]: can't find crate for `std`

error[E0463]: can't find crate for `std`

error[E0463]: can't find crate for `std`

error[E0463]: can't find crate for `std`

error[E0463]: can't find crate for `std`

error: aborting due to previous error

For more information about this error, try `rustc --explain E0463`.
error[E0463]: can't find crate for `std`

error[E0463]: can't find crate for `std`

error: aborting due to previous error
error: aborting due to previous error
error: aborting due to previous error


error[E0463]: can't find crate for `std`


error: aborting due to previous error

For more information about this error, try `rustc --explain E0463`.For more information about this error, try `rustc --explain E0463`.
For more information about this error, try `rustc --explain E0463`.

For more information about this error, try `rustc --explain E0463`.
error[E0463]: can't find crate for `std`
error: aborting due to previous error
error: aborting due to previous error



For more information about this error, try `rustc --explain E0463`.
For more information about this error, try `rustc --explain E0463`.
error[E0463]: can't find crate for `std`
error: aborting due to previous error


For more information about this error, try `rustc --explain E0463`.
error: aborting due to previous error

For more information about this error, try `rustc --explain E0463`.
error[E0463]: can't find crate for `std`

error: aborting due to previous error

For more information about this error, try `rustc --explain E0463`.
error: aborting due to previous error

For more information about this error, try `rustc --explain E0463`.
error[E0463]: can't find crate for `core`

error[E0463]: can't find crate for `core`

error[E0463]: can't find crate for `core`
error[E0463]: can't find crate for `core`
error[E0463]: can't find crate for `core`
error[E0463]: can't find crate for `core`



error[E0463]: can't find crate for `compiler_builtins`


error[E0463]: can't find crate for `compiler_builtins`

error[E0463]: can't find crate for `compiler_builtins`

error[E0463]: can't find crate for `compiler_builtins`

error[E0463]: can't find crate for `compiler_builtins`

error[E0463]: can't find crate for `compiler_builtins`

error[E0463]: can't find crate for `core`

error[E0463]: can't find crate for `compiler_builtins`

error[E0463]: can't find crate for `core`

error[E0463]: can't find crate for `core`

error[E0463]: can't find crate for `compiler_builtins`

error[E0463]: can't find crate for `compiler_builtins`

error[E0463]: can't find crate for `core`

error: aborting due to 2 previous errors
error: aborting due to 2 previous errors
error: aborting due to 2 previous errors
error: aborting due to 2 previous errors




error: aborting due to 2 previous errors
error: aborting due to 2 previous errors
error: aborting due to 2 previous errors



For more information about this error, try `rustc --explain E0463`.
For more information about this error, try `rustc --explain E0463`.
For more information about this error, try `rustc --explain E0463`.error[E0463]: can't find crate for `compiler_builtins`


For more information about this error, try `rustc --explain E0463`.For more information about this error, try `rustc --explain E0463`.For more information about this error, try `rustc --explain E0463`.
For more information about this error, try `rustc --explain E0463`.


error: aborting due to 2 previous errors
error: aborting due to 2 previous errors


For more information about this error, try `rustc --explain E0463`.For more information about this error, try `rustc --explain E0463`.

error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0463`.
error[E0463]: can't find crate for `core`

error[E0463]: can't find crate for `compiler_builtins`

error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0463`.
warning: autocfg could not probe for `std`
warning: autocfg could not probe for `std`
warning: autocfg could not probe for `std`
warning: autocfg could not probe for `std`
warning: autocfg could not probe for `std`
warning: autocfg could not probe for `std`
warning: autocfg could not probe for `std`
warning: autocfg could not probe for `std`
warning: autocfg could not probe for `std`
warning: autocfg could not probe for `std`
warning: autocfg could not probe for `std`
error[E0463]: can't find crate for `std`

error[E0463]: can't find crate for `std`

error[E0463]: can't find crate for `std`

error[E0463]: can't find crate for `std`
error[E0463]: can't find crate for `std`


error[E0463]: can't find crate for `std`

error[E0463]: can't find crate for `doesnt_exist`
 --> <anon>:1:1
  |
1 | extern crate doesnt_exist as probe;
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ can't find crate

error[E0463]: can't find crate for `std`

error[E0463]: can't find crate for `std`
 --> <anon>:1:1
  |
1 | extern crate std as probe;
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^ can't find crate
error: aborting due to previous error


error: aborting due to previous error

For more information about this error, try `rustc --explain E0463`.For more information about this error, try `rustc --explain E0463`.

error: requires `sized` lang_item

error[E0463]: can't find crate for `std`

error[E0463]: can't find crate for `std`

error: aborting due to 2 previous errors
error: aborting due to 2 previous errors
error: aborting due to previous error



For more information about this error, try `rustc --explain E0463`.
For more information about this error, try `rustc --explain E0463`.
For more information about this error, try `rustc --explain E0463`.
error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0463`.
error: aborting due to previous error
error[E0463]: can't find crate for `std`


For more information about this error, try `rustc --explain E0463`.
error: requires `sized` lang_item

error[E0463]: can't find crate for `alloc`
 --> <anon>:1:1
  |
1 | extern crate alloc as probe;
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ can't find crate

error: aborting due to previous error

For more information about this error, try `rustc --explain E0463`.
error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0463`.
error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0463`.
error: test failed, to rerun pass `--lib`

unsetting RUST_SRC_PATH doesn't change anything though.

@cuviper
Copy link
Owner

cuviper commented Feb 7, 2023

Did you truncate that tree at rustlib, or is that empty? The $sysroot/lib is used at runtime, but for builds rustc will look in $sysroot/lib/rustlib/$target/lib by default.

As for environment, RUSTFLAGS would be the most obvious, but that should be supported. RUST_WRAPPER would be my next bet, and that is not supported yet -- #26, but I do have a local branch for that. Beyond that, I don't know, check for anything with RUST or CARGO in the name.

@cuviper
Copy link
Owner

cuviper commented Feb 8, 2023

rustc will look in $sysroot/lib/rustlib/$target/lib by default.

I just remembered there's a concise command to find this, rustc --print target-libdir.

@zhaofengli
Copy link

If you use toolchains shipped by rust-overlay, this should be fixed with oxalica/rust-overlay#134.

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

3 participants