-
Notifications
You must be signed in to change notification settings - Fork 21
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
Making a Dylint binary? #839
Comments
I want to be sure I understand what you are asking for. You want to create a set of lints, and a binary that runs those lints on an arbitrary project. Is that right? If so, that's not really what Dylint is meant for. It's not discouraged, but it would likely require some engineering. For example, Dylint expects lints to be encapsulated in dynamic libraries. So the binary would need to have a way of obtaining such libraries, e.g., by downloading or building them. Having said that, Dylint itself can be used as a library. I am open to suggestions on how to make it more useable as a library. Please let me know if I have misunderstood your question. |
Exactly. As I mentioned, the ideal outcome would be a crates.io-distributed binary that runs similarly to
What would be a "proper" way of going about this? I really don't have any experience with rustc, sorry. |
Sorry, I don't follow. What do you mean by "proper"? |
Nothing in particular. I simply mean a semi-reliable method that's not too "hacky". But to be honest, anything will suffice. I'm just looking for a starting point. |
Maybe? One advantage this approach would have is that you could reuse Dylint's drivers, which are extensible by design. But if the driver only needs to run a fixed set of lints, one could argue they should be statically linked, like they are in Clippy. Actually, here is a way one might accomplish that. I very recently added a constituent feature to You might be able to use that feature as follows. Build and test Dylint libraries as normal. Then, when you are ready to link the lints into a binary, enable the Here is the idea in slightly more detail. The driver would have a dylint/examples/general/src/lib.rs Line 11 in 674c878
The driver would call that function instead of calling one from a dynamic library, the way Dylint drivers do: Line 230 in 674c878
The dylint/examples/general/Cargo.toml Line 13 in 674c878
Sorry, that was a mouthful. But I would be happy to expand on any of the above. |
I'll try it out, thanks! |
I've got the linter structure just like in the examples, but I'm confused about how to actually call and use the lints from the binary |
The situation is not as simple as one would hope. Most linters that use rustc's linting interface are divided into two binaries: a command line tool (e.g., a cargo subcommand) and a driver. The driver is essentially a wrapper around the rust compiler and is invoked by Cargo for each crate that needs to be compiled. The command line tool tells Cargo where to find the driver by setting the This blog post provides more details: https://blog.trailofbits.com/2021/11/09/write-rust-lints-without-forking-clippy/ So what I imagine you are writing now as your |
Thanks a lot! I've been putting this off for the last two weeks, but I had a look at the Clippy source code and it doesn't seem that bad. This does mean that I won't be using Dylint though. Would love to see an update that focuses on creating binary linters, |
@tigerros I'm attaching a While Dylint could be used to help create a linting binary (e.g., like I described here), that's not really what Dylint was meant for. I think the idea of creating a linting binary framework has merit. It's just a little outside of Dylint's scope. |
@smoelius I saw rust-marker being suggested somewhere, as a way to create a CLI linter. However, I'm not quite sure what it is, I've just kind of skimmed over it, and the docs aren't stellar. You're actually one of the contributors, so I'm wondering if you forgot about it or if it's not what I was looking for. I saw the "crate lint" example, but that seems similar to Dylint, because it's a cdylib, not a binary. |
Marker is similar to Dylint, in that it allows you to write and run individual lints. A (perhaps "the") key difference is that Marker provides its own, stable linting API, whereas Dylint provides direct access to the Rust compiler linting APIs. However, for both Dylint and Marker, the compiled artifacts are cdylibs. In other words, I think some "finagling" would be required to build a linting binary using either tool. cc: @xFrednet (who should not feel obligated to comment) |
@smoelius summarized it pretty well. The interface of Marker is currently a bit more limited than the rustc one dylint exposes. Though, I think it's sufficient for a good number of lints already and more user-friendly in some regards. Regarding the requested feature in the context of Marker: We have rust-marker/marker#258, which requests the implementation of static linking for lint crates. We also have an RFC rust-marker/marker#307 which suggests a way to potentially combine multiple lint crates into a single cdylib. @tigerros could you explain a bit how you would like to use this feature? Marker and I believe dylint, both provide an CLI which hides the lint crate compilation. For example, in Marker you can use |
@xFrednet Yes, I want to make something like Clippy, just for a specific framework. I think Marker will do nicely. I'm having some issues with installation though. I get this output when running
|
Awesome, if you run into any problems, you're always welcome to create an issue in the Marker repo. These kinds of issues are an enormous help. For the bug: I don't use windows, so this might have slipped through. I've created rust-marker/marker#318 to track this bug and also included a suggestion on how to fix it for now. Was the CLI the main reason for requesting static linking of lint crates, or are there other motivations? |
How would one go about making a Dylint binary? In the guide, it only seems to cover libraries, but I would like to make a binary that can run in any package, like
cargo clippy
. Am I missing something?The text was updated successfully, but these errors were encountered: