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

Dylint relies on rustup #452

Open
GoldsteinE opened this issue Sep 13, 2022 · 19 comments
Open

Dylint relies on rustup #452

GoldsteinE opened this issue Sep 13, 2022 · 19 comments
Labels
future enhancement Expands the project's scope

Comments

@GoldsteinE
Copy link

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

@smoelius
Copy link
Collaborator

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

@GoldsteinE
Copy link
Author

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)

@smoelius
Copy link
Collaborator

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?

@GoldsteinE
Copy link
Author

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.

@smoelius
Copy link
Collaborator

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
Copy link
Collaborator

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.

@GoldsteinE
Copy link
Author

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
Copy link
Author

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.

@smoelius
Copy link
Collaborator

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.

@GoldsteinE
Copy link
Author

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).

@smoelius
Copy link
Collaborator

On the face of it, that sounds perfectly reasonable.

@smoelius
Copy link
Collaborator

  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?

@GoldsteinE GoldsteinE changed the title could not compile clippy_utils due to 520 previous errors Dylint relies on rustup Sep 14, 2022
@GoldsteinE
Copy link
Author

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.

@smoelius
Copy link
Collaborator

Related: rust-lang/rust-clippy#7261

@smoelius smoelius added the future enhancement Expands the project's scope label Mar 22, 2024
@smoelius
Copy link
Collaborator

@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.

@frondeus
Copy link

frondeus commented May 8, 2024

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.

@smoelius
Copy link
Collaborator

smoelius commented May 8, 2024

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?

@frondeus
Copy link

frondeus commented May 9, 2024

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

@smoelius
Copy link
Collaborator

smoelius commented May 9, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
future enhancement Expands the project's scope
Projects
None yet
Development

No branches or pull requests

3 participants