Skip to content

Commit

Permalink
feat(zkstack_cli): Use the same rust toolchain as main repo (matter-l…
Browse files Browse the repository at this point in the history
…abs#3230)

## What ❔

<!-- What are the changes this PR brings about? -->
<!-- Example: This PR adds a PR template to the repo. -->
<!-- (For bigger PRs adding more context is appreciated) -->
Add linting target for Rust toolchains.

## Why ❔

<!-- Why are these changes done? What goal do they contribute to? What
are the principles behind them? -->
<!-- Example: PR templates ensure PR reviewers, observers, and future
iterators are in context about the evolution of repos. -->

## Checklist

<!-- Check your PR fulfills the following items. -->
<!-- For draft PRs check the boxes as you complete them. -->

- [x] PR title corresponds to the body of PR (we generate changelog
entries from PRs).
- [x] Tests for the changes have been added / updated.
- [x] Documentation comments have been added / updated.
- [x] Code has been formatted via `zkstack dev fmt` and `zkstack dev
lint`.
  • Loading branch information
manuelmauro authored Nov 7, 2024
1 parent 7b8640a commit e69d15b
Show file tree
Hide file tree
Showing 9 changed files with 54 additions and 21 deletions.
1 change: 1 addition & 0 deletions .github/workflows/ci-core-lint-reusable.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ jobs:
ci_run zkstack dev lint -t ts --check
ci_run zkstack dev lint -t rs --check
ci_run zkstack dev lint -t autocompletion --check
ci_run zkstack dev lint -t rust-toolchain
- name: Check Database
run: |
Expand Down
3 changes: 2 additions & 1 deletion rust-toolchain
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
nightly-2024-08-01
[toolchain]
channel = "nightly-2024-08-01"
7 changes: 0 additions & 7 deletions zkstack_cli/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions zkstack_cli/crates/zkstack/completion/_zkstack.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -1255,8 +1255,8 @@ esac
;;
(lint)
_arguments "${_arguments_options[@]}" : \
'*-t+[]:TARGETS:(md sol js ts rs contracts autocompletion)' \
'*--targets=[]:TARGETS:(md sol js ts rs contracts autocompletion)' \
'*-t+[]:TARGETS:(md sol js ts rs contracts autocompletion rust-toolchain)' \
'*--targets=[]:TARGETS:(md sol js ts rs contracts autocompletion rust-toolchain)' \
'--chain=[Chain to use]:CHAIN:_default' \
'-c[]' \
'--check[]' \
Expand Down Expand Up @@ -1309,8 +1309,8 @@ _arguments "${_arguments_options[@]}" : \
;;
(prettier)
_arguments "${_arguments_options[@]}" : \
'*-t+[]:TARGETS:(md sol js ts rs contracts autocompletion)' \
'*--targets=[]:TARGETS:(md sol js ts rs contracts autocompletion)' \
'*-t+[]:TARGETS:(md sol js ts rs contracts autocompletion rust-toolchain)' \
'*--targets=[]:TARGETS:(md sol js ts rs contracts autocompletion rust-toolchain)' \
'--chain=[Chain to use]:CHAIN:_default' \
'-v[Verbose mode]' \
'--verbose[Verbose mode]' \
Expand Down
2 changes: 1 addition & 1 deletion zkstack_cli/crates/zkstack/completion/zkstack.fish
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ complete -c zkstack -n "__fish_zkstack_using_subcommand dev; and __fish_seen_sub
complete -c zkstack -n "__fish_zkstack_using_subcommand dev; and __fish_seen_subcommand_from snapshot" -s h -l help -d 'Print help'
complete -c zkstack -n "__fish_zkstack_using_subcommand dev; and __fish_seen_subcommand_from snapshot" -f -a "create"
complete -c zkstack -n "__fish_zkstack_using_subcommand dev; and __fish_seen_subcommand_from snapshot" -f -a "help" -d 'Print this message or the help of the given subcommand(s)'
complete -c zkstack -n "__fish_zkstack_using_subcommand dev; and __fish_seen_subcommand_from lint" -s t -l targets -r -f -a "{md\t'',sol\t'',js\t'',ts\t'',rs\t'',contracts\t'',autocompletion\t''}"
complete -c zkstack -n "__fish_zkstack_using_subcommand dev; and __fish_seen_subcommand_from lint" -s t -l targets -r -f -a "{md\t'',sol\t'',js\t'',ts\t'',rs\t'',contracts\t'',autocompletion\t'',rust-toolchain\t''}"
complete -c zkstack -n "__fish_zkstack_using_subcommand dev; and __fish_seen_subcommand_from lint" -l chain -d 'Chain to use' -r
complete -c zkstack -n "__fish_zkstack_using_subcommand dev; and __fish_seen_subcommand_from lint" -s c -l check
complete -c zkstack -n "__fish_zkstack_using_subcommand dev; and __fish_seen_subcommand_from lint" -s v -l verbose -d 'Verbose mode'
Expand Down
8 changes: 4 additions & 4 deletions zkstack_cli/crates/zkstack/completion/zkstack.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3104,11 +3104,11 @@ _zkstack() {
fi
case "${prev}" in
--targets)
COMPREPLY=($(compgen -W "md sol js ts rs contracts autocompletion" -- "${cur}"))
COMPREPLY=($(compgen -W "md sol js ts rs contracts autocompletion rust-toolchain" -- "${cur}"))
return 0
;;
-t)
COMPREPLY=($(compgen -W "md sol js ts rs contracts autocompletion" -- "${cur}"))
COMPREPLY=($(compgen -W "md sol js ts rs contracts autocompletion rust-toolchain" -- "${cur}"))
return 0
;;
--chain)
Expand Down Expand Up @@ -3768,11 +3768,11 @@ _zkstack() {
fi
case "${prev}" in
--targets)
COMPREPLY=($(compgen -W "md sol js ts rs contracts autocompletion" -- "${cur}"))
COMPREPLY=($(compgen -W "md sol js ts rs contracts autocompletion rust-toolchain" -- "${cur}"))
return 0
;;
-t)
COMPREPLY=($(compgen -W "md sol js ts rs contracts autocompletion" -- "${cur}"))
COMPREPLY=($(compgen -W "md sol js ts rs contracts autocompletion rust-toolchain" -- "${cur}"))
return 0
;;
--chain)
Expand Down
42 changes: 39 additions & 3 deletions zkstack_cli/crates/zkstack/src/commands/dev/commands/lint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ pub fn run(shell: &Shell, args: LintArgs) -> anyhow::Result<()> {
Target::Ts,
Target::Contracts,
Target::Autocompletion,
Target::RustToolchain,
]
} else {
args.targets.clone()
Expand All @@ -55,6 +56,7 @@ pub fn run(shell: &Shell, args: LintArgs) -> anyhow::Result<()> {
Target::Rs => lint_rs(shell, &ecosystem, args.check)?,
Target::Contracts => lint_contracts(shell, &ecosystem, args.check)?,
Target::Autocompletion => lint_autocompletion_files(shell, args.check)?,
Target::RustToolchain => check_rust_toolchain(shell)?,
ext => lint(shell, &ecosystem, &ext, args.check)?,
}
}
Expand All @@ -70,13 +72,18 @@ fn lint_rs(shell: &Shell, ecosystem: &EcosystemConfig, check: bool) -> anyhow::R
let link_to_code = &ecosystem.link_to_code;
let lint_to_prover = &ecosystem.link_to_code.join("prover");
let link_to_zkstack = &ecosystem.link_to_code.join("zkstack_cli");
let paths = vec![link_to_code, lint_to_prover, link_to_zkstack];

