-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
cargo clippy #681
cargo clippy #681
Conversation
Oh, no, this isn't what I meant. I was suggesting we create |
That way we don't need to have clippy as a staticlib at all. It can be run as a plugin and run as a compiler drop-in. |
hmm... that works? I'll see what cargo says |
Basically, this way folks can continue using it as a plugin, but |
i so didn't think this would work, but behold: I'm using lib.rs for both clippy the plugin and cargo-clippy the executable |
travis failure is due to my inability to figure out the location of the standard libs in a portable way |
args.push("-L".to_owned()); | ||
args.push(dep_path.as_ref().to_string_lossy().into_owned()); | ||
args.push(String::from("--sysroot")); | ||
args.push(format!("{}/.multirust/toolchains/nightly", std::env::var("HOME").unwrap())); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This won't always be true
so this isn't quite so trivial... Simply replacing rustc by using the |
so... I got it to work. Here's the current status quo:
|
Why not read |
because we don't necessarily have multirust, but I can do it if it's there |
Please do. You'll need to use this in conjunction with MULTIRUST_HOME and some other variables which I forget (read through the rustc shell script). They are only set within an invocation of rustc or cargo, though. Which works for us. |
done |
I left the fallback in, so anyone not using multirust can set the
To run the pedantic lints, just run It would also be easy to add a flag to run clippy while compiling dependencies, not sure if that is of any use. |
(will review soon, bit busy with packing and unpacking and repacking et cetera) |
args.push(String::from("--sysroot")); | ||
args.push(sysroot); | ||
args.push("-Zno-trans".to_owned()); | ||
args.push("-Dclippy".to_owned()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we want -Dclippy by default? cc @llogiq
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In what context is this (sorry, am on mobile)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should cargo clippy -Dclippy by default?
(I lean towards no)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed. The default behavior of clippy should also be cargo-cclippy's default.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yea, it makes no difference, since there's -Z-no-trans
so compilation stops after the lints anyway, I just had this in there for testing some stuff.
Overall LGTM, small fixes. We should also update the readme to mention |
works awesomely btw, really excited to get this up! 😄 |
args.push(sysroot); | ||
args.push("-Zno-trans".to_owned()); | ||
args.push("-Dclippy".to_owned()); | ||
args | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also can all of this be moved to src/bin
or at least src/main.rs
? Especially since src/lib.rs
is mostly generated from the Python scripts.
Besides that great! 🎉
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll check, not sure how cargo install
interacts with this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ugh, I remember why I chose not to do that. Clippy is built as a dylib, so it needs to be distributed (cargo install only ever installs a single file). I'll check if I can enforce clippy to be built both as a dylib and a staticlib
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cargo install installs the binary which is different from the lib anyway?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So... I haven't figured it out. There's crate-type = ["staticlib", "dylib"]
, but then I get lots of errors about dependency 'foo' not found in rlib format
. We can split clippy threeways:
- clippy-lints: the current code except for the
#[plugin_registrar]
attribute - clippy: a plugin with
#[plugin_registrar]
that simply calls theplugin_registrar
function inclippy-lints
- clippy-cargo: an executable that calls
plugin_registrar
ofclippy-lints
like it does now
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cargo install installs the binary which is different from the lib anyway?
yea, but if the lib is built as a dylib, then it's not statically linked into the binary, so executing the binary fails with libclippy.so not found
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Manishearth and I chatted on irc. The decision was to do this later.
addressed comments |
as a next step we should probably let travis run |
travis likes it now... Takes around 6 minutes (previously it was 4 minutes), since But |
rebased and added docs |
I'm OK with Travis taking a bit longer if we also check cargo-clippy in the process. |
let dep_path = env::current_dir().expect("current dir is not readable").join("target").join("debug").join("deps"); | ||
let sys_root = match (option_env!("MULTIRUST_HOME"), option_env!("MULTIRUST_TOOLCHAIN")) { | ||
(Some(home), Some(toolchain)) => format!("{}/toolchains/{}", home, toolchain), | ||
_ => option_env!("SYSROOT").expect("need to specify SYSROOT env var during clippy compilation").to_owned(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
... or use multirust
This got lost in a hidden github comment: What is the behaviour you expect from calling |
In a cargo repo. I'm okay with having Alternatively, provide a different binary "clippy" that doesn't do the cargo stuff. But you mentioned that splitting lib.rs doesn't work well, which would be necessary here. Hmm. (postpone this to the future?) rustfmt has cargo fmt and rustfmt for this reason |
@@ -243,6 +267,8 @@ cargo rustc -- -L /path/to/clippy_so -Z extra-plugins=clippy | |||
*[Note](https://github.com/Manishearth/rust-clippy/wiki#a-word-of-warning):* | |||
Be sure that clippy was compiled with the same version of rustc that cargo invokes here! | |||
|
|||
###optional dependency |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
capitalize
addressed all comments. r=@Manishearth (https://botbot.me/mozilla/rust/2016-05-08/?msg=65674824&page=8) |
I shall make a publish and test this through the publish tomorrow ( |
works great! |
yay! :) I'll add it to TWIR |
args.push(String::from("--sysroot")); | ||
args.push(sysroot); | ||
args.push("-Zno-trans".to_owned()); | ||
args | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
By the way, GitHub hide that but it’s really ugly IMO to have
extern crate rustc_driver;
extern crate getopts;
fn main() {
…
}
extern crate some;
extern crate other;
extern crate krates;
pub fn plugin_registrar(reg: &mut Registry) {
…
}
And I really would have preferred to split that file in src/lib.rs
+ src/bin.rs
(but GitHub also censored that comment at some point).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I noticed the comment, there was some discussion (that disappeared) and some discussion on irc, it's really hard to do this without splitting the main clippy stuff into its own crate, because I couldn't figure out how to let src/main.rs
link against clippy
statically, because clippy sets plugin = true
and then that's that, no way to also compile it as a staticlib
. So we'd need to split clippy into a crate with all the code, and a plugin crate + binary crate (the last two can be together again)... or, I just noticed, the plugin crate can link against the binary crate, but that's probably even messier than what we have now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah ok then, you’ve done enough wizardry already here 😄, I can live with it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, its a follow-up bug I may look into
Could you ensure this works with rustup.rs? Someone on IRC had trouble with it but didn't elaborate. Otherwise I'll look into it tomorrow. |
Might be worth asking if cargo-clippy will now yank theirs, as I accidentally got that one at first. That one does a brute git-clone into And in fact rustup doesn't work -- I just filed #910. |
@arcnmx thoughts? |
@Manishearth that's not mine, it's @White-Oak's. |
Ah, so |
Yes, that's what it does. |
cc arcnmx/cargo-clippy#16
@arcnmx are you ok with moving this here?