Skip to content

Commit

Permalink
fix: check install cargo prove not build crate
Browse files Browse the repository at this point in the history
  • Loading branch information
nhtyy committed Nov 26, 2024
1 parent b636df5 commit eaa6ffa
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 24 deletions.
61 changes: 39 additions & 22 deletions crates/build/src/build.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
use anyhow::Result;
use cargo_metadata::camino::Utf8PathBuf;
use std::path::{Path, PathBuf};
use std::{
os::unix::process::CommandExt,

Check warning on line 4 in crates/build/src/build.rs

View workflow job for this annotation

GitHub Actions / Formatting & Clippy

unused import: `os::unix::process::CommandExt`

Check failure on line 4 in crates/build/src/build.rs

View workflow job for this annotation

GitHub Actions / Formatting & Clippy

unused import: `os::unix::process::CommandExt`

Check warning on line 4 in crates/build/src/build.rs

View workflow job for this annotation

GitHub Actions / Test (ARM)

unused import: `os::unix::process::CommandExt`

Check warning on line 4 in crates/build/src/build.rs

View workflow job for this annotation

GitHub Actions / Test (ARM)

unused import: `os::unix::process::CommandExt`

Check warning on line 4 in crates/build/src/build.rs

View workflow job for this annotation

GitHub Actions / Test (x86-64)

unused import: `os::unix::process::CommandExt`

Check warning on line 4 in crates/build/src/build.rs

View workflow job for this annotation

GitHub Actions / Test (x86-64)

unused import: `os::unix::process::CommandExt`
path::{Path, PathBuf},
};

use crate::{
command::{docker::create_docker_command, local::create_local_command, utils::execute_command},
Expand Down Expand Up @@ -200,7 +203,7 @@ fn verify_locked_version(program_dir: impl AsRef<Path>) -> Result<()> {
return Ok(());
}

// This might be a workspace, so we need optionally search parent dirs for lock files
// This might be a workspace, need optionally search parent dirs for lock files
let canon = program_dir.as_ref().canonicalize()?;
let mut lock_path = canon.join("Cargo.lock");
if !lock_path.is_file() {
Expand All @@ -226,40 +229,54 @@ fn verify_locked_version(program_dir: impl AsRef<Path>) -> Result<()> {

let lock_file = cargo_lock::Lockfile::load(lock_path)?;

let vm_package = lock_file
// You need an entrypoint, therefore you need sp1-zkvm.
let vm_version = &lock_file
.packages
.iter()
.find(|p| p.name.as_str() == "sp1-zkvm")
.ok_or_else(|| anyhow::anyhow!("sp1-zkvm not found in lock file!"))?;
.ok_or_else(|| anyhow::anyhow!("sp1-zkvm not found in lock file!"))?
.version;

let sp1_sdk = lock_file
.packages
.iter()
.find(|p| p.name.as_str() == "sp1-sdk")
.ok_or_else(|| anyhow::anyhow!("sp1-sdk not found in lock file!"))?;
let maybe_sdk =
lock_file.packages.iter().find(|p| p.name.as_str() == "sp1-sdk").map(|p| &p.version);

// Print these just to be useful.
let toolchain_version = env!("CARGO_PKG_VERSION");
println!("cargo:warning=Locked version of sp1-zkvm is {}", vm_package.version);
println!("cargo:warning=Locked version of sp1-sdk is {}", sp1_sdk.version);
println!("cargo:warning=Current toolchain version = {}", toolchain_version);
// Most people will install the actual rust toolchain along with thier cargo-prove,
// so we can just use the cargo-prove version.
let toolchain_version = {
let output = std::process::Command::new("cargo")
.args(["prove", "--version"]).output().expect("Failed to find check toolchain version, see https://docs.succinct.xyz/getting-started/install.html");

let version = String::from_utf8(output.stdout).expect("Failed to parse version string");

semver::Version::parse(
version.split_once('\n').expect("The version should have whitespace, this is a bug").1,
)?
};

let toolchain_version = semver::Version::parse(toolchain_version)?;
let vm_version = &vm_package.version;
let sp1_sdk_version = &sp1_sdk.version;
// Print these just to be useful.
if let Some(ref sdk) = maybe_sdk {
println!("cargo:warning=Locked version of sp1-sdk is {}", sdk);
} else {
println!("cargo:warning=sp1-sdk not found in lock file!");
}
println!("cargo:warning=Locked version of sp1-zkvm is {}", vm_version);
println!("cargo:warning=Current toolchain version = {}", toolchain_version);

if vm_version.major != toolchain_version.major || vm_version.minor != toolchain_version.minor {
return Err(anyhow::anyhow!(
"Locked version of sp1-zkvm is incompatible with the current toolchain version"
));
}

if sp1_sdk_version.major != toolchain_version.major
|| sp1_sdk_version.minor != toolchain_version.minor
{
return Err(anyhow::anyhow!(
"Locked version of sp1-sdk is incompatible with the current toolchain version"
));
if let Some(sdk_version) = maybe_sdk {
if sdk_version.major != toolchain_version.major
|| sdk_version.minor != toolchain_version.minor
{
return Err(anyhow::anyhow!(
"Locked version of sp1-sdk is incompatible with the current toolchain version"
));
}
}

Ok(())
Expand Down
12 changes: 10 additions & 2 deletions crates/cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,16 @@ use std::process::{Command, Stdio};

pub const RUSTUP_TOOLCHAIN_NAME: &str = "succinct";

pub const SP1_VERSION_MESSAGE: &str =
concat!("sp1", " (", env!("VERGEN_GIT_SHA"), " ", env!("VERGEN_BUILD_TIMESTAMP"), ")");
pub const SP1_VERSION_MESSAGE: &str = concat!(
"sp1",
" (",
env!("VERGEN_GIT_SHA"),
" ",
env!("VERGEN_BUILD_TIMESTAMP"),
")",
"\n",
env!("CARGO_PKG_VERSION")
);

trait CommandExecutor {
fn run(&mut self) -> Result<()>;
Expand Down

0 comments on commit eaa6ffa

Please sign in to comment.