Skip to content

Make clippy work for sp1 #2216

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

Closed
2 tasks done
liuchengxu opened this issue Apr 7, 2025 · 2 comments
Closed
2 tasks done

Make clippy work for sp1 #2216

liuchengxu opened this issue Apr 7, 2025 · 2 comments

Comments

@liuchengxu
Copy link
Contributor

Component

cargo prove CLI/sp1up

Have you ensured that all of these are up to date?

  • SP1 SDK
  • cargo prove CLI/sp1up

What version of SP1 SDK are you on?

No response

What version of the cargo prove CLI are you on?

No response

Operating System

None

Describe the bug

You can reproduce this by running clippy on any crate requiring the program, e.g., cd examples && cargo clippy --package aggregation-script.

warning: aggregation-script@1.1.0: Skipping build due to clippy invocation.
warning: aggregation-script@1.1.0: Skipping build due to clippy invocation.
   Compiling sp1-core-machine v4.2.0 (/mnt/Zhitai0/src/github.com/succinctlabs/sp1/crates/core/machine)
   Compiling sp1-recursion-core v4.2.0 (/mnt/Zhitai0/src/github.com/succinctlabs/sp1/crates/recursion/core)
    Checking sp1-curves v4.2.0 (/mnt/Zhitai0/src/github.com/succinctlabs/sp1/crates/curves)
    Checking sp1-core-executor v4.2.0 (/mnt/Zhitai0/src/github.com/succinctlabs/sp1/crates/core/executor)
    Checking zkhash v0.2.0
    Checking alloy-rpc-types-eth v0.11.0
    Checking alloy-json-rpc v0.11.0
    Checking axum v0.7.9
    Checking hyper-timeout v0.5.2
    Checking reqwest-middleware v0.3.3
    Checking alloy-rpc-types-any v0.11.0
    Checking alloy-network v0.11.0
    Checking alloy-signer-local v0.11.0
    Checking twirp-rs v0.13.0-succinct
    Checking tonic v0.12.3
    Checking sp1-recursion-compiler v4.2.0 (/mnt/Zhitai0/src/github.com/succinctlabs/sp1/crates/recursion/compiler)
    Checking sp1-recursion-circuit v4.2.0 (/mnt/Zhitai0/src/github.com/succinctlabs/sp1/crates/recursion/circuit)
error: couldn't read `/mnt/Zhitai0/src/github.com/succinctlabs/sp1/examples/target/elf-compilation/riscv32im-succinct-zkvm-elf/release/aggregation-program`: No such file or directory (os error 2)
 --> aggregation/script/src/main.rs:9:32
  |
9 | const AGGREGATION_ELF: &[u8] = include_elf!("aggregation-program");
  |                                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  |
  = note: this error originates in the macro `include_bytes` which comes from the expansion of the macro `include_elf` (in Nightly builds, run with -Z macro-backtrace for more info)

error: couldn't read `/mnt/Zhitai0/src/github.com/succinctlabs/sp1/examples/target/elf-compilation/riscv32im-succinct-zkvm-elf/release/fibonacci-program`: No such file or directory (os error 2)
  --> aggregation/script/src/main.rs:12:30
   |
12 | const FIBONACCI_ELF: &[u8] = include_elf!("fibonacci-program");
   |                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
   = note: this error originates in the macro `include_bytes` which comes from the expansion of the macro `include_elf` (in Nightly builds, run with -Z macro-backtrace for more info)

warning: aggregation-script@1.1.0: Skipping build due to clippy invocation.
warning: aggregation-script@1.1.0: Skipping build due to clippy invocation.
error: could not compile `aggregation-script` (bin "aggregation-script") due to 2 previous errors

The root cause is that we do nothing but set the env var when running clippy, resulting the error of elf file not found. We should handle the elf file properly whenever the env var is set.

// Check if RUSTC_WORKSPACE_WRAPPER is set to clippy-driver (i.e. if `cargo clippy` is the
// current compiler). If so, don't execute `cargo prove build` because it breaks
// rust-analyzer's `cargo clippy` feature.
let is_clippy_driver = std::env::var("RUSTC_WORKSPACE_WRAPPER")
.map(|val| val.contains("clippy-driver"))
.unwrap_or(false);
if is_clippy_driver {
// Still need to set ELF env vars even if build is skipped.
let target_elf_paths = generate_elf_paths(&metadata, args.as_ref())
.expect("failed to collect target ELF paths");
print_elf_paths_cargo_directives(&target_elf_paths);
println!("cargo:warning=Skipping build due to clippy invocation.");
return;
}

@liuchengxu
Copy link
Contributor Author

diff --git a/crates/build/src/lib.rs b/crates/build/src/lib.rs
index e5dc7fcd..bc543732 100644
--- a/crates/build/src/lib.rs
+++ b/crates/build/src/lib.rs
@@ -156,6 +156,10 @@ pub fn build_program_with_args(path: &str, args: BuildArgs) {
 #[macro_export]
 macro_rules! include_elf {
     ($arg:tt) => {{
-        include_bytes!(env!(concat!("SP1_ELF_", $arg)))
+        if cfg!(clippy) {
+            &[]
+        } else {
+            include_bytes!(env!(concat!("SP1_ELF_", $arg)))
+        }
     }};
 }

We can use empty bytes when clippy is running. Thoughts? @leruaa

@leruaa
Copy link
Contributor

leruaa commented Apr 15, 2025

Unfortunately there is no easy way to fix that

@leruaa leruaa closed this as not planned Won't fix, can't repro, duplicate, stale Apr 15, 2025
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 a pull request may close this issue.

2 participants