rust-lang / rust-clippy

A bunch of lints to catch common mistakes and improve your Rust code. Book: https://doc.rust-lang.org/clippy/
https://rust-lang.github.io/rust-clippy/
Other
11.28k stars 1.52k forks source link

Locating standard libraries outside of sysroot #7017

Open rpbeltran opened 3 years ago

rpbeltran commented 3 years ago

I'm currently working on running Clippy to analyze Rust repositories that are being cross compiled.

The location of sysroot is decided based on the platform being compiled, such as /build/amd64-generic, while the sysroot found by running rustc --print sysroot is /usr. Because this sysroot is different from the sysroot used by the compiling platform, it may not actually contain the compiler itself, or the standard library, which seems to break some of the underlying assumptions being made by Clippy.

I get the following error message: error[E0463]: can't find crate for `std`

On the other hand, running the same commands with cargo build successfully builds the repository. It would therefore seem that Clippy expects the standard library and all other dependencies to exist with the compiler in the same tree in SYSROOT, while cargo build does not.

This makes it difficult to properly support linting before cross compilation.

I'm currently quite new to working with Rust, but I'm happy to contribute in any way I can if someone could offer some pointers or insight on what it would take to support this usecase. Thanks!

camsteffen commented 3 years ago

Could you provide steps to reproduce the error?