spinner.freeze();
for path in paths {
for path in [link_to_code, lint_to_prover, link_to_zkstack] {
let _dir_guard = shell.push_dir(path);
let mut cmd = cmd!(shell, "cargo clippy");
let common_args = &["--locked", "--", "-D", "warnings"];
let mut common_args = vec!["--locked", "--", "-D", "warnings"];

if !path.ends_with("prover") {
common_args.push("-D");
common_args.push("unstable-features");
}

if !check {
cmd = cmd.args(&["--fix", "--allow-dirty"]);
}
Expand All @@ -87,6 +94,34 @@ fn lint_rs(shell: &Shell, ecosystem: &EcosystemConfig, check: bool) -> anyhow::R
Ok(())
}

fn check_rust_toolchain(shell: &Shell) -> anyhow::Result<()> {
// deserialize /zkstack_cli/rust-toolchain as TOML
let path = Path::new("zkstack_cli/rust-toolchain");
if !path.exists() {
logger::info("WARNING: Please run this command from the project's root folder");
return Ok(());
}
let contents = shell.read_file(path)?;
let zkstack_cli_toolchain: toml::Value = toml::from_str(&contents)?;

// deserialize /rust-toolchain as TOML
let path = Path::new("rust-toolchain");
let contents = shell.read_file(path)?;
let zksync_era_toolchain: toml::Value = toml::from_str(&contents)?;

// check if the toolchains are the same
if zksync_era_toolchain["toolchain"]["channel"] != zkstack_cli_toolchain["toolchain"]["channel"]
{
bail!(
"The Rust toolchains are not the same: ZKsync Era: {} - ZK Stack CLI: {}",
zksync_era_toolchain["toolchain"]["channel"],
zkstack_cli_toolchain["toolchain"]["channel"]
);
}

Ok(())
}

fn get_linter(target: &Target) -> Vec<String> {
match target {
Target::Rs => vec!["cargo".to_string(), "clippy".to_string()],
Expand All @@ -96,6 +131,7 @@ fn get_linter(target: &Target) -> Vec<String> {
Target::Ts => vec!["eslint".to_string(), "--ext".to_string(), "ts".to_string()],
Target::Contracts => vec![],
Target::Autocompletion => vec![],
Target::RustToolchain => vec![],
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ pub enum Target {
Rs,
Contracts,
Autocompletion,
RustToolchain,
}

#[derive(Deserialize, Serialize, Debug)]
Expand Down
3 changes: 2 additions & 1 deletion zkstack_cli/rust-toolchain
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
nightly-2024-08-01
[toolchain]
channel = "nightly-2024-08-01"

0 comments on commit e69d15b

Please sign in to comment.