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

Clippy cannot find 'std' with non-standard libdir #2874

Closed
o01eg opened this issue Jun 26, 2018 · 11 comments
Closed

Clippy cannot find 'std' with non-standard libdir #2874

o01eg opened this issue Jun 26, 2018 · 11 comments
Labels
C-bug Category: Clippy is not doing the correct thing

Comments

@o01eg
Copy link
Contributor

o01eg commented Jun 26, 2018

When I try even hello world project I got error:

$ cargo clippy --verbose
    Checking tst001 v0.1.0 (file:///tmp/tst001)
     Running `/usr/bin/clippy-driver rustc --crate-name tst001 src/main.rs --crate-type bin --emit=dep-info,metadata -C debuginfo=2 -C metadata=9d53d8442a8c6217 -C extra-filename=-9d53d8442a8c6217 --out-dir /tmp/tst001/target/debug/deps -C incremental=/tmp/tst001/target/debug/incremental -L dependency=/tmp/tst001/target/debug/deps`
error[E0463]: can't find crate for `std`

error: Could not compile `tst001`.

Clippy version: 0.0.210
Rustc version:

rustc 1.28.0-dev (773ce53ce 2018-06-26)
binary: rustc
commit-hash: 773ce53ce7b3acb97cfbd3d189dc3fbf33ec05c6
commit-date: 2018-06-26
host: x86_64-unknown-linux-gnu
release: 1.28.0-dev
LLVM version: 6.0

Rustc built with non-standart libdir and libstd placed there:

/usr/lib64/rust-9999/libstd-c9650cebf997ec41.so
/usr/lib64/rust-9999/rustlib/x86_64-unknown-linux-gnu/lib/libstd-c9650cebf997ec41.rlib
/usr/lib64/rust-9999/rustlib/x86_64-unknown-linux-gnu/lib/libstd-c9650cebf997ec41.so

Rustc successfully builds programs but clippy fails to check it.

@oli-obk oli-obk changed the title Clippy could find 'std' with non-standart libdir. Clippy cannot find 'std' with non-standard libdir Jun 28, 2018
@o01eg
Copy link
Contributor Author

o01eg commented Aug 28, 2018

It could be fixed by RUSTFLAGS="-L /usr/lib/rust-9999/ -L /usr/lib64/rust-9999/rustlib/x86_64-unknown-linux-gnu/lib/" same way as rust-lang/rust#45345

@o01eg
Copy link
Contributor Author

o01eg commented Oct 3, 2018

Looks like clippy gets wrong sysroot:

clippy searches std crate:

DEBUG 2018-10-03T18:02:52Z: rustc_metadata::creader: resolving extern crate stmt. ident: std orig_name: Some(std)
 INFO 2018-10-03T18:02:52Z: rustc_metadata::creader: resolving crate `extern crate std as std`
 INFO 2018-10-03T18:02:52Z: rustc_metadata::creader: falling back to a load
DEBUG 2018-10-03T18:02:52Z: rustc::session::filesearch: using sysroot = , triple = x86_64-unknown-linux-gnu
DEBUG 2018-10-03T18:02:52Z: rustc::session::filesearch: filesearch: searching lib path
DEBUG 2018-10-03T18:02:52Z: rustc::session::filesearch: searching lib64/rust-9999/rustlib/x86_64-unknown-linux-gnu/lib
DEBUG 2018-10-03T18:02:52Z: rustc::session::filesearch: using sysroot = , triple = x86_64-unknown-linux-gnu
DEBUG 2018-10-03T18:02:52Z: rustc::session::filesearch: filesearch: searching lib path
DEBUG 2018-10-03T18:02:52Z: rustc::session::filesearch: searching lib64/rust-9999/rustlib/x86_64-unknown-linux-gnu/lib

rustc searches std crate:

DEBUG 2018-10-03T18:02:43Z: rustc_metadata::creader: resolving extern crate stmt. ident: std orig_name: Some(std)
 INFO 2018-10-03T18:02:43Z: rustc_metadata::creader: resolving crate `extern crate std as std`
 INFO 2018-10-03T18:02:43Z: rustc_metadata::creader: falling back to a load
DEBUG 2018-10-03T18:02:43Z: rustc::session::filesearch: using sysroot = /usr, triple = x86_64-unknown-linux-gnu
DEBUG 2018-10-03T18:02:43Z: rustc::session::filesearch: filesearch: searching lib path
DEBUG 2018-10-03T18:02:43Z: rustc::session::filesearch: searching /usr/lib64/rust-9999/rustlib/x86_64-unknown-linux-gnu/lib
DEBUG 2018-10-03T18:02:43Z: rustc::session::filesearch: testing /usr/lib64/rust-9999/rustlib/x86_64-unknown-linux-gnu/lib/librustc_msan-1cfc56079fb3f13f.rlib
DEBUG 2018-10-03T18:02:43Z: rustc::session::filesearch: rejected /usr/lib64/rust-9999/rustlib/x86_64-unknown-linux-gnu/lib/librustc_msan-1cfc56079fb3f13f.rlib
DEBUG 2018-10-03T18:02:43Z: rustc::session::filesearch: testing /usr/lib64/rust-9999/rustlib/x86_64-unknown-linux-gnu/lib/librustc_apfloat-0c6154b2be7a1779.rlib
DEBUG 2018-10-03T18:02:43Z: rustc::session::filesearch: rejected /usr/lib64/rust-9999/rustlib/x86_64-unknown-linux-gnu/lib/librustc_apfloat-0c6154b2be7a1779.rlib
DEBUG 2018-10-03T18:02:43Z: rustc::session::filesearch: testing /usr/lib64/rust-9999/rustlib/x86_64-unknown-linux-gnu/lib/librand-5f71905a3afeb3c6.rlib
DEBUG 2018-10-03T18:02:43Z: rustc::session::filesearch: rejected /usr/lib64/rust-9999/rustlib/x86_64-unknown-linux-gnu/lib/librand-5f71905a3afeb3c6.rlib
DEBUG 2018-10-03T18:02:43Z: rustc::session::filesearch: testing /usr/lib64/rust-9999/rustlib/x86_64-unknown-linux-gnu/lib/liblibc-9051971c5420da5b.rlib
DEBUG 2018-10-03T18:02:43Z: rustc::session::filesearch: rejected /usr/lib64/rust-9999/rustlib/x86_64-unknown-linux-gnu/lib/liblibc-9051971c5420da5b.rlib
DEBUG 2018-10-03T18:02:43Z: rustc::session::filesearch: testing /usr/lib64/rust-9999/rustlib/x86_64-unknown-linux-gnu/lib/libcore-64c00a26fde9072b.rlib
DEBUG 2018-10-03T18:02:43Z: rustc::session::filesearch: rejected /usr/lib64/rust-9999/rustlib/x86_64-unknown-linux-gnu/lib/libcore-64c00a26fde9072b.rlib
DEBUG 2018-10-03T18:02:43Z: rustc::session::filesearch: testing /usr/lib64/rust-9999/rustlib/x86_64-unknown-linux-gnu/lib/liblog-df0261a19691ce50.rlib
DEBUG 2018-10-03T18:02:43Z: rustc::session::filesearch: rejected /usr/lib64/rust-9999/rustlib/x86_64-unknown-linux-gnu/lib/liblog-df0261a19691ce50.rlib
...
DEBUG 2018-10-03T18:02:43Z: rustc::session::filesearch: testing /usr/lib64/rust-9999/rustlib/x86_64-unknown-linux-gnu/lib/libLLVM-8svn.so
DEBUG 2018-10-03T18:02:43Z: rustc::session::filesearch: rejected /usr/lib64/rust-9999/rustlib/x86_64-unknown-linux-gnu/lib/libLLVM-8svn.so
DEBUG 2018-10-03T18:02:43Z: rustc::session::filesearch: testing /usr/lib64/rust-9999/rustlib/x86_64-unknown-linux-gnu/lib/libstd-bfc851248fb38db2.so
 INFO 2018-10-03T18:02:43Z: rustc_metadata::locator: lib candidate: /usr/lib64/rust-9999/rustlib/x86_64-unknown-linux-gnu/lib/libstd-bfc851248fb38db2.so
DEBUG 2018-10-03T18:02:43Z: rustc::session::filesearch: picked /usr/lib64/rust-9999/rustlib/x86_64-unknown-linux-gnu/lib/libstd-bfc851248fb38db2.so
DEBUG 2018-10-03T18:02:43Z: rustc::session::filesearch: testing /usr/lib64/rust-9999/rustlib/x86_64-unknown-linux-gnu/lib/librustc_codegen_utils-45be47c90e032f27.so
DEBUG 2018-10-03T18:02:43Z: rustc::session::filesearch: rejected /usr/lib64/rust-9999/rustlib/x86_64-unknown-linux-gnu/lib/librustc_codegen_utils-45be47c90e032f27.so
...
DEBUG 2018-10-03T18:02:43Z: rustc::session::filesearch: testing /usr/lib64/rust-9999/rustlib/x86_64-unknown-linux-gnu/lib/librustc_save_analysis-0dd167a18754e5a9.so
DEBUG 2018-10-03T18:02:43Z: rustc::session::filesearch: rejected /usr/lib64/rust-9999/rustlib/x86_64-unknown-linux-gnu/lib/librustc_save_analysis-0dd167a18754e5a9.so
 INFO 2018-10-03T18:02:43Z: rustc_metadata::locator: rlib reading metadata from: /usr/lib64/rust-9999/rustlib/x86_64-unknown-linux-gnu/lib/libstd-bfc851248fb38db2.rlib
 INFO 2018-10-03T18:02:43Z: rustc_metadata::locator: reading "libstd-bfc851248fb38db2.rlib" => 89.626µs
 INFO 2018-10-03T18:02:43Z: rustc_metadata::creader: register crate `extern crate std as std`

@o01eg
Copy link
Contributor Author

o01eg commented Oct 3, 2018

Session parameters are differs:
Clippy:

Session.default_sysroot = None
Session.opts.maybe_sysroot = Some("")

Rustc:

Session.default_sysroot = Some("/usr")
Session.opts.maybe_sysroot =  None

@o01eg
Copy link
Contributor Author

o01eg commented Oct 4, 2018

sys_root at https://github.com/rust-lang-nursery/rust-clippy/blob/master/src/driver.rs#L32 somehow get value "" while rustc --print sysroot returns /usr

@oli-obk oli-obk added the C-bug Category: Clippy is not doing the correct thing label Oct 4, 2018
@oli-obk
Copy link
Contributor

oli-obk commented Oct 4, 2018

Whoa, great analysis! Thanks

The culprit is most likey https://github.com/rust-lang-nursery/rust-clippy/blob/master/src/driver.rs#L70 which was necessary to get clippy to work back in the day. We probably don't need it anymore now that clippy is distributed with rustup.

@o01eg
Copy link
Contributor Author

o01eg commented Oct 4, 2018

Would be good if it could be removed because I've tried to add panics to or_else branches and it looks like gets its value from option_env!("SYSROOT") but in compilation logs I gets different sysroot:

rustc command: "LD_LIBRARY_PATH"="/tmp/portage/dev-lang/rust-9999/work/rust-git-src/build/x86_64-unknown-linux-gnu/stage2/lib:/tmp/portage/dev-lang/rust-9999/work/rust-git-src/build/x86_64-unknown-linux-gnu/stage2-tools/release/deps:/tmp/portage/dev-lang/rust-9999/work/rust-git-src/build/x86_64-unknown-linux-gnu/stage2/lib:/tmp/portage/dev-lang/rust-9999/work/rust-git-src/build/x86_64-unknown-linux-gnu/stage2-tools/release/build/backtrace-sys-53a8f6542068b62c/out" "/tmp/portage/dev-lang/rust-9999/work/rust-git-src/build/x86_64-unknown-linux-gnu/stage2/bin/rustc" "--edition=2018" "--crate-name" "clippy_driver" "tools/clippy/src/driver.rs" "--color" "always" "--crate-type" "bin" "--emit=dep-info,link" "-C" "opt-level=2" "-C" "metadata=5be02e1874c1f6e1" "-C" "extra-filename=-5be02e1874c1f6e1" "--out-dir" "/tmp/portage/dev-lang/rust-9999/work/rust-git-src/build/x86_64-unknown-linux-gnu/stage2-tools/x86_64-unknown-linux-gnu/release/deps" "--target" "x86_64-unknown-linux-gnu" "-L" "dependency=/tmp/portage/dev-lang/rust-9999/work/rust-git-src/build/x86_64-unknown-linux-gnu/stage2-tools/x86_64-unknown-linux-gnu/release/deps" "-L" "dependency=/tmp/portage/dev-lang/rust-9999/work/rust-git-src/build/x86_64-unknown-linux-gnu/stage2-tools/release/deps" "--extern" "clippy=/tmp/portage/dev-lang/rust-9999/work/rust-git-src/build/x86_64-unknown-linux-gnu/stage2-tools/release/deps/libclippy-e843d026bc5653f9.so" "--extern" "clippy_lints=/tmp/portage/dev-lang/rust-9999/work/rust-git-src/build/x86_64-unknown-linux-gnu/stage2-tools/x86_64-unknown-linux-gnu/release/deps/libclippy_lints-a50a4bef572b65e1.rlib" "--extern" "regex=/tmp/portage/dev-lang/rust-9999/work/rust-git-src/build/x86_64-unknown-linux-gnu/stage2-tools/x86_64-unknown-linux-gnu/release/deps/libregex-f67f10ff25c1a30c.rlib" "--extern" "rustc_tools_util=/tmp/portage/dev-lang/rust-9999/work/rust-git-src/build/x86_64-unknown-linux-gnu/stage2-tools/x86_64-unknown-linux-gnu/release/deps/librustc_tools_util-a4c7a68e27e3eb06.rlib" "--extern" "semver=/tmp/portage/dev-lang/rust-9999/work/rust-git-src/build/x86_64-unknown-linux-gnu/stage2-tools/x86_64-unknown-linux-gnu/release/deps/libsemver-6dcaed672aa8a0bb.rlib" "-L" "native=/tmp/portage/dev-lang/rust-9999/work/rust-git-src/build/x86_64-unknown-linux-gnu/stage2-tools/x86_64-unknown-linux-gnu/release/build/backtrace-sys-3f0854e9df9d1851/out" "--cfg" "stage2" "--sysroot" "/tmp/portage/dev-lang/rust-9999/work/rust-git-src/build/x86_64-unknown-linux-gnu/stage2" "-Clinker=x86_64-pc-linux-gnu-gcc" "-C" "debug-assertions=y"
sysroot: "/tmp/portage/dev-lang/rust-9999/work/rust-git-src/build/x86_64-unknown-linux-gnu/stage2"
libdir: "/tmp/portage/dev-lang/rust-9999/work/rust-git-src/build/x86_64-unknown-linux-gnu/stage2/lib"

@oli-obk
Copy link
Contributor

oli-obk commented Oct 4, 2018

OH! that makes total sense. It used to be that everyone built clippy on their own system. So in that case this would still make sense probably.

We need to tread carefully here, but I think it's fine to get rid of the entire sysroot hackery

@o01eg
Copy link
Contributor Author

o01eg commented Oct 4, 2018

What if get sysroot from internals of rustc?

Oh, removing sysroot argument would actually do this.

matthiaskrgr added a commit to matthiaskrgr/rust-clippy that referenced this issue Dec 11, 2018
This reverts commit 041c49c, reversing
changes made to 1df5766.

This broke clippy working when installed from the git repo via cargo install.

Fixes rust-lang#3523
Reopens rust-lang#2874
bors added a commit that referenced this issue Dec 19, 2018
Revert "Merge pull request #3257 from o01eg/remove-sysroot"

This reverts commit 041c49c, reversing
changes made to 1df5766.

The PR broke running a cargo-install'd clippy.
The installed clippy would not be able to find a crate for std.

Fixes #3523
Reopens #2874
@matthiaskrgr
Copy link
Member

The fix pr had to be reverted.

@o01eg
Copy link
Contributor Author

o01eg commented Dec 25, 2018

Looks like built-in clippy compiled with SYSROOT="". What if ignore compiled SYSROOT variable if it empty Some("")?

@flip1995
Copy link
Member

This should've been fixed here: f5db351

It is also tested by our CI, that clippy-driver and rustc always print the same sysroot.

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

Successfully merging a pull request may close this issue.

4 participants