From 7a97f6b29bc32a04b5a4b04d1dd96243ca364f09 Mon Sep 17 00:00:00 2001 From: Manuel Mauro Date: Tue, 5 Nov 2024 15:30:14 +0100 Subject: [PATCH 1/5] feat: add linting target for Rust toolchains --- .github/workflows/ci-core-lint-reusable.yml | 1 + rust-toolchain | 3 +- zkstack_cli/Cargo.lock | 7 ---- .../crates/zkstack/completion/_zkstack.zsh | 8 ++-- .../crates/zkstack/completion/zkstack.fish | 2 +- .../crates/zkstack/completion/zkstack.sh | 8 ++-- .../zkstack/src/commands/dev/commands/lint.rs | 38 ++++++++++++++++++- .../src/commands/dev/commands/lint_utils.rs | 1 + zkstack_cli/rust-toolchain | 3 +- 9 files changed, 52 insertions(+), 19 deletions(-) diff --git a/.github/workflows/ci-core-lint-reusable.yml b/.github/workflows/ci-core-lint-reusable.yml index 0babbd1c9db7..0d4db601c467 100644 --- a/.github/workflows/ci-core-lint-reusable.yml +++ b/.github/workflows/ci-core-lint-reusable.yml @@ -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: | diff --git a/rust-toolchain b/rust-toolchain index 03c040b91f1f..bc5d1d6bbd8e 100644 --- a/rust-toolchain +++ b/rust-toolchain @@ -1 +1,2 @@ -nightly-2024-08-01 +[toolchain] +channel = "nightly-2024-08-01" diff --git a/zkstack_cli/Cargo.lock b/zkstack_cli/Cargo.lock index 7770d06a1977..0f3450db64d0 100644 --- a/zkstack_cli/Cargo.lock +++ b/zkstack_cli/Cargo.lock @@ -1088,7 +1088,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b42b6fa04a440b495c8b04d0e71b707c585f83cb9cb28cf8cd0d976c315e31b4" dependencies = [ "powerfmt", - "serde", ] [[package]] @@ -6799,11 +6798,6 @@ dependencies = [ "rand", "secrecy", "serde", - "strum", - "strum_macros", - "time", - "url", - "vise", "zksync_basic_types", "zksync_concurrency", "zksync_consensus_utils", @@ -6953,7 +6947,6 @@ dependencies = [ "secrecy", "serde_json", "serde_yaml", - "time", "tracing", "zksync_basic_types", "zksync_config", diff --git a/zkstack_cli/crates/zkstack/completion/_zkstack.zsh b/zkstack_cli/crates/zkstack/completion/_zkstack.zsh index f1cfc9946731..825fc967e6d7 100644 --- a/zkstack_cli/crates/zkstack/completion/_zkstack.zsh +++ b/zkstack_cli/crates/zkstack/completion/_zkstack.zsh @@ -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[]' \ @@ -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]' \ diff --git a/zkstack_cli/crates/zkstack/completion/zkstack.fish b/zkstack_cli/crates/zkstack/completion/zkstack.fish index a1261082e6f0..7ad4e6959f90 100644 --- a/zkstack_cli/crates/zkstack/completion/zkstack.fish +++ b/zkstack_cli/crates/zkstack/completion/zkstack.fish @@ -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' diff --git a/zkstack_cli/crates/zkstack/completion/zkstack.sh b/zkstack_cli/crates/zkstack/completion/zkstack.sh index 7cdb20ae9aa7..ff351ebd79ed 100644 --- a/zkstack_cli/crates/zkstack/completion/zkstack.sh +++ b/zkstack_cli/crates/zkstack/completion/zkstack.sh @@ -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) @@ -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) diff --git a/zkstack_cli/crates/zkstack/src/commands/dev/commands/lint.rs b/zkstack_cli/crates/zkstack/src/commands/dev/commands/lint.rs index 6c3c3fa3d756..8535779ac39e 100644 --- a/zkstack_cli/crates/zkstack/src/commands/dev/commands/lint.rs +++ b/zkstack_cli/crates/zkstack/src/commands/dev/commands/lint.rs @@ -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() @@ -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)?, } } @@ -76,7 +78,14 @@ fn lint_rs(shell: &Shell, ecosystem: &EcosystemConfig, check: bool) -> anyhow::R for path in paths { let _dir_guard = shell.push_dir(path); let mut cmd = cmd!(shell, "cargo clippy"); - let common_args = &["--locked", "--", "-D", "warnings"]; + let common_args = &[ + "--locked", + "--", + "-D", + "warnings", + "-D", + "unstable-features", + ]; if !check { cmd = cmd.args(&["--fix", "--allow-dirty"]); } @@ -87,6 +96,32 @@ fn lint_rs(shell: &Shell, ecosystem: &EcosystemConfig, check: bool) -> anyhow::R Ok(()) } +fn check_rust_toolchain(_shell: &Shell) -> anyhow::Result<()> { + // read rust-toolchain.toml + let mut file = File::open("rust-toolchain")?; + let mut contents = String::new(); + file.read_to_string(&mut contents)?; + let zksync_era_toolchain: toml::Value = toml::from_str(&contents)?; + + // deserialize rust-toolchain.toml in zkstack_cli as TOML + let mut file = File::open("zkstack_cli/rust-toolchain")?; + let mut zkstack_contents = String::new(); + file.read_to_string(&mut zkstack_contents)?; + let zkstack_cli_toolchain: toml::Value = toml::from_str(&zkstack_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 { match target { Target::Rs => vec!["cargo".to_string(), "clippy".to_string()], @@ -96,6 +131,7 @@ fn get_linter(target: &Target) -> Vec { Target::Ts => vec!["eslint".to_string(), "--ext".to_string(), "ts".to_string()], Target::Contracts => vec![], Target::Autocompletion => vec![], + Target::RustToolchain => vec![], } } diff --git a/zkstack_cli/crates/zkstack/src/commands/dev/commands/lint_utils.rs b/zkstack_cli/crates/zkstack/src/commands/dev/commands/lint_utils.rs index 11a325047104..93184de76561 100644 --- a/zkstack_cli/crates/zkstack/src/commands/dev/commands/lint_utils.rs +++ b/zkstack_cli/crates/zkstack/src/commands/dev/commands/lint_utils.rs @@ -15,6 +15,7 @@ pub enum Target { Rs, Contracts, Autocompletion, + RustToolchain, } #[derive(Deserialize, Serialize, Debug)] diff --git a/zkstack_cli/rust-toolchain b/zkstack_cli/rust-toolchain index 03c040b91f1f..bc5d1d6bbd8e 100644 --- a/zkstack_cli/rust-toolchain +++ b/zkstack_cli/rust-toolchain @@ -1 +1,2 @@ -nightly-2024-08-01 +[toolchain] +channel = "nightly-2024-08-01" From 03c74a379160d0a4f342f323a1122ef737e36b89 Mon Sep 17 00:00:00 2001 From: Manuel Mauro Date: Tue, 5 Nov 2024 15:54:31 +0100 Subject: [PATCH 2/5] feat: check CWD when linting Rust toolchains --- .../zkstack/src/commands/dev/commands/lint.rs | 24 ++++++++++--------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/zkstack_cli/crates/zkstack/src/commands/dev/commands/lint.rs b/zkstack_cli/crates/zkstack/src/commands/dev/commands/lint.rs index 8535779ac39e..fad9969130cf 100644 --- a/zkstack_cli/crates/zkstack/src/commands/dev/commands/lint.rs +++ b/zkstack_cli/crates/zkstack/src/commands/dev/commands/lint.rs @@ -96,18 +96,20 @@ fn lint_rs(shell: &Shell, ecosystem: &EcosystemConfig, check: bool) -> anyhow::R Ok(()) } -fn check_rust_toolchain(_shell: &Shell) -> anyhow::Result<()> { - // read rust-toolchain.toml - let mut file = File::open("rust-toolchain")?; - let mut contents = String::new(); - file.read_to_string(&mut contents)?; - let zksync_era_toolchain: toml::Value = toml::from_str(&contents)?; +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.toml in zkstack_cli as TOML - let mut file = File::open("zkstack_cli/rust-toolchain")?; - let mut zkstack_contents = String::new(); - file.read_to_string(&mut zkstack_contents)?; - let zkstack_cli_toolchain: toml::Value = toml::from_str(&zkstack_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"] From a8ff7bd79018652494a0beafbc2c082ae12cacd2 Mon Sep 17 00:00:00 2001 From: Manuel Mauro Date: Tue, 5 Nov 2024 16:19:53 +0100 Subject: [PATCH 3/5] fix: forbid unstable features only in zkstack_cli --- .../zkstack/src/commands/dev/commands/lint.rs | 20 +++++++++---------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/zkstack_cli/crates/zkstack/src/commands/dev/commands/lint.rs b/zkstack_cli/crates/zkstack/src/commands/dev/commands/lint.rs index fad9969130cf..7d5cc14cef5f 100644 --- a/zkstack_cli/crates/zkstack/src/commands/dev/commands/lint.rs +++ b/zkstack_cli/crates/zkstack/src/commands/dev/commands/lint.rs @@ -72,20 +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", - "-D", - "unstable-features", - ]; + let mut common_args = vec!["--locked", "--", "-D", "warnings"]; + + if path.ends_with("zkstack_cli") { + common_args.push("-D"); + common_args.push("unstable-features"); + } + if !check { cmd = cmd.args(&["--fix", "--allow-dirty"]); } @@ -96,7 +94,7 @@ fn lint_rs(shell: &Shell, ecosystem: &EcosystemConfig, check: bool) -> anyhow::R Ok(()) } -fn check_rust_toolchain(shell: &Shell) -> anyhow::Result<()> { +fn check_rust_toolchain(shell: &Shell, ecosystem: &EcosystemConfig) -> anyhow::Result<()> { // deserialize /zkstack_cli/rust-toolchain as TOML let path = Path::new("zkstack_cli/rust-toolchain"); if !path.exists() { From 3072ae9fe184d548b07fa1008bffb777880ca343 Mon Sep 17 00:00:00 2001 From: Manuel Mauro Date: Tue, 5 Nov 2024 16:20:42 +0100 Subject: [PATCH 4/5] fix: remove typo --- zkstack_cli/crates/zkstack/src/commands/dev/commands/lint.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/zkstack_cli/crates/zkstack/src/commands/dev/commands/lint.rs b/zkstack_cli/crates/zkstack/src/commands/dev/commands/lint.rs index 7d5cc14cef5f..260957fea4c8 100644 --- a/zkstack_cli/crates/zkstack/src/commands/dev/commands/lint.rs +++ b/zkstack_cli/crates/zkstack/src/commands/dev/commands/lint.rs @@ -94,7 +94,7 @@ fn lint_rs(shell: &Shell, ecosystem: &EcosystemConfig, check: bool) -> anyhow::R Ok(()) } -fn check_rust_toolchain(shell: &Shell, ecosystem: &EcosystemConfig) -> anyhow::Result<()> { +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() { From 6eba57a87891e434e1926ff4a7330968fb737fb4 Mon Sep 17 00:00:00 2001 From: Manuel Mauro Date: Wed, 6 Nov 2024 12:12:13 +0100 Subject: [PATCH 5/5] feat: allow unstable Rust features only in prover --- zkstack_cli/crates/zkstack/src/commands/dev/commands/lint.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/zkstack_cli/crates/zkstack/src/commands/dev/commands/lint.rs b/zkstack_cli/crates/zkstack/src/commands/dev/commands/lint.rs index 260957fea4c8..5e413871f5d1 100644 --- a/zkstack_cli/crates/zkstack/src/commands/dev/commands/lint.rs +++ b/zkstack_cli/crates/zkstack/src/commands/dev/commands/lint.rs @@ -79,7 +79,7 @@ fn lint_rs(shell: &Shell, ecosystem: &EcosystemConfig, check: bool) -> anyhow::R let mut cmd = cmd!(shell, "cargo clippy"); let mut common_args = vec!["--locked", "--", "-D", "warnings"]; - if path.ends_with("zkstack_cli") { + if !path.ends_with("prover") { common_args.push("-D"); common_args.push("unstable-features"); }