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

Integrate dylint lints to build #1412

Merged
merged 35 commits into from
Jan 24, 2024
Merged

Integrate dylint lints to build #1412

merged 35 commits into from
Jan 24, 2024

Conversation

jubnzv
Copy link
Member

@jubnzv jubnzv commented Nov 28, 2023

Summary

  • [n] y/n | Does it introduce breaking changes?
  • [y] y/n | Is it dependent on the specific version of ink or pallet-contracts?

Description

This PR follows up use-ink/ink#2001 making dylint-based lints mandatory in the build process. This change allows us to introduce ink-specific compilation errors more flexibly through the dylint-based ink_linting module.

Checklist before requesting a review

  • My code follows the style guidelines of this project
  • I have added an entry to CHANGELOG.md
  • I have commented my code, particularly in hard-to-understand areas
  • I have added tests that prove my fix is effective or that my feature works
  • Any dependent changes have been merged and published in downstream modules

fn lint(
dylint: bool,
extra_lints: bool,
Copy link
Member Author

@jubnzv jubnzv Nov 28, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't like that all the lints will be executed on each build, because it slows down the build process and may bother the user with extra noise generated by lints. Ideally, we should execute only mandatory lints needed to check compilation errors (like no_main) and skip the rest.

I think the most simple way to do this is to split our ink_linting in two dylint libraries, like ink_linting and ink_linting_extra. The first one will contain only the mandatory lints, and the second one will run the optional analyses when user requesting it.

There are other ways to suppress lints (like hacking Cargo.toml in contract projects or compilation flags for rustc), but AFAIK these will execute lints anyway, suppressing their output.

WDYT @ascjones?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes we only want the mandatory lints to execute every time, extra lints must still be opt-in.

I think the most simple way to do this is to split our ink_linting in two dylint libraries, like ink_linting and ink_linting_extra

Sounds good to me 👍

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Merged use-ink/ink#2032 now

crates/build/src/lib.rs Outdated Show resolved Hide resolved
crates/build/src/lib.rs Outdated Show resolved Hide resolved
fn lint(
dylint: bool,
extra_lints: bool,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes we only want the mandatory lints to execute every time, extra lints must still be opt-in.

I think the most simple way to do this is to split our ink_linting in two dylint libraries, like ink_linting and ink_linting_extra

Sounds good to me 👍

crates/build/src/lib.rs Show resolved Hide resolved
jubnzv added a commit to jubnzv/ink that referenced this pull request Dec 21, 2023
Split `ink_linting` to `ink_linting_mandatory` and `ink_linting`.

Mandatory lints will be integrated in the `cargo-build` build
process in use-ink/cargo-contract#1412.

Extra lints are optional and could be run by the contract developer to
highlight possible issues with secure coding style and to check the
compliance with best practices.

For more information about this design decision, see: use-ink/cargo-contract#1412 (comment).

Closes use-ink#2006
@jubnzv jubnzv marked this pull request as ready for review December 24, 2023 14:20
@jubnzv jubnzv requested review from cmichi, SkymanOne and a team as code owners December 24, 2023 14:20
@jubnzv
Copy link
Member Author

jubnzv commented Dec 24, 2023

It is ready for review; however, we need use-ink/ink#2032 to be merged first. This will allow us to install the ink_linting_mandatory library in GitHub Actions to fix the CI.

ascjones pushed a commit to use-ink/ink that referenced this pull request Jan 3, 2024
* feat(linter): Split `ink_linting` into two libraries

Split `ink_linting` to `ink_linting_mandatory` and `ink_linting`.

Mandatory lints will be integrated in the `cargo-build` build
process in use-ink/cargo-contract#1412.

Extra lints are optional and could be run by the contract developer to
highlight possible issues with secure coding style and to check the
compliance with best practices.

For more information about this design decision, see: use-ink/cargo-contract#1412 (comment).

Closes #2006

* chore: Update CHANGELOG

* feat: Run linting tests in github-actions

* fix(ci): Add caching for `linting` builds

* fix(ci): gh-actions syntax

* fix(ci)

* fix(ci): Remove `--locked` flag for linting

This is necessary, because the lockfile needs to be updated since we run
build with a different `rust-toolchain.yml`.
@jubnzv
Copy link
Member Author

jubnzv commented Jan 15, 2024

use-ink/ink#2060 will enable us to fix the CI issues here.

Copy link
Collaborator

@ascjones ascjones left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

Copy link
Collaborator

@cmichi cmichi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, Georgiy!

Reuse the previous approach with hacking the workspace manifest in the
contract project.

We cannot add those libraries as direct dependencies to cargo-contract
because we use a different version of the toolchain. To make it possible
for these libraries to be found at runtime, we would also have to hack
dylint.
Otherwise, it takes the toolchain version from `rust-toolchain.toml`
This is necessary to avoid installing two versions of toolchains.
@jubnzv
Copy link
Member Author

jubnzv commented Jan 22, 2024

It passed the CI and could be merged. But I would like to draw attention to a few points:

  1. This PR introduces rust-toolchain.toml to cargo-contract. The linter runs on a specific version of the toolchain. This requires users to have that particular toolchain version installed, along with the clippy and dylint components. To simplify the installation process for the end-user, I suggest using the same toolchain in cargo-contract, therefore enforcing it in the rust-toolchain file.
  2. cargo-dylint and dylint-link are now mandatory dependencies. I have updated all the instructions and the Dockerfile for the build image accordingly. However, I want to emphasize this point in case there is anything else where we should mention these dependencies.

@ascjones
Copy link
Collaborator

While I agree with idea of making it simple, I'm not sure about 1., because cargo-contract is no longer only used for compiling contracts. There are lots of features e.g. for interacting with contracts on the chain, so for another set of users who may not be compiling contracts at all we are making installation more difficult because they have to install that specific toolchain.

For 2., I guess you need to update use.ink setup instructions: source: https://github.com/paritytech/ink-docs/blob/master/docs/getting-started/setup.md

I am beginning to wonder whether we should start to encourage using a docker workflow, especially for workshops because getting setup with cargo-contract is becoming more complicated and time consuming, so something we should think about. Just thinking out loud, not something to solve here: but we should definitely keep in mind trying to keep things reasonably accessible when starting from scratch.

@cmichi
Copy link
Collaborator

cmichi commented Jan 22, 2024

I think we should avoid requiring a particular Rust toolchain for cargo-contract. As Andrew stated it will result in more complex user instructions. In the past we saw that every additional bit of complexity in the installation instructions results in significantly more users asking for help in channels.

@jubnzv
Copy link
Member Author

jubnzv commented Jan 24, 2024

I have removed the fixed toolchain version. Instead, I provide users with warnings and instructions on how to install the required toolchain. This occurs only if the user compiles for the RiscV target or explicitly runs the build with the --lint option.

I suggest not adding any complicated logic to toolchain management in the next release. This approach will give us time to discuss it and ensure that nothing is broken.

@jubnzv jubnzv merged commit 1319a7f into use-ink:master Jan 24, 2024
9 checks passed
@jubnzv jubnzv mentioned this pull request Jan 24, 2024
4 tasks
@smiasojed smiasojed mentioned this pull request Feb 8, 2024
@smiasojed smiasojed mentioned this pull request Mar 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants