dylint icon indicating copy to clipboard operation
dylint copied to clipboard

Dylint relies on rustup

Open GoldsteinE opened this issue 3 years ago • 19 comments

Doing cargo dylint new lint-name, trying to implement a new lint and running cargo build produces enormous amount of errors inside of clippy.

GoldsteinE avatar Sep 13 '22 11:09 GoldsteinE

Hi, @GoldsteinE. I'm sorry this isn't working for you. I want to help you get this resolved.

Can I confirm, you are running these commands?

cargo dylint new lint-name
cd lint-name
cargo build

From within the lint-name directory, could you please share the output of the following commands?

uname -a
cargo dylint --version
cat Cargo.toml
cat rust-toolchain

smoelius avatar Sep 13 '22 14:09 smoelius

Yes, I’m running these commands.

$ uname -a
Linux think 5.19.5 #1-NixOS SMP PREEMPT_DYNAMIC Mon Aug 29 09:18:05 UTC 2022 x86_64 GNU/Linux
$ cargo dylint --version
cargo-dylint 2.0.12
$ cat Cargo.toml
[package]
name = "lint_name"
version = "0.1.0"
authors = ["authors go here"]
description = "description goes here"
edition = "2021"
publish = false

[lib]
crate-type = ["cdylib"]

[dependencies]
clippy_utils = { git = "https://github.com/rust-lang/rust-clippy", rev = "2b2190cb5667cdd276a24ef8b9f3692209c54a89" }
dylint_linting = "2.0.12"
if_chain = "1.0.2"

[dev-dependencies]
dylint_testing = "2.0.12"

[package.metadata.rust-analyzer]
rustc_private = true

rust-toolchain is irrelevant, since I’m not using rustup, so here is my rustc --version instead:

rustc 1.65.0-nightly (b44197abb 2022-09-05)

GoldsteinE avatar Sep 13 '22 16:09 GoldsteinE

rust-toolchain is irrelevant, since I’m not using rustup, so here is my rustc --version instead:

I suspect that's the source of the problem. Each clippy_utils revision is pinned to a specific rustc version. For example, revision 2b2190cb5667cdd276a24ef8b9f3692209c54a89 is pinned to nightly-2022-08-11.

Could you try cargo +nightly-2022-08-11 build?

Is using rustup not an option for you?

smoelius avatar Sep 13 '22 16:09 smoelius

Using rustup is not an option for me, but I can try specific nightly version.

In general I’d prefer for dylint to determine and use installed nightly, not the other way around. Is there a mapping of some kind? Maybe I could contribute a patch for such an option.

GoldsteinE avatar Sep 13 '22 16:09 GoldsteinE

In general I’d prefer for dylint to determine and use installed nightly, not the other way around.

The current behavior is by design. The problem is that the compiler APIs can change. So just like a clippy_utils revision is pinned to a specific compiler revision, so too is a lint. The rustc version that a lint is pinned to is essentially recorded in its rustup-toolchain file.

In other words, if Dylint used the installed nightly, the following could happen. A lint builds fine. Then the developer updates their toolchain. Then the lint ceases to build. The current setup is meant to avoid this possibility.

smoelius avatar Sep 13 '22 17:09 smoelius

In other words, if Dylint used the installed nightly, the following could happen. A lint builds fine. Then the developer updates their toolchain. Then the lint ceases to build. The current setup is meant to avoid this possibility.

I should say, one can do this---there's nothing in Dylint that prevents using the installed toolchain. But doing so could be painful, for the reason given.

smoelius avatar Sep 13 '22 17:09 smoelius

I changed the toolchain to one in rust-toolchain, exported RUSTUP_TOOLCHAIN (which is required by dylint’s linker for some reason) and it worked. I’ll try to send some patches to make this more friendly to non-rustup workflow.

GoldsteinE avatar Sep 13 '22 18:09 GoldsteinE

UI tests seem to be completely unusable without rustup, even with rustup shim answering to rustup which rustc. I’ll try fix it, so non-rustup workflows are possible.

GoldsteinE avatar Sep 13 '22 19:09 GoldsteinE

I’ll try to send some patches to make this more friendly to non-rustup workflow.

I just want to ensure that the current rustup-based workflow doesn't break.

If you would like to propose ideas here before implementing, you would be welcome to.

smoelius avatar Sep 13 '22 20:09 smoelius

I need to get a look at the source code first, but generally I think that when rustup is not found, dylint should fall back to more general solutions (like which rustc instead of rustup which rustc).

GoldsteinE avatar Sep 13 '22 20:09 GoldsteinE

On the face of it, that sounds perfectly reasonable.

smoelius avatar Sep 13 '22 21:09 smoelius

  1. Could we please change the title of this issue to something like "Dylnt relies on rustup"?
  2. In the past, I have considered using rustup as a library, instead of using the command line tool. The reason then was to make it easier to test with a specific version of rustup, as opposed to whatever the user had installed. Would a solution like that work for you, or are you opposed to all rustup-related tooling, generally?

smoelius avatar Sep 14 '22 05:09 smoelius

Using a built in rustup would certainly be better. It'd still install a second copy of Rust, even if system Rust already has the right version.

GoldsteinE avatar Sep 14 '22 06:09 GoldsteinE

Related: https://github.com/rust-lang/rust-clippy/issues/7261

smoelius avatar Apr 17 '23 13:04 smoelius

@GoldsteinE I've attached a future enhancement label to this issue and I want to explain why.

I was seriously considering linking in rustup to avoid relying on it being available on the command line. But there is a tradeoff: linking in rustup would benefit users that do not have rustup installed, but it would also increase Dylint's overall number of dependencies.

Experience has taught me that having a large number of dependencies can be bad. Until version 3.0.0, Dylint linked in cargo, which has a large number of dependencies. On more than one occasion, a problem with one of cargo's dependencies broke cargo-dylint installation. For this reason, Dylint no longer links in cargo by default.

The number of dependencies that rustup relies on is not as large as cargo, but I think the lesson still applies.

So, again, thank you very much for raising the issue. But, for now, I think the best course of action is to rely on rustup being available on the command line.

smoelius avatar Mar 22 '24 12:03 smoelius

I think this is the same story:

There is one case where I find relying on rustup excessive: cargo-dylint --help fails with exit code 1 if there is no RUST_TOOLCHAIN env variable. However I run --help only to ensure in CI that the cargo-dylint library is properly compiled.

frondeus avatar May 08 '24 12:05 frondeus

cargo-dylint --help fails with exit code 1 if there is no RUST_TOOLCHAIN env variable

I can't seem to reproduce this. I agree that would be excessive, though.

Are you using a recent version of cargo-dylint? Is there a publicly available GitHub log showing the failure?

smoelius avatar May 08 '24 14:05 smoelius

My apologies, I made a mistake - it's not a cargo-dylint but dylint-link that exits with code 1: image

frondeus avatar May 09 '24 15:05 frondeus

Ah. I agree that should not happen. Thanks for reporting. I'll get it fixed.

smoelius avatar May 09 '24 15:05 smoelius