diff --git a/crates/build/src/build.rs b/crates/build/src/build.rs index 04c3ad5fd9..e7a01b9d50 100644 --- a/crates/build/src/build.rs +++ b/crates/build/src/build.rs @@ -9,17 +9,19 @@ use crate::{ BuildArgs, }; -/// Build a program with the specified [`BuildArgs`]. The `program_dir` is specified as an argument when -/// the program is built via `build_program`. +/// Build a program with the specified [`BuildArgs`]. The `program_dir` is specified as an argument +/// when the program is built via `build_program`. /// /// # Arguments /// -/// * `args` - A reference to a `BuildArgs` struct that holds various arguments used for building the program. +/// * `args` - A reference to a `BuildArgs` struct that holds various arguments used for building +/// the program. /// * `program_dir` - An optional `PathBuf` specifying the directory of the program to be built. /// /// # Returns /// -/// * `Result` - The path to the built program as a `Utf8PathBuf` on success, or an error on failure. +/// * `Result` - The path to the built program as a `Utf8PathBuf` on success, or an +/// error on failure. pub fn execute_build_program( args: &BuildArgs, program_dir: Option, @@ -27,17 +29,14 @@ pub fn execute_build_program( // If the program directory is not specified, use the current directory. let program_dir = program_dir .unwrap_or_else(|| std::env::current_dir().expect("Failed to get current directory.")); - let program_dir: Utf8PathBuf = program_dir - .try_into() - .expect("Failed to convert PathBuf to Utf8PathBuf"); + let program_dir: Utf8PathBuf = + program_dir.try_into().expect("Failed to convert PathBuf to Utf8PathBuf"); // Get the program metadata. let program_metadata_file = program_dir.join("Cargo.toml"); let mut program_metadata_cmd = cargo_metadata::MetadataCommand::new(); - let program_metadata = program_metadata_cmd - .manifest_path(program_metadata_file) - .exec() - .unwrap(); + let program_metadata = + program_metadata_cmd.manifest_path(program_metadata_file).exec().unwrap(); // Get the command corresponding to Docker or local build. let cmd = if args.docker { @@ -59,10 +58,7 @@ pub(crate) fn build_program_internal(path: &str, args: Option) { let mut metadata_cmd = cargo_metadata::MetadataCommand::new(); let metadata = metadata_cmd.manifest_path(metadata_file).exec().unwrap(); let root_package = metadata.root_package(); - let root_package_name = root_package - .as_ref() - .map(|p| p.name.as_str()) - .unwrap_or("Program"); + let root_package_name = root_package.as_ref().map(|p| p.name.as_str()).unwrap_or("Program"); // Skip the program build if the SP1_SKIP_PROGRAM_BUILD environment variable is set to true. let skip_program_build = std::env::var("SP1_SKIP_PROGRAM_BUILD") @@ -80,8 +76,9 @@ pub(crate) fn build_program_internal(path: &str, args: Option) { // Activate the build command if the dependencies change. cargo_rerun_if_changed(&metadata, program_dir); - // 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. + // 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); @@ -100,9 +97,5 @@ pub(crate) fn build_program_internal(path: &str, args: Option) { panic!("Failed to build SP1 program: {}.", err); } - println!( - "cargo:warning={} built at {}", - root_package_name, - current_datetime() - ); + println!("cargo:warning={} built at {}", root_package_name, current_datetime()); } diff --git a/crates/build/src/command/local.rs b/crates/build/src/command/local.rs index 7a14e9a5a2..47e129fd6c 100644 --- a/crates/build/src/command/local.rs +++ b/crates/build/src/command/local.rs @@ -13,18 +13,14 @@ pub(crate) fn create_local_command( program_metadata: &cargo_metadata::Metadata, ) -> Command { let mut command = Command::new("cargo"); - let canonicalized_program_dir = program_dir - .canonicalize() - .expect("Failed to canonicalize program directory"); + let canonicalized_program_dir = + program_dir.canonicalize().expect("Failed to canonicalize program directory"); // If CC_riscv32im_succinct_zkvm_elf is not set, set it to the default C++ toolchain // downloaded by 'sp1up --c-toolchain'. if env::var("CC_riscv32im_succinct_zkvm_elf").is_err() { if let Some(home_dir) = home_dir() { - let cc_path = home_dir - .join(".sp1") - .join("bin") - .join("riscv32-unknown-elf-gcc"); + let cc_path = home_dir.join(".sp1").join("bin").join("riscv32-unknown-elf-gcc"); if cc_path.exists() { command.env("CC_riscv32im_succinct_zkvm_elf", cc_path); } @@ -32,21 +28,20 @@ pub(crate) fn create_local_command( } // When executing the local command: - // 1. Set the target directory to a subdirectory of the program's target directory to avoid build + // 1. Set the target directory to a subdirectory of the program's target directory to avoid + // build // conflicts with the parent process. Source: https://github.com/rust-lang/cargo/issues/6412 // 2. Set the rustup toolchain to succinct. // 3. Set the encoded rust flags. // 4. Remove the rustc configuration, otherwise in a build script it will attempt to compile the - // program with the toolchain of the normal build process, rather than the Succinct toolchain. + // program with the toolchain of the normal build process, rather than the Succinct + // toolchain. command .current_dir(canonicalized_program_dir) .env("RUSTUP_TOOLCHAIN", "succinct") .env("CARGO_ENCODED_RUSTFLAGS", get_rust_compiler_flags()) .env_remove("RUSTC") - .env( - "CARGO_TARGET_DIR", - program_metadata.target_directory.join(HELPER_TARGET_SUBDIR), - ) + .env("CARGO_TARGET_DIR", program_metadata.target_directory.join(HELPER_TARGET_SUBDIR)) .args(&get_program_build_args(args)); command } diff --git a/crates/build/src/lib.rs b/crates/build/src/lib.rs index 913b7e8ba6..89731cc864 100644 --- a/crates/build/src/lib.rs +++ b/crates/build/src/lib.rs @@ -82,8 +82,8 @@ impl Default for BuildArgs { /// Builds the program if the program at the specified path, or one of its dependencies, changes. /// -/// This function monitors the program and its dependencies for changes. If any changes are detected, -/// it triggers a rebuild of the program. +/// This function monitors the program and its dependencies for changes. If any changes are +/// detected, it triggers a rebuild of the program. /// /// # Arguments /// diff --git a/crates/build/src/utils.rs b/crates/build/src/utils.rs index e7266fa367..72af0da115 100644 --- a/crates/build/src/utils.rs +++ b/crates/build/src/utils.rs @@ -14,8 +14,8 @@ pub(crate) fn copy_elf_to_output_dir( let root_package = program_metadata.root_package(); let root_package_name = root_package.as_ref().map(|p| &p.name); - // The ELF is written to a target folder specified by the program's package. If built with Docker, - // includes /docker after HELPER_TARGET_SUBDIR. + // The ELF is written to a target folder specified by the program's package. If built with + // Docker, includes /docker after HELPER_TARGET_SUBDIR. let target_dir_suffix = if args.docker { format!("{}/{}", HELPER_TARGET_SUBDIR, "docker") } else { @@ -42,11 +42,7 @@ pub(crate) fn copy_elf_to_output_dir( BUILD_TARGET.to_string() }; - let elf_dir = program_metadata - .target_directory - .parent() - .unwrap() - .join(&args.output_directory); + let elf_dir = program_metadata.target_directory.parent().unwrap().join(&args.output_directory); fs::create_dir_all(&elf_dir)?; let result_elf_path = elf_dir.join(elf_name); @@ -73,19 +69,13 @@ pub(crate) fn cargo_rerun_if_changed(metadata: &Metadata, program_dir: &Path) { ]; for dir in dirs { if dir.exists() { - println!( - "cargo::rerun-if-changed={}", - dir.canonicalize().unwrap().display() - ); + println!("cargo::rerun-if-changed={}", dir.canonicalize().unwrap().display()); } } // Re-run the build script if the workspace root's Cargo.lock changes. If the program is its own // workspace, this will be the program's Cargo.lock. - println!( - "cargo:rerun-if-changed={}", - metadata.workspace_root.join("Cargo.lock").as_str() - ); + println!("cargo:rerun-if-changed={}", metadata.workspace_root.join("Cargo.lock").as_str()); // Re-run if any local dependency changes. for package in &metadata.packages { diff --git a/crates/cli/src/commands/prove.rs b/crates/cli/src/commands/prove.rs index fb4eebe6e0..0e2951dc23 100644 --- a/crates/cli/src/commands/prove.rs +++ b/crates/cli/src/commands/prove.rs @@ -1,14 +1,11 @@ use anstyle::*; use anyhow::Result; use clap::Parser; -use sp1_build::{build_program, BuildArgs}; use sp1_build::{execute_build_program, BuildArgs}; -use sp1_core::utils::{setup_logger, setup_tracer}; use sp1_core_machine::{ io::SP1Stdin, utils::{setup_logger, setup_tracer}, }; -use sp1_prover::SP1Stdin; use sp1_sdk::ProverClient; use std::{env, fs::File, io::Read, path::PathBuf, str::FromStr, time::Instant